removed test classes which only test log4j features, not extra features
git-svn-id: https://svn.apache.org/repos/asf/logging/log4j/companions/extras/trunk@1481785 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/test/java/org/apache/log4j/EnhancedMyPatternLayout.java b/src/test/java/org/apache/log4j/EnhancedMyPatternLayout.java
deleted file mode 100644
index 4ec375c..0000000
--- a/src/test/java/org/apache/log4j/EnhancedMyPatternLayout.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.log4j;
-import org.apache.log4j.helpers.PatternParser;
-
-/**
-
- Example showing how to extend EnhancedPatternLayout to recognize additional
- conversion characters.
-
- <p>In this case MyPatternLayout recognizes %# conversion pattern. It
- outputs the value of an internal counter which is also incremented
- at each call.
-
- <p>See <a href=doc-files/MyPatternLayout.java><b>source</b></a> code
- for more details.
-
- @see MyPatternParser
- @see org.apache.log4j.EnhancedPatternLayout
- @author Anders Kristensen
-*/
-public class EnhancedMyPatternLayout extends EnhancedPatternLayout {
- public
- EnhancedMyPatternLayout() {
- this(DEFAULT_CONVERSION_PATTERN);
- }
-
- public
- EnhancedMyPatternLayout(String pattern) {
- super(pattern);
- }
-
- public
- PatternParser createPatternParser(String pattern) {
- return new MyPatternParser(
- pattern == null ? DEFAULT_CONVERSION_PATTERN : pattern);
- }
-}
diff --git a/src/test/java/org/apache/log4j/EnhancedPatternLayoutTest.java b/src/test/java/org/apache/log4j/EnhancedPatternLayoutTest.java
deleted file mode 100644
index 39d5767..0000000
--- a/src/test/java/org/apache/log4j/EnhancedPatternLayoutTest.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.log4j;
-
-import org.apache.log4j.spi.LoggingEvent;
-
-
-/**
- * Test for EnhancedPatternLayout.
- *
- */
-public class EnhancedPatternLayoutTest extends LayoutTest {
- /**
- * Construct new instance of PatternLayoutTest.
- *
- * @param testName test name.
- */
- public EnhancedPatternLayoutTest(final String testName) {
- super(testName, "text/plain", true, null, null);
- }
-
- /**
- * @{inheritDoc}
- */
- protected Layout createLayout() {
- return new EnhancedPatternLayout("[%t] %p %c - %m%n");
- }
-
- /**
- * Tests format.
- */
- public void testFormat() {
- Logger logger = Logger.getLogger("org.apache.log4j.LayoutTest");
- LoggingEvent event =
- new LoggingEvent(
- "org.apache.log4j.Logger", logger, Level.INFO, "Hello, World", null);
- EnhancedPatternLayout layout = (EnhancedPatternLayout) createLayout();
- String result = layout.format(event);
- StringBuffer buf = new StringBuffer(100);
- buf.append('[');
- buf.append(event.getThreadName());
- buf.append("] ");
- buf.append(event.getLevel().toString());
- buf.append(' ');
- buf.append(event.getLoggerName());
- buf.append(" - ");
- buf.append(event.getMessage());
- buf.append(System.getProperty("line.separator"));
- assertEquals(buf.toString(), result);
- }
-
- /**
- * Tests getPatternFormat().
- */
- public void testGetPatternFormat() {
- EnhancedPatternLayout layout = (EnhancedPatternLayout) createLayout();
- assertEquals("[%t] %p %c - %m%n", layout.getConversionPattern());
- }
-
- /**
- * Tests DEFAULT_CONVERSION_PATTERN constant.
- */
- public void testDefaultConversionPattern() {
- assertEquals("%m%n", EnhancedPatternLayout.DEFAULT_CONVERSION_PATTERN);
- }
-
- /**
- * Tests DEFAULT_CONVERSION_PATTERN constant.
- */
- public void testTTCCConversionPattern() {
- assertEquals(
- "%r [%t] %p %c %x - %m%n", EnhancedPatternLayout.TTCC_CONVERSION_PATTERN);
- }
-
- /**
- * Tests buffer downsizing code path.
- */
- public void testFormatResize() {
- Logger logger = Logger.getLogger("org.apache.log4j.xml.PatternLayoutTest");
- NDC.clear();
-
- char[] msg = new char[2000];
-
- for (int i = 0; i < msg.length; i++) {
- msg[i] = 'A';
- }
-
- LoggingEvent event1 =
- new LoggingEvent(
- "org.apache.log4j.Logger", logger, Level.DEBUG, new String(msg), null);
- EnhancedPatternLayout layout = (EnhancedPatternLayout) createLayout();
- String result = layout.format(event1);
- LoggingEvent event2 =
- new LoggingEvent(
- "org.apache.log4j.Logger", logger, Level.WARN, "Hello, World", null);
- result = layout.format(event2);
- assertEquals("[", result.substring(0, 1));
- }
-
- /**
- * Class to ensure that protected members are still available.
- */
- public static final class DerivedPatternLayout extends EnhancedPatternLayout {
- /**
- * Constructs a new instance of DerivedPatternLayout.
- */
- public DerivedPatternLayout() {
- }
-
- /**
- * Get BUF_SIZE.
- * @return return initial buffer size in characters.
- * @deprecated
- */
- public int getBufSize() {
- return BUF_SIZE;
- }
-
- /**
- * Get MAX_CAPACITY.
- * @return maximum capacity in characters.
- * @deprecated
- */
- public int getMaxCapacity() {
- return MAX_CAPACITY;
- }
- }
-}
diff --git a/src/test/java/org/apache/log4j/EnhancedPatternLayoutTestCase.java b/src/test/java/org/apache/log4j/EnhancedPatternLayoutTestCase.java
deleted file mode 100644
index 315a827..0000000
--- a/src/test/java/org/apache/log4j/EnhancedPatternLayoutTestCase.java
+++ /dev/null
@@ -1,615 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.log4j;
-
-import junit.framework.TestCase;
-import org.apache.log4j.util.AbsoluteDateAndTimeFilter;
-import org.apache.log4j.util.AbsoluteTimeFilter;
-import org.apache.log4j.util.Compare;
-import org.apache.log4j.util.ControlFilter;
-import org.apache.log4j.util.Filter;
-import org.apache.log4j.util.ISO8601Filter;
-import org.apache.log4j.util.JunitTestRunnerFilter;
-import org.apache.log4j.util.LineNumberFilter;
-import org.apache.log4j.util.RelativeTimeFilter;
-import org.apache.log4j.util.SunReflectFilter;
-import org.apache.log4j.util.Transformer;
-import org.apache.log4j.util.MDCOrderFilter;
-import org.apache.log4j.spi.ThrowableInformation;
-
-import java.text.ParsePosition;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.TimeZone;
-import java.io.*;
-import java.util.Properties;
-
-
-public class EnhancedPatternLayoutTestCase extends TestCase {
- static String TEMP = "target/temp";
- static String FILTERED = "target/filtered";
- static String EXCEPTION1 = "java.lang.Exception: Just testing";
- static String EXCEPTION2 = "\\s*at .*\\(.*:\\d{1,4}\\)";
- static String EXCEPTION3 = "\\s*at .*\\((Native Method|Unknown Source)\\)";
- static String EXCEPTION4 = "\\s*at .*\\(.*Compiled Code\\)";
-
- static String PAT0 =
- "\\[main]\\ (DEBUG|INFO|WARN|ERROR|FATAL) .* - Message \\d{1,2}";
- static String PAT1 = Filter.ISO8601_PAT + " " + PAT0;
- static String PAT2 = Filter.ABSOLUTE_DATE_AND_TIME_PAT + " " + PAT0;
- static String PAT3 = Filter.ABSOLUTE_TIME_PAT + " " + PAT0;
- static String PAT4 = Filter.RELATIVE_TIME_PAT + " " + PAT0;
- static String PAT5 =
- "\\[main]\\ (DEBUG|INFO|WARN|ERROR|FATAL) .* : Message \\d{1,2}";
- static String PAT6 =
- "\\[main]\\ (DEBUG|INFO |WARN |ERROR|FATAL) org.apache.log4j.EnhancedPatternLayoutTestCase.common\\(EnhancedPatternLayoutTestCase.java:\\d{1,4}\\): Message \\d{1,2}";
- static String PAT11a =
- "^(DEBUG|INFO |WARN |ERROR|FATAL) \\[main]\\ log4j.EnhancedPatternLayoutTest: Message \\d{1,2}";
- static String PAT11b =
- "^(DEBUG|INFO |WARN |ERROR|FATAL) \\[main]\\ root: Message \\d{1,2}";
- static String PAT12 =
- "^\\[main]\\ (DEBUG|INFO |WARN |ERROR|FATAL) "
- + "org.apache.log4j.EnhancedPatternLayoutTestCase.common\\(EnhancedPatternLayoutTestCase.java:\\d{3}\\): "
- + "Message \\d{1,2}";
- static String PAT13 =
- "^\\[main]\\ (DEBUG|INFO |WARN |ERROR|FATAL) "
- + "apache.log4j.EnhancedPatternLayoutTestCase.common\\(EnhancedPatternLayoutTestCase.java:\\d{3}\\): "
- + "Message \\d{1,2}";
- static String PAT14 =
- "^(TRACE|DEBUG| INFO| WARN|ERROR|FATAL)\\ \\d{1,2}\\ *- Message \\d{1,2}";
- static String PAT_MDC_1 = "";
- Logger root;
- Logger logger;
-
- public EnhancedPatternLayoutTestCase(final String name) {
- super(name);
- }
-
- public void setUp() {
- root = Logger.getRootLogger();
- logger = Logger.getLogger(EnhancedPatternLayoutTest.class);
- }
-
- public void tearDown() {
- root.getLoggerRepository().resetConfiguration();
- }
-
- /**
- * Configures log4j from a properties file resource in class loader path.
- * @param fileName resource name, only last element is significant.
- * @throws IOException if resource not found or error reading resource.
- */
- private static void configure(final String fileName) throws IOException {
- String resourceName = fileName;
- int lastSlash = resourceName.lastIndexOf("/");
- if (lastSlash >= 0) {
- resourceName = resourceName.substring(lastSlash + 1);
- }
- InputStream is = EnhancedPatternLayoutTestCase.class.getResourceAsStream(resourceName);
- if (is == null) {
- throw new FileNotFoundException("Could not find resource " + resourceName);
- }
- Properties props = new Properties();
- props.load(is);
- PropertyConfigurator.configure(props);
- }
-
- /**
- * Compares actual and expected files.
- * @param actual file name for file generated by test
- * @param expected resource name containing expected output
- * @return true if files are the same after adjustments
- * @throws IOException if IO error during comparison.
- */
- private static boolean compare(final String actual,
- final String expected) throws IOException {
- return Compare.compare(EnhancedPatternLayoutTestCase.class, actual, expected);
- }
-
-
- public void test1() throws Exception {
- configure("enhancedPatternLayout1.properties");
- common();
- Transformer.transform(
- TEMP, FILTERED,
- new Filter[] {
- new LineNumberFilter(), new SunReflectFilter(),
- new JunitTestRunnerFilter()
- });
- assertTrue(compare(FILTERED, "witness/pattern/enhancedPatternLayout.1"));
- }
-
- public void test2() throws Exception {
- configure("input/pattern/enhancedPatternLayout2.properties");
- common();
-
- ControlFilter cf1 =
- new ControlFilter(
- new String[] { PAT1, EXCEPTION1, EXCEPTION2, EXCEPTION3 });
- Transformer.transform(
- TEMP, FILTERED,
- new Filter[] {
- cf1, new LineNumberFilter(), new ISO8601Filter(),
- new SunReflectFilter(), new JunitTestRunnerFilter()
- });
- assertTrue(compare(FILTERED, "witness/pattern/enhancedPatternLayout.2"));
- }
-
- public void test3() throws Exception {
- configure("input/pattern/enhancedPatternLayout3.properties");
- common();
-
- ControlFilter cf1 =
- new ControlFilter(
- new String[] { PAT1, EXCEPTION1, EXCEPTION2, EXCEPTION3 });
- Transformer.transform(
- TEMP, FILTERED,
- new Filter[] {
- cf1, new LineNumberFilter(), new ISO8601Filter(),
- new SunReflectFilter(), new JunitTestRunnerFilter()
- });
- assertTrue(compare(FILTERED, "witness/pattern/enhancedPatternLayout.3"));
- }
-
- // Output format:
- // 06 avr. 2002 18:30:58,937 [main] DEBUG atternLayoutTest - Message 0
- public void test4() throws Exception {
- configure("input/pattern/enhancedPatternLayout4.properties");
- common();
-
- ControlFilter cf1 =
- new ControlFilter(
- new String[] { PAT2, EXCEPTION1, EXCEPTION2, EXCEPTION3 });
- Transformer.transform(
- TEMP, FILTERED,
- new Filter[] {
- cf1, new LineNumberFilter(), new AbsoluteDateAndTimeFilter(),
- new SunReflectFilter(), new JunitTestRunnerFilter()
- });
- assertTrue(compare(FILTERED, "witness/pattern/enhancedPatternLayout.4"));
- }
-
- public void test5() throws Exception {
- configure("input/pattern/enhancedPatternLayout5.properties");
- common();
-
- ControlFilter cf1 =
- new ControlFilter(
- new String[] { PAT2, EXCEPTION1, EXCEPTION2, EXCEPTION3 });
- Transformer.transform(
- TEMP, FILTERED,
- new Filter[] {
- cf1, new LineNumberFilter(), new AbsoluteDateAndTimeFilter(),
- new SunReflectFilter(), new JunitTestRunnerFilter()
- });
- assertTrue(compare(FILTERED, "witness/pattern/enhancedPatternLayout.5"));
- }
-
- // 18:54:19,201 [main] DEBUG atternLayoutTest - Message 0
- public void test6() throws Exception {
- configure("input/pattern/enhancedPatternLayout6.properties");
- common();
-
- ControlFilter cf1 =
- new ControlFilter(
- new String[] { PAT3, EXCEPTION1, EXCEPTION2, EXCEPTION3 });
- Transformer.transform(
- TEMP, FILTERED,
- new Filter[] {
- cf1, new LineNumberFilter(), new AbsoluteTimeFilter(),
- new SunReflectFilter(), new JunitTestRunnerFilter()
- });
- assertTrue(compare(FILTERED, "witness/pattern/enhancedPatternLayout.6"));
- }
-
- public void test7() throws Exception {
- configure("input/pattern/enhancedPatternLayout7.properties");
- common();
-
- ControlFilter cf1 =
- new ControlFilter(
- new String[] { PAT3, EXCEPTION1, EXCEPTION2, EXCEPTION3 });
- Transformer.transform(
- TEMP, FILTERED,
- new Filter[] {
- cf1, new LineNumberFilter(), new AbsoluteTimeFilter(),
- new SunReflectFilter(), new JunitTestRunnerFilter()
- });
- assertTrue(compare(FILTERED, "witness/pattern/enhancedPatternLayout.7"));
- }
-
- public void test8() throws Exception {
- configure("input/pattern/enhancedPatternLayout8.properties");
- common();
-
- ControlFilter cf1 =
- new ControlFilter(
- new String[] { PAT4, EXCEPTION1, EXCEPTION2, EXCEPTION3 });
- Transformer.transform(
- TEMP, FILTERED,
- new Filter[] {
- cf1, new LineNumberFilter(), new RelativeTimeFilter(),
- new SunReflectFilter(), new JunitTestRunnerFilter()
- });
- assertTrue(compare(FILTERED, "witness/pattern/enhancedPatternLayout.8"));
- }
-
- public void test9() throws Exception {
- configure("input/pattern/enhancedPatternLayout9.properties");
- common();
-
- ControlFilter cf1 =
- new ControlFilter(
- new String[] { PAT5, EXCEPTION1, EXCEPTION2, EXCEPTION3 });
- Transformer.transform(
- TEMP, FILTERED,
- new Filter[] {
- cf1, new LineNumberFilter(), new SunReflectFilter(),
- new JunitTestRunnerFilter()
- });
- assertTrue(compare(FILTERED, "witness/pattern/enhancedPatternLayout.9"));
- }
-
- public void test10() throws Exception {
- configure("input/pattern/enhancedPatternLayout10.properties");
- common();
-
- ControlFilter cf1 =
- new ControlFilter(
- new String[] { PAT6, EXCEPTION1, EXCEPTION2, EXCEPTION3 });
- Transformer.transform(
- TEMP, FILTERED,
- new Filter[] {
- cf1, new LineNumberFilter(), new SunReflectFilter(),
- new JunitTestRunnerFilter()
- });
- assertTrue(compare(FILTERED, "witness/pattern/enhancedPatternLayout.10"));
- }
-
- public void test11() throws Exception {
- configure("input/pattern/enhancedPatternLayout11.properties");
- common();
-
- ControlFilter cf1 =
- new ControlFilter(
- new String[] { PAT11a, PAT11b, EXCEPTION1, EXCEPTION2, EXCEPTION3 });
- Transformer.transform(
- TEMP, FILTERED,
- new Filter[] {
- cf1, new LineNumberFilter(), new SunReflectFilter(),
- new JunitTestRunnerFilter()
- });
- assertTrue(compare(FILTERED, "witness/pattern/enhancedPatternLayout.11"));
- }
-
- public void test12() throws Exception {
- configure("input/pattern/enhancedPatternLayout12.properties");
- common();
-
- ControlFilter cf1 =
- new ControlFilter(
- new String[] { PAT12, EXCEPTION1, EXCEPTION2, EXCEPTION3 });
- Transformer.transform(
- TEMP, FILTERED,
- new Filter[] {
- cf1, new LineNumberFilter(), new SunReflectFilter(),
- new JunitTestRunnerFilter()
- });
- assertTrue(compare(FILTERED, "witness/pattern/enhancedPatternLayout.12"));
- }
-
- public void test13() throws Exception {
- configure("input/pattern/enhancedPatternLayout13.properties");
- common();
-
- ControlFilter cf1 =
- new ControlFilter(
- new String[] { PAT13, EXCEPTION1, EXCEPTION2, EXCEPTION3 });
- Transformer.transform(
- TEMP, FILTERED,
- new Filter[] {
- cf1, new LineNumberFilter(), new SunReflectFilter(),
- new JunitTestRunnerFilter()
- });
- assertTrue(compare(FILTERED, "witness/pattern/enhancedPatternLayout.13"));
- }
-
- /**
- * Test of class abbreviation.
- *
- * @throws Exception
- */
- public void test14() throws Exception {
- configure("input/pattern/enhancedPatternLayout14.properties");
- common();
-
- Transformer.transform(
- TEMP, FILTERED,
- new Filter[] {
- new LineNumberFilter(), new SunReflectFilter(),
- new JunitTestRunnerFilter()
- });
- assertTrue(compare(FILTERED, "witness/pattern/enhancedPatternLayout.14"));
- }
-
-
- private static void clearMDC() throws Exception {
- java.util.Hashtable context = MDC.getContext();
- if (context != null) {
- context.clear();
- }
- }
-
- public void testMDC1() throws Exception {
- configure("input/pattern/enhancedPatternLayout.mdc.1.properties");
- clearMDC();
- MDC.put("key1", "va11");
- MDC.put("key2", "va12");
- logger.debug("Hello World");
- MDC.remove("key1");
- MDC.remove("key2");
-
- Transformer.transform(
- TEMP, FILTERED,
- new Filter[] {
- new LineNumberFilter(), new SunReflectFilter(),
- new JunitTestRunnerFilter(),
- new MDCOrderFilter()
- });
- assertTrue(compare(FILTERED, "witness/pattern/enhancedPatternLayout.mdc.1"));
- }
- /**
- * Tests log4j 1.2 style extension of EnhancedPatternLayout.
- * Was test14 in log4j 1.2.
- * @throws Exception
- */
- public void test15() throws Exception {
- configure("input/pattern/enhancedPatternLayout15.properties");
- common();
- ControlFilter cf1 = new ControlFilter(new String[]{PAT14, EXCEPTION1,
- EXCEPTION2, EXCEPTION3, EXCEPTION4});
- Transformer.transform(
- TEMP, FILTERED,
- new Filter[] {
- cf1, new LineNumberFilter(), new SunReflectFilter(),
- new JunitTestRunnerFilter()
- });
- assertTrue(compare(FILTERED, "witness/pattern/enhancedPatternLayout.15"));
- }
- /**
- * Tests explicit UTC time zone in pattern.
- * @throws Exception
- */
- public void test16() throws Exception {
- final long start = new Date().getTime();
- configure("input/pattern/enhancedPatternLayout16.properties");
- common();
- final long end = new Date().getTime();
- FileReader reader = new FileReader("target/patternLayout16.log");
- char chars[] = new char[50];
- reader.read(chars, 0, chars.length);
- reader.close();
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- format.setTimeZone(TimeZone.getTimeZone("GMT+0"));
- String utcStr = new String(chars, 0, 19);
- Date utcDate = format.parse(utcStr, new ParsePosition(0));
- assertTrue(utcDate.getTime() >= start - 1000 && utcDate.getTime() < end + 1000);
- String cstStr = new String(chars, 21, 19);
- format.setTimeZone(TimeZone.getTimeZone("GMT-6"));
- Date cstDate = format.parse(cstStr, new ParsePosition(0));
- assertFalse(cstStr.equals(utcStr));
- assertTrue(cstDate.getTime() >= start - 1000 && cstDate.getTime() < end + 1000);
- }
-
- /**
- * Test left and right truncation
- */
- public void test17() throws Exception {
- configure("input/pattern/enhancedPatternLayout17.properties");
- root.info("012");
- root.info("");
- root.info("12345");
- root.info("0123456789");
- assertTrue(compare("target/patternLayout17.log", "witness/pattern/enhancedPatternLayout.17"));
- }
-
-
- void common() {
- int i = -1;
-
- logger.debug("Message " + ++i);
- root.debug("Message " + i);
-
- logger.info("Message " + ++i);
- root.info("Message " + i);
-
- logger.warn("Message " + ++i);
- root.warn("Message " + i);
-
- logger.error("Message " + ++i);
- root.error("Message " + i);
-
- logger.log(Level.FATAL, "Message " + ++i);
- root.log(Level.FATAL, "Message " + i);
-
- Exception e = new Exception("Just testing");
-
- logger.debug("Message " + ++i, e);
- logger.info("Message " + ++i, e);
- logger.warn("Message " + ++i, e);
- logger.error("Message " + ++i, e);
- logger.log(Level.FATAL, "Message " + ++i, e);
- }
-
- /**
- Test case for MDC conversion pattern. */
- public void testMDC2() throws Exception {
- String OUTPUT_FILE = "target/patternLayout.mdc.2";
- String WITNESS_FILE = "witness/pattern/enhancedPatternLayout.mdc.2";
-
- String mdcMsgPattern1 = "%m : %X%n";
- String mdcMsgPattern2 = "%m : %X{key1}%n";
- String mdcMsgPattern3 = "%m : %X{key2}%n";
- String mdcMsgPattern4 = "%m : %X{key3}%n";
- String mdcMsgPattern5 = "%m : %X{key1},%X{key2},%X{key3}%n";
-
- // set up appender
- EnhancedPatternLayout layout = new EnhancedPatternLayout("%m%n");
- Appender appender = new FileAppender(layout, OUTPUT_FILE, false);
-
- // set appender on root and set level to debug
- root.addAppender(appender);
- root.setLevel(Level.DEBUG);
-
- clearMDC();
- // output starting message
- root.debug("starting mdc pattern test");
-
- layout.setConversionPattern(mdcMsgPattern1);
- layout.activateOptions();
- root.debug("empty mdc, no key specified in pattern");
-
- layout.setConversionPattern(mdcMsgPattern2);
- layout.activateOptions();
- root.debug("empty mdc, key1 in pattern");
-
- layout.setConversionPattern(mdcMsgPattern3);
- layout.activateOptions();
- root.debug("empty mdc, key2 in pattern");
-
- layout.setConversionPattern(mdcMsgPattern4);
- layout.activateOptions();
- root.debug("empty mdc, key3 in pattern");
-
- layout.setConversionPattern(mdcMsgPattern5);
- layout.activateOptions();
- root.debug("empty mdc, key1, key2, and key3 in pattern");
-
- MDC.put("key1", "value1");
- MDC.put("key2", "value2");
-
- layout.setConversionPattern(mdcMsgPattern1);
- layout.activateOptions();
- root.debug("filled mdc, no key specified in pattern");
-
- layout.setConversionPattern(mdcMsgPattern2);
- layout.activateOptions();
- root.debug("filled mdc, key1 in pattern");
-
- layout.setConversionPattern(mdcMsgPattern3);
- layout.activateOptions();
- root.debug("filled mdc, key2 in pattern");
-
- layout.setConversionPattern(mdcMsgPattern4);
- layout.activateOptions();
- root.debug("filled mdc, key3 in pattern");
-
- layout.setConversionPattern(mdcMsgPattern5);
- layout.activateOptions();
- root.debug("filled mdc, key1, key2, and key3 in pattern");
-
- MDC.remove("key1");
- MDC.remove("key2");
-
- layout.setConversionPattern("%m%n");
- layout.activateOptions();
- root.debug("finished mdc pattern test");
-
-
- Transformer.transform(
- OUTPUT_FILE, FILTERED,
- new Filter[] {
- new LineNumberFilter(), new SunReflectFilter(),
- new JunitTestRunnerFilter(),
- new MDCOrderFilter()
- });
-
- assertTrue(compare(FILTERED, WITNESS_FILE));
- }
- /**
- Test case for throwable conversion pattern. */
- public void testThrowable() throws Exception {
- String OUTPUT_FILE = "target/patternLayout.throwable";
- String WITNESS_FILE = "witness/pattern/enhancedPatternLayout.throwable";
-
-
- // set up appender
- EnhancedPatternLayout layout = new EnhancedPatternLayout("%m%n");
- Appender appender = new FileAppender(layout, OUTPUT_FILE, false);
-
- // set appender on root and set level to debug
- root.addAppender(appender);
- root.setLevel(Level.DEBUG);
-
- // output starting message
- root.debug("starting throwable pattern test");
- Exception ex = new Exception("Test Exception");
- root.debug("plain pattern, no exception");
- root.debug("plain pattern, with exception", ex);
- layout.setConversionPattern("%m%n%throwable");
- layout.activateOptions();
- root.debug("%throwable, no exception");
- root.debug("%throwable, with exception", ex);
-
- layout.setConversionPattern("%m%n%throwable{short}");
- layout.activateOptions();
- root.debug("%throwable{short}, no exception");
- root.debug("%throwable{short}, with exception", ex);
-
- layout.setConversionPattern("%m%n%throwable{none}");
- layout.activateOptions();
- root.debug("%throwable{none}, no exception");
- root.debug("%throwable{none}, with exception", ex);
-
-
- layout.setConversionPattern("%m%n%throwable{0}");
- layout.activateOptions();
- root.debug("%throwable{0}, no exception");
- root.debug("%throwable{0}, with exception", ex);
-
- layout.setConversionPattern("%m%n%throwable{1}");
- layout.activateOptions();
- root.debug("%throwable{1}, no exception");
- root.debug("%throwable{1}, with exception", ex);
-
- layout.setConversionPattern("%m%n%throwable{100}");
- layout.activateOptions();
- root.debug("%throwable{100}, no exception");
- root.debug("%throwable{100}, with exception", ex);
-
- //
- // manufacture a pattern to get just the first two lines
- //
- String[] trace = new ThrowableInformation(ex).getThrowableStrRep();
- layout.setConversionPattern("%m%n%throwable{" + (2 - trace.length) + "}");
- layout.activateOptions();
- root.debug("%throwable{-n}, no exception");
- root.debug("%throwable{-n}, with exception", ex);
-
-
- Transformer.transform(
- OUTPUT_FILE, FILTERED,
- new Filter[] {
- new LineNumberFilter(), new SunReflectFilter(),
- new JunitTestRunnerFilter(),
- new MDCOrderFilter()
- });
-
- assertTrue(compare(FILTERED, WITNESS_FILE));
- }
-}
diff --git a/src/test/java/org/apache/log4j/TestLogMF.java b/src/test/java/org/apache/log4j/TestLogMF.java
deleted file mode 100755
index 9adff21..0000000
--- a/src/test/java/org/apache/log4j/TestLogMF.java
+++ /dev/null
@@ -1,1291 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.log4j;
-
-import junit.framework.TestCase;
-
-import java.io.CharArrayWriter;
-import java.text.MessageFormat;
-import java.text.NumberFormat;
-import java.util.Date;
-import java.text.DateFormat;
-
-
-/**
- * Unit test for LogMF.
- */
-public class TestLogMF extends TestCase {
- /**
- * Trace level.
- */
- private static final Level TRACE = getTraceLevel();
-
- /**
- * Gets Trace level.
- * Trace level was not defined prior to log4j 1.2.12.
- * @return trace level
- */
- private static Level getTraceLevel() {
- try {
- return (Level) Level.class.getField("TRACE").get(null);
- } catch(Exception ex) {
- return new Level(5000, "TRACE", 7);
- }
- }
-
- /**
- * Logger.
- */
- private final Logger logger = Logger.getLogger(
- "org.apache.log4j.formatter.TestLogMF");
-
- /**
- * Create the test case
- *
- * @param testName name of the test case
- */
- public TestLogMF(String testName) {
- super(testName);
- }
-
-
- /**
- * Post test clean up.
- */
- public void tearDown() {
- LogManager.resetConfiguration();
- }
-
- /**
- * Test class name when logging through LogMF.
- */
- public void testClassName() {
- CharArrayWriter writer = new CharArrayWriter();
- PatternLayout layout = new PatternLayout("%C");
- WriterAppender appender = new WriterAppender(layout, writer);
- appender.activateOptions();
- Logger.getRootLogger().addAppender(appender);
- LogMF.debug(logger, null, Math.PI);
- assertEquals(TestLogMF.class.getName(), writer.toString());
- }
-
- /**
- * Test LogMF.trace with null pattern.
- */
- public void testTraceNullPattern() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
- LogMF.trace(logger, null, Math.PI);
- assertNull(capture.getMessage());
- }
-
- /**
- * Test LogMF.trace with no-field pattern.
- */
- public void testTraceNoArg() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
- LogMF.trace(logger, "Hello, World", Math.PI);
- assertEquals("Hello, World", capture.getMessage());
- }
-
- /**
- * Test LogMF.trace with malformed pattern.
- */
- public void testTraceBadPattern() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
- LogMF.trace(logger, "Hello, {.", Math.PI);
- assertEquals("Hello, {.", capture.getMessage());
- }
-
- /**
- * Test LogMF.trace with missing argument.
- */
- public void testTraceMissingArg() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
- LogMF.trace(logger, "Hello, {0}World", new Object[0]);
- assertEquals("Hello, {0}World", capture.getMessage());
- }
-
- /**
- * Test LogMF.trace with single field pattern with string argument.
- */
- public void testTraceString() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
- LogMF.trace(logger, "Hello, {0}", "World");
- assertEquals("Hello, World", capture.getMessage());
- }
-
- /**
- * Test LogMF.trace with single field pattern with null argument.
- */
- public void testTraceNull() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
- LogMF.trace(logger, "Hello, {0}", (Object) null);
- assertEquals("Hello, null", capture.getMessage());
- }
-
- /**
- * Test LogMF.trace with single field pattern with int argument.
- */
- public void testTraceInt() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
-
- int val = 42;
- LogMF.trace(logger, "Iteration {0}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogMF.trace with single field pattern with byte argument.
- */
- public void testTraceByte() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
-
- byte val = 42;
- LogMF.trace(logger, "Iteration {0}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogMF.trace with single field pattern with short argument.
- */
- public void testTraceShort() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
-
- short val = 42;
- LogMF.trace(logger, "Iteration {0}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogMF.trace with single field pattern with long argument.
- */
- public void testTraceLong() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
-
- long val = 42;
- LogMF.trace(logger, "Iteration {0}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogMF.trace with single field pattern with char argument.
- */
- public void testTraceChar() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
-
- char val = 'C';
- LogMF.trace(logger, "Iteration {0}", val);
- assertEquals("Iteration C", capture.getMessage());
- }
-
- /**
- * Test LogMF.trace with single field pattern with boolean argument.
- */
- public void testTraceBoolean() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
-
- boolean val = true;
- LogMF.trace(logger, "Iteration {0}", val);
- assertEquals("Iteration true", capture.getMessage());
- }
-
- /**
- * Test LogMF.trace with single field pattern with float argument.
- */
- public void testTraceFloat() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
-
- float val = 3.14f;
- NumberFormat format = NumberFormat.getInstance();
- LogMF.trace(logger, "Iteration {0}", val);
- assertEquals("Iteration "+ format.format(val), capture.getMessage());
- }
-
- /**
- * Test LogMF.trace with single field pattern with double argument.
- */
- public void testTraceDouble() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
-
- double val = 3.14;
- NumberFormat format = NumberFormat.getInstance();
- LogMF.trace(logger, "Iteration {0}", val);
- assertEquals("Iteration "+ format.format(val), capture.getMessage());
- }
-
- /**
- * Test LogMF.trace with two arguments.
- */
- public void testTraceTwoArg() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
- LogMF.trace(logger, "{1}, {0}.", "World", "Hello");
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogMF.trace with three arguments.
- */
- public void testTraceThreeArg() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
- LogMF.trace(logger, "{1}{2} {0}.", "World", "Hello", ",");
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogMF.trace with four arguments.
- */
- public void testTraceFourArg() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
- LogMF.trace(logger, "{1}{2} {0}{3}", "World", "Hello", ",", ".");
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogMF.trace with Object[] argument.
- */
- public void testTraceArrayArg() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
-
- Object[] args = new Object[] { "World", "Hello", ",", "." };
- LogMF.trace(logger, "{1}{2} {0}{3}", args);
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogMF.trace with null Object[] argument.
- */
- public void testTraceNullArrayArg() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
-
- Object[] args = null;
- LogMF.trace(logger, "{1}{2} {0}{3}", args);
- assertEquals("{1}{2} {0}{3}", capture.getMessage());
- }
-
-
- /**
- * Test LogMF.debug with null pattern.
- */
- public void testDebugNullPattern() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- LogMF.debug(logger, null, Math.PI);
- assertEquals(null, capture.getMessage());
- }
-
- /**
- * Test LogMF.debug with no-field pattern.
- */
- public void testDebugNoArg() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- LogMF.debug(logger, "Hello, World", Math.PI);
- assertEquals("Hello, World", capture.getMessage());
- }
-
- /**
- * Test LogMF.debug with malformed pattern.
- */
- public void testDebugBadPattern() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- LogMF.debug(logger, "Hello, {.", Math.PI);
- assertEquals("Hello, {.", capture.getMessage());
- }
-
- /**
- * Test LogMF.debug with missing argument.
- */
- public void testDebugMissingArg() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- LogMF.debug(logger, "Hello, {0}World", new Object[0]);
- assertEquals("Hello, {0}World", capture.getMessage());
- }
-
- /**
- * Test LogMF.debug with single field pattern with string argument.
- */
- public void testDebugString() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- LogMF.debug(logger, "Hello, {0}", "World");
- assertEquals("Hello, World", capture.getMessage());
- }
-
- /**
- * Test LogMF.debug with single field pattern with null argument.
- */
- public void testDebugNull() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- LogMF.debug(logger, "Hello, {0}", (Object) null);
- assertEquals("Hello, null", capture.getMessage());
- }
-
- /**
- * Test LogMF.debug with single field pattern with int argument.
- */
- public void testDebugInt() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- int val = 42;
- LogMF.debug(logger, "Iteration {0}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogMF.debug with single field pattern with byte argument.
- */
- public void testDebugByte() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- byte val = 42;
- LogMF.debug(logger, "Iteration {0}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogMF.debug with single field pattern with short argument.
- */
- public void testDebugShort() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- short val = 42;
- LogMF.debug(logger, "Iteration {0}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogMF.debug with single field pattern with long argument.
- */
- public void testDebugLong() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- long val = 42;
- LogMF.debug(logger, "Iteration {0}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogMF.debug with single field pattern with char argument.
- */
- public void testDebugChar() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- char val = 'C';
- LogMF.debug(logger, "Iteration {0}", val);
- assertEquals("Iteration C", capture.getMessage());
- }
-
- /**
- * Test LogMF.debug with single field pattern with boolean argument.
- */
- public void testDebugBoolean() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- boolean val = true;
- LogMF.debug(logger, "Iteration {0}", val);
- assertEquals("Iteration true", capture.getMessage());
- }
-
- /**
- * Test LogMF.debug with single field pattern with float argument.
- */
- public void testDebugFloat() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- LogMF.debug(logger, "Iteration {0}", (float) Math.PI);
-
- String expected = MessageFormat.format("Iteration {0}",
- new Object[] { new Float(Math.PI) });
- assertEquals(expected, capture.getMessage());
- }
-
- /**
- * Test LogMF.debug with single field pattern with double argument.
- */
- public void testDebugDouble() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- LogMF.debug(logger, "Iteration {0}", Math.PI);
-
- String expected = MessageFormat.format("Iteration {0}",
- new Object[] { new Double(Math.PI) });
- assertEquals(expected, capture.getMessage());
- }
-
- /**
- * Test LogMF.debug with two arguments.
- */
- public void testDebugTwoArg() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- LogMF.debug(logger, "{1}, {0}.", "World", "Hello");
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogMF.debug with three arguments.
- */
- public void testDebugThreeArg() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- LogMF.debug(logger, "{1}{2} {0}.", "World", "Hello", ",");
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogMF.debug with four arguments.
- */
- public void testDebugFourArg() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- LogMF.debug(logger, "{1}{2} {0}{3}", "World", "Hello", ",", ".");
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogMF.debug with Object[] argument.
- */
- public void testDebugArrayArg() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- Object[] args = new Object[] { "World", "Hello", ",", "." };
- LogMF.debug(logger, "{1}{2} {0}{3}", args);
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogMF.debug with single field pattern with double argument.
- */
- public void testDebugDate() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- Date epoch = new Date(0);
- LogMF.debug(logger, "Iteration {0}", epoch);
-
- String expected = MessageFormat.format("Iteration {0}",
- new Object[] { epoch });
- String expected2 = "Iteration " + DateFormat.getDateTimeInstance(
- DateFormat.SHORT,
- DateFormat.SHORT).format(epoch);
- String actual = capture.getMessage();
- //
- // gcj has been observed to output 12/31/69 6:00:00 PM
- // instead of the expected 12/31/69 6:00 PM
- if (System.getProperty("java.vendor").indexOf("Free") == -1) {
- assertEquals(expected, actual);
- }
- assertEquals(expected2, actual);
- }
-
- /**
- * Test LogMF.debug with null Object[] argument.
- */
- public void testDebugNullArrayArg() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- Object[] args = null;
- LogMF.debug(logger, "{1}{2} {0}{3}", args);
- assertEquals("{1}{2} {0}{3}", capture.getMessage());
- }
-
- public void testDebugPercent() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- LogMF.debug(logger, "{0, number, percent}", Math.PI);
-
- String expected = java.text.MessageFormat.format("{0, number, percent}",
- new Object[] { new Double(Math.PI) });
- assertEquals(expected, capture.getMessage());
- }
-
- public void testDebugFullPrecisionAndPercent() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- LogMF.debug(logger, "{0}{0, number, percent}", Math.PI);
-
- String expected = java.text.MessageFormat.format("{0}{0, number, percent}",
- new Object[] { new Double(Math.PI) });
- assertEquals(expected, capture.getMessage());
- }
-
- public void testDebugQuoted() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- LogMF.debug(logger, "'{0}'", "World");
- assertEquals("{0}", capture.getMessage());
- }
-
- /**
- * Test LogMF.info with null pattern.
- */
- public void testInfoNullPattern() {
- LogCapture capture = new LogCapture(Level.INFO);
- LogMF.info(logger, null, Math.PI);
- assertNull(capture.getMessage());
- }
-
- /**
- * Test LogMF.info with no-field pattern.
- */
- public void testInfoNoArg() {
- LogCapture capture = new LogCapture(Level.INFO);
- LogMF.info(logger, "Hello, World", Math.PI);
- assertEquals("Hello, World", capture.getMessage());
- }
-
- /**
- * Test LogMF.info with malformed pattern.
- */
- public void testInfoBadPattern() {
- LogCapture capture = new LogCapture(Level.INFO);
- LogMF.info(logger, "Hello, {.", Math.PI);
- assertEquals("Hello, {.", capture.getMessage());
- }
-
- /**
- * Test LogMF.info with missing argument.
- */
- public void testInfoMissingArg() {
- LogCapture capture = new LogCapture(Level.INFO);
- LogMF.info(logger, "Hello, {0}World", new Object[0]);
- assertEquals("Hello, {0}World", capture.getMessage());
- }
-
- /**
- * Test LogMF.info with single field pattern with string argument.
- */
- public void testInfoString() {
- LogCapture capture = new LogCapture(Level.INFO);
- LogMF.info(logger, "Hello, {0}", "World");
- assertEquals("Hello, World", capture.getMessage());
- }
-
- /**
- * Test LogMF.info with single field pattern with null argument.
- */
- public void testInfoNull() {
- LogCapture capture = new LogCapture(Level.INFO);
- LogMF.info(logger, "Hello, {0}", (Object) null);
- assertEquals("Hello, null", capture.getMessage());
- }
-
- /**
- * Test LogMF.info with single field pattern with int argument.
- */
- public void testInfoInt() {
- LogCapture capture = new LogCapture(Level.INFO);
- int val = 42;
- LogMF.info(logger, "Iteration {0}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogMF.info with single field pattern with byte argument.
- */
- public void testInfoByte() {
- LogCapture capture = new LogCapture(Level.INFO);
- byte val = 42;
- LogMF.info(logger, "Iteration {0}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogMF.info with single field pattern with short argument.
- */
- public void testInfoShort() {
- LogCapture capture = new LogCapture(Level.INFO);
- short val = 42;
- LogMF.info(logger, "Iteration {0}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogMF.info with single field pattern with long argument.
- */
- public void testInfoLong() {
- LogCapture capture = new LogCapture(Level.INFO);
- long val = 42;
- LogMF.info(logger, "Iteration {0}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogMF.info with single field pattern with char argument.
- */
- public void testInfoChar() {
- LogCapture capture = new LogCapture(Level.INFO);
- char val = 'C';
- LogMF.info(logger, "Iteration {0}", val);
- assertEquals("Iteration C", capture.getMessage());
- }
-
- /**
- * Test LogMF.info with single field pattern with boolean argument.
- */
- public void testInfoBoolean() {
- LogCapture capture = new LogCapture(Level.INFO);
- boolean val = true;
- LogMF.info(logger, "Iteration {0}", val);
- assertEquals("Iteration true", capture.getMessage());
- }
-
- /**
- * Test LogMF.info with single field pattern with float argument.
- */
- public void testInfoFloat() {
- LogCapture capture = new LogCapture(Level.INFO);
- LogMF.info(logger, "Iteration {0}", (float) Math.PI);
-
- String expected = MessageFormat.format("Iteration {0}",
- new Object[] { new Float(Math.PI) });
- assertEquals(expected, capture.getMessage());
- }
-
- /**
- * Test LogMF.info with single field pattern with double argument.
- */
- public void testInfoDouble() {
- LogCapture capture = new LogCapture(Level.INFO);
- LogMF.info(logger, "Iteration {0}", Math.PI);
-
- String expected = MessageFormat.format("Iteration {0}",
- new Object[] { new Double(Math.PI) });
- assertEquals(expected, capture.getMessage());
- }
-
- /**
- * Test LogMF.info with two arguments.
- */
- public void testInfoTwoArg() {
- LogCapture capture = new LogCapture(Level.INFO);
- LogMF.info(logger, "{1}, {0}.", "World", "Hello");
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogMF.info with three arguments.
- */
- public void testInfoThreeArg() {
- LogCapture capture = new LogCapture(Level.INFO);
- LogMF.info(logger, "{1}{2} {0}.", "World", "Hello", ",");
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogMF.info with four arguments.
- */
- public void testInfoFourArg() {
- LogCapture capture = new LogCapture(Level.INFO);
- LogMF.info(logger, "{1}{2} {0}{3}", "World", "Hello", ",", ".");
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogMF.info with Object[] argument.
- */
- public void testInfoArrayArg() {
- LogCapture capture = new LogCapture(Level.INFO);
- Object[] args = new Object[] { "World", "Hello", ",", "." };
- LogMF.info(logger, "{1}{2} {0}{3}", args);
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogMF.warn with null pattern.
- */
- public void testWarnNullPattern() {
- LogCapture capture = new LogCapture(Level.WARN);
- LogMF.warn(logger, null, Math.PI);
- assertNull(capture.getMessage());
- }
-
- /**
- * Test LogMF.warn with no-field pattern.
- */
- public void testWarnNoArg() {
- LogCapture capture = new LogCapture(Level.WARN);
- LogMF.warn(logger, "Hello, World", Math.PI);
- assertEquals("Hello, World", capture.getMessage());
- }
-
- /**
- * Test LogMF.warn with malformed pattern.
- */
- public void testWarnBadPattern() {
- LogCapture capture = new LogCapture(Level.WARN);
- LogMF.warn(logger, "Hello, {.", Math.PI);
- assertEquals("Hello, {.", capture.getMessage());
- }
-
- /**
- * Test LogMF.warn with missing argument.
- */
- public void testWarnMissingArg() {
- LogCapture capture = new LogCapture(Level.WARN);
- LogMF.warn(logger, "Hello, {0}World", new Object[0]);
- assertEquals("Hello, {0}World", capture.getMessage());
- }
-
- /**
- * Test LogMF.warn with single field pattern with string argument.
- */
- public void testWarnString() {
- LogCapture capture = new LogCapture(Level.WARN);
- LogMF.warn(logger, "Hello, {0}", "World");
- assertEquals("Hello, World", capture.getMessage());
- }
-
- /**
- * Test LogMF.warn with single field pattern with null argument.
- */
- public void testWarnNull() {
- LogCapture capture = new LogCapture(Level.WARN);
- LogMF.warn(logger, "Hello, {0}", (Object) null);
- assertEquals("Hello, null", capture.getMessage());
- }
-
- /**
- * Test LogMF.warn with single field pattern with int argument.
- */
- public void testWarnInt() {
- LogCapture capture = new LogCapture(Level.WARN);
- int val = 42;
- LogMF.warn(logger, "Iteration {0}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogMF.warn with single field pattern with byte argument.
- */
- public void testWarnByte() {
- LogCapture capture = new LogCapture(Level.WARN);
- byte val = 42;
- LogMF.warn(logger, "Iteration {0}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogMF.warn with single field pattern with short argument.
- */
- public void testWarnShort() {
- LogCapture capture = new LogCapture(Level.WARN);
- short val = 42;
- LogMF.warn(logger, "Iteration {0}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogMF.warn with single field pattern with long argument.
- */
- public void testWarnLong() {
- LogCapture capture = new LogCapture(Level.WARN);
- long val = 42;
- LogMF.warn(logger, "Iteration {0}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogMF.warn with single field pattern with char argument.
- */
- public void testWarnChar() {
- LogCapture capture = new LogCapture(Level.WARN);
- char val = 'C';
- LogMF.warn(logger, "Iteration {0}", val);
- assertEquals("Iteration C", capture.getMessage());
- }
-
- /**
- * Test LogMF.warn with single field pattern with boolean argument.
- */
- public void testWarnBoolean() {
- LogCapture capture = new LogCapture(Level.WARN);
- boolean val = true;
- LogMF.warn(logger, "Iteration {0}", val);
- assertEquals("Iteration true", capture.getMessage());
- }
-
- /**
- * Test LogMF.warn with single field pattern with float argument.
- */
- public void testWarnFloat() {
- LogCapture capture = new LogCapture(Level.WARN);
- LogMF.warn(logger, "Iteration {0}", (float) Math.PI);
-
- String expected = MessageFormat.format("Iteration {0}",
- new Object[] { new Float(Math.PI) });
- assertEquals(expected, capture.getMessage());
- }
-
- /**
- * Test LogMF.debug with single field pattern with double argument.
- */
- public void testWarnDouble() {
- LogCapture capture = new LogCapture(Level.WARN);
- LogMF.warn(logger, "Iteration {0}", Math.PI);
-
- String expected = MessageFormat.format("Iteration {0}",
- new Object[] { new Double(Math.PI) });
- assertEquals(expected, capture.getMessage());
- }
-
- /**
- * Test LogMF.warn with two arguments.
- */
- public void testWarnTwoArg() {
- LogCapture capture = new LogCapture(Level.WARN);
- LogMF.warn(logger, "{1}, {0}.", "World", "Hello");
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogMF.warn with three arguments.
- */
- public void testWarnThreeArg() {
- LogCapture capture = new LogCapture(Level.WARN);
- LogMF.warn(logger, "{1}{2} {0}.", "World", "Hello", ",");
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogMF.debug with four arguments.
- */
- public void testWarnFourArg() {
- LogCapture capture = new LogCapture(Level.WARN);
- LogMF.warn(logger, "{1}{2} {0}{3}", "World", "Hello", ",", ".");
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogMF.warn with Object[] argument.
- */
- public void testWarnArrayArg() {
- LogCapture capture = new LogCapture(Level.WARN);
- Object[] args = new Object[] { "World", "Hello", ",", "." };
- LogMF.warn(logger, "{1}{2} {0}{3}", args);
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogMF.log with null pattern.
- */
- public void testLogNullPattern() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.log(logger, Level.ERROR, null, Math.PI);
- assertNull(capture.getMessage());
- }
-
- /**
- * Test LogMF.log with no-field pattern.
- */
- public void testLogNoArg() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.log(logger, Level.ERROR, "Hello, World", Math.PI);
- assertEquals("Hello, World", capture.getMessage());
- }
-
- /**
- * Test LogMF.log with malformed pattern.
- */
- public void testLogBadPattern() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.log(logger, Level.ERROR, "Hello, {.", Math.PI);
- assertEquals("Hello, {.", capture.getMessage());
- }
-
- /**
- * Test LogMF.log with missing argument.
- */
- public void testLogMissingArg() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.log(logger, Level.ERROR, "Hello, {0}World", new Object[0]);
- assertEquals("Hello, {0}World", capture.getMessage());
- }
-
- /**
- * Test LogMF.log with single field pattern with string argument.
- */
- public void testLogString() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.log(logger, Level.ERROR, "Hello, {0}", "World");
- assertEquals("Hello, World", capture.getMessage());
- }
-
- /**
- * Test LogMF.log with single field pattern with null argument.
- */
- public void testLogNull() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.log(logger, Level.ERROR, "Hello, {0}", (Object) null);
- assertEquals("Hello, null", capture.getMessage());
- }
-
- /**
- * Test LogMF.log with single field pattern with int argument.
- */
- public void testLogInt() {
- LogCapture capture = new LogCapture(Level.ERROR);
- int val = 42;
- LogMF.log(logger, Level.ERROR, "Iteration {0}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogMF.log with single field pattern with byte argument.
- */
- public void testLogByte() {
- LogCapture capture = new LogCapture(Level.ERROR);
- byte val = 42;
- LogMF.log(logger, Level.ERROR, "Iteration {0}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogMF.log with single field pattern with short argument.
- */
- public void testLogShort() {
- LogCapture capture = new LogCapture(Level.ERROR);
- short val = 42;
- LogMF.log(logger, Level.ERROR, "Iteration {0}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogMF.log with single field pattern with long argument.
- */
- public void testLogLong() {
- LogCapture capture = new LogCapture(Level.ERROR);
- long val = 42;
- LogMF.log(logger, Level.ERROR, "Iteration {0}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogMF.log with single field pattern with char argument.
- */
- public void testLogChar() {
- LogCapture capture = new LogCapture(Level.ERROR);
- char val = 'C';
- LogMF.log(logger, Level.ERROR, "Iteration {0}", val);
- assertEquals("Iteration C", capture.getMessage());
- }
-
- /**
- * Test LogMF.log with single field pattern with boolean argument.
- */
- public void testLogBoolean() {
- LogCapture capture = new LogCapture(Level.ERROR);
- boolean val = true;
- LogMF.log(logger, Level.ERROR, "Iteration {0}", val);
- assertEquals("Iteration true", capture.getMessage());
- }
-
- /**
- * Test LogMF.log with single field pattern with float argument.
- */
- public void testLogFloat() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.log(logger, Level.ERROR, "Iteration {0}", (float) Math.PI);
-
- String expected = MessageFormat.format("Iteration {0}",
- new Object[] { new Float(Math.PI) });
- assertEquals(expected, capture.getMessage());
- }
-
- /**
- * Test LogMF.log with single field pattern with double argument.
- */
- public void testLogDouble() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.log(logger, Level.ERROR, "Iteration {0}", Math.PI);
-
- String expected = MessageFormat.format("Iteration {0}",
- new Object[] { new Double(Math.PI) });
- assertEquals(expected, capture.getMessage());
- }
-
- /**
- * Test LogMF.log with two arguments.
- */
- public void testLogTwoArg() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.log(logger, Level.ERROR, "{1}, {0}.", "World", "Hello");
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogMF.log with three arguments.
- */
- public void testLogThreeArg() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.log(logger, Level.ERROR, "{1}{2} {0}.", "World", "Hello", ",");
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogMF.log with four arguments.
- */
- public void testLogFourArg() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.log(logger, Level.ERROR, "{1}{2} {0}{3}", "World", "Hello", ",", ".");
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogMF.log with Object[] argument.
- */
- public void testLogArrayArg() {
- LogCapture capture = new LogCapture(Level.ERROR);
- Object[] args = new Object[] { "World", "Hello", ",", "." };
- LogMF.log(logger, Level.ERROR, "{1}{2} {0}{3}", args);
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Bundle name for resource bundle tests.
- */
- private static final String BUNDLE_NAME =
- "org.apache.log4j.TestLogMFPatterns";
-
- /**
- * Test LogMF.logrb with null bundle name.
- */
- public void testLogrbNullBundle() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.logrb(logger, Level.ERROR, null, "Iteration0", Math.PI);
- assertEquals("Iteration0", capture.getMessage());
- }
-
- /**
- * Test LogMF.logrb with null key.
- */
- public void testLogrbNullKey() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.logrb(logger, Level.ERROR, BUNDLE_NAME, null, Math.PI);
- assertNull(capture.getMessage());
- }
-
- /**
- * Test LogMF.logrb with no-field pattern.
- */
- public void testLogrbNoArg() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Hello1", Math.PI);
- assertEquals("Hello, World", capture.getMessage());
- }
-
- /**
- * Test LogMF.logrb with malformed pattern.
- */
- public void testLogrbBadPattern() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Malformed", Math.PI);
- assertEquals("Hello, {.", capture.getMessage());
- }
-
- /**
- * Test LogMF.logrb with missing argument.
- */
- public void testLogrbMissingArg() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Hello2", new Object[0]);
- assertEquals("Hello, {0}World", capture.getMessage());
- }
-
- /**
- * Test LogMF.logrb with single field pattern with string argument.
- */
- public void testLogrbString() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Hello3", "World");
- assertEquals("Hello, World", capture.getMessage());
- }
-
- /**
- * Test LogMF.logrb with single field pattern with null argument.
- */
- public void testLogrbNull() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Hello3", (Object) null);
- assertEquals("Hello, null", capture.getMessage());
- }
-
- /**
- * Test LogMF.logrb with single field pattern with int argument.
- */
- public void testLogrbInt() {
- LogCapture capture = new LogCapture(Level.ERROR);
- int val = 42;
- LogMF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Iteration0", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogMF.logrb with single field pattern with byte argument.
- */
- public void testLogrbByte() {
- LogCapture capture = new LogCapture(Level.ERROR);
- byte val = 42;
- LogMF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Iteration0", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogMF.logrb with single field pattern with short argument.
- */
- public void testLogrbShort() {
- LogCapture capture = new LogCapture(Level.ERROR);
- short val = 42;
- LogMF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Iteration0", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogMF.logrb with single field pattern with long argument.
- */
- public void testLogrbLong() {
- LogCapture capture = new LogCapture(Level.ERROR);
- long val = 42;
- LogMF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Iteration0", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogMF.logrb with single field pattern with char argument.
- */
- public void testLogrbChar() {
- LogCapture capture = new LogCapture(Level.ERROR);
- char val = 'C';
- LogMF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Iteration0", val);
- assertEquals("Iteration C", capture.getMessage());
- }
-
- /**
- * Test LogMF.logrb with single field pattern with boolean argument.
- */
- public void testLogrbBoolean() {
- LogCapture capture = new LogCapture(Level.ERROR);
- boolean val = true;
- LogMF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Iteration0", val);
- assertEquals("Iteration true", capture.getMessage());
- }
-
- /**
- * Test LogMF.logrb with single field pattern with float argument.
- */
- public void testLogrbFloat() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Iteration0", (float) Math.PI);
-
- String expected = MessageFormat.format("Iteration {0}",
- new Object[] { new Float(Math.PI) });
- assertEquals(expected, capture.getMessage());
- }
-
- /**
- * Test LogMF.logrb with single field pattern with double argument.
- */
- public void testLogrbDouble() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Iteration0", Math.PI);
-
- String expected = MessageFormat.format("Iteration {0}",
- new Object[] { new Double(Math.PI) });
- assertEquals(expected, capture.getMessage());
- }
-
- /**
- * Test LogMF.logrb with two arguments.
- */
- public void testLogrbTwoArg() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.logrb(logger, Level.ERROR,
- BUNDLE_NAME, "Hello4", "World", "Hello");
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogMF.logrb with three arguments.
- */
- public void testLogrbThreeArg() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.logrb(logger, Level.ERROR,
- BUNDLE_NAME, "Hello5", "World", "Hello", ",");
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogMF.logrb with four arguments.
- */
- public void testLogrbFourArg() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.logrb(logger, Level.ERROR,
- BUNDLE_NAME, "Hello6", "World", "Hello", ",", ".");
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogMF.logrb with Object[] argument.
- */
- public void testLogrbArrayArg() {
- LogCapture capture = new LogCapture(Level.ERROR);
- Object[] args = new Object[] { "World", "Hello", ",", "." };
- LogMF.logrb(logger, Level.ERROR,
- BUNDLE_NAME, "Hello6", args);
- assertEquals("Hello, World.", capture.getMessage());
- }
-
-
- /**
- * Test LogMF.info with a pattern containing {9} and one argument.
- */
- public void testInfo1ParamBrace9() {
- LogCapture capture = new LogCapture(Level.INFO);
- LogMF.info(logger, "Hello, {9}{0}", "World");
- assertEquals("Hello, {9}World", capture.getMessage());
- }
-
- /**
- * Test LogMF.info with a pattern containing {9} and two arguments.
- */
- public void testInfo2ParamBrace9() {
- LogCapture capture = new LogCapture(Level.INFO);
- LogMF.info(logger, "{1}, {9}{0}", "World", "Hello");
- assertEquals("Hello, {9}World", capture.getMessage());
- }
-
- /**
- * Test LogMF.info with a pattern containing {9} and two arguments.
- */
- public void testInfo10ParamBrace9() {
- LogCapture capture = new LogCapture(Level.INFO);
- LogMF.info(logger, "{1}, {9}{0}",
- new Object[] { "World", "Hello", null, null, null,
- null, null, null, null, "New " });
- assertEquals("Hello, New World", capture.getMessage());
- }
-
- /**
- * Test LogMF.info with indexes just outside of 0 to 9.
- */
- public void testInfo1ParamBraceSlashColon() {
- LogCapture capture = new LogCapture(Level.INFO);
- String pattern = "Hello, {/}{0}{:}";
- LogMF.info(logger, pattern, "World");
- assertEquals(pattern, capture.getMessage());
- }
-
-
-}
diff --git a/src/test/java/org/apache/log4j/TestLogSF.java b/src/test/java/org/apache/log4j/TestLogSF.java
deleted file mode 100755
index 330cd9b..0000000
--- a/src/test/java/org/apache/log4j/TestLogSF.java
+++ /dev/null
@@ -1,1191 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.log4j;
-
-import junit.framework.TestCase;
-
-import java.io.CharArrayWriter;
-
-
-/**
- * Unit test for LogSF.
- */
-public class TestLogSF extends TestCase {
- /**
- * Trace level.
- */
- private static final Level TRACE = getTraceLevel();
-
- /**
- * Gets Trace level.
- * Trace level was not defined prior to log4j 1.2.12.
- * @return trace level
- */
- private static Level getTraceLevel() {
- try {
- return (Level) Level.class.getField("TRACE").get(null);
- } catch(Exception ex) {
- return new Level(5000, "TRACE", 7);
- }
- }
-
- /**
- * Logger.
- */
- private final Logger logger = Logger.getLogger(
- "org.apache.log4j.formatter.TestLogSF");
-
- /**
- * Create the test case
- *
- * @param testName name of the test case
- */
- public TestLogSF(String testName) {
- super(testName);
- }
-
-
- /**
- * Post test clean up.
- */
- public void tearDown() {
- LogManager.resetConfiguration();
- }
-
- /**
- * Test class name when logging through LogSF.
- */
- public void testClassName() {
- CharArrayWriter writer = new CharArrayWriter();
- PatternLayout layout = new PatternLayout("%C");
- WriterAppender appender = new WriterAppender(layout, writer);
- appender.activateOptions();
- Logger.getRootLogger().addAppender(appender);
- LogSF.debug(logger, null, Math.PI);
- assertEquals(TestLogSF.class.getName(), writer.toString());
- }
-
-
-
- /**
- * Test LogSF.trace with null pattern.
- */
- public void testTraceNullPattern() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
- LogSF.trace(logger, null, Math.PI);
- assertNull(capture.getMessage());
- }
-
- /**
- * Test LogSF.trace with no-field pattern.
- */
- public void testTraceNoArg() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
- LogSF.trace(logger, "Hello, World", Math.PI);
- assertEquals("Hello, World", capture.getMessage());
- }
-
- /**
- * Test LogSF.trace with malformed pattern.
- */
- public void testTraceBadPattern() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
- LogSF.trace(logger, "Hello, {.", Math.PI);
- assertEquals("Hello, {.", capture.getMessage());
- }
-
- /**
- * Test LogSF.trace with missing argument.
- */
- public void testTraceMissingArg() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
- LogSF.trace(logger, "Hello, {}World", new Object[0]);
- assertEquals("Hello, {}World", capture.getMessage());
- }
-
- /**
- * Test LogSF.trace with single field pattern with string argument.
- */
- public void testTraceString() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
- LogSF.trace(logger, "Hello, {}", "World");
- assertEquals("Hello, World", capture.getMessage());
- }
-
- /**
- * Test LogSF.trace with single field pattern with null argument.
- */
- public void testTraceNull() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
- LogSF.trace(logger, "Hello, {}", (Object) null);
- assertEquals("Hello, null", capture.getMessage());
- }
-
- /**
- * Test LogSF.trace with single field pattern with int argument.
- */
- public void testTraceInt() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
- int val = 42;
- LogSF.trace(logger, "Iteration {}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogSF.trace with single field pattern with byte argument.
- */
- public void testTraceByte() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
- byte val = 42;
- LogSF.trace(logger, "Iteration {}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogSF.trace with single field pattern with short argument.
- */
- public void testTraceShort() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
- short val = 42;
- LogSF.trace(logger, "Iteration {}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogSF.trace with single field pattern with long argument.
- */
- public void testTraceLong() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
- long val = 42;
- LogSF.trace(logger, "Iteration {}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogSF.trace with single field pattern with char argument.
- */
- public void testTraceChar() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
- char val = 'C';
- LogSF.trace(logger, "Iteration {}", val);
- assertEquals("Iteration C", capture.getMessage());
- }
-
- /**
- * Test LogSF.trace with single field pattern with boolean argument.
- */
- public void testTraceBoolean() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
- boolean val = true;
- LogSF.trace(logger, "Iteration {}", val);
- assertEquals("Iteration true", capture.getMessage());
- }
-
- /**
- * Test LogSF.trace with single field pattern with float argument.
- */
- public void testTraceFloat() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
- float val = 3.14f;
- LogSF.trace(logger, "Iteration {}", val);
- assertEquals("Iteration " + String.valueOf(val), capture.getMessage());
- }
-
- /**
- * Test LogSF.trace with single field pattern with double argument.
- */
- public void testTraceDouble() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
- double val = 3.14;
- LogSF.trace(logger, "Iteration {}", val);
- assertEquals("Iteration " + String.valueOf(val), capture.getMessage());
- }
-
- /**
- * Test LogSF.trace with two arguments.
- */
- public void testTraceTwoArg() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
- LogSF.trace(logger, "{}, {}.", "Hello", "World");
- assertEquals("Hello, World.", capture.getMessage());
-
- }
-
- /**
- * Test LogSF.trace with three arguments.
- */
- public void testTraceThreeArg() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
- LogSF.trace(logger, "{}{} {}.", "Hello", ",", "World");
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogSF.trace with Object[] argument.
- */
- public void testTraceFourArg() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
- LogSF.trace(logger, "{}{} {}{}", "Hello", ",", "World", ".");
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogSF.trace with Object[] argument.
- */
- public void testTraceArrayArg() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
- Object[] args = new Object[] { "Hello", ",", "World", "." };
- LogSF.trace(logger, "{}{} {}{}", args);
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogSF.trace with null Object[] argument.
- */
- public void testTraceNullArrayArg() {
- LogCapture capture = new LogCapture(TRACE);
- logger.setLevel(TRACE);
- Object[] args = null;
- LogSF.trace(logger, "{}{} {}{}", args);
- assertEquals("{}{} {}{}", capture.getMessage());
- }
-
-
-
- /**
- * Test LogSF.debug with null pattern.
- */
- public void testDebugNullPattern() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- LogSF.debug(logger, null, Math.PI);
- assertNull(capture.getMessage());
- }
-
- /**
- * Test LogSF.debug with no-field pattern.
- */
- public void testDebugNoArg() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- LogSF.debug(logger, "Hello, World", Math.PI);
- assertEquals("Hello, World", capture.getMessage());
- }
-
- /**
- * Test LogSF.debug with malformed pattern.
- */
- public void testDebugBadPattern() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- LogSF.debug(logger, "Hello, {.", Math.PI);
- assertEquals("Hello, {.", capture.getMessage());
- }
-
- /**
- * Test LogSF.debug with missing argument.
- */
- public void testDebugMissingArg() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- LogSF.debug(logger, "Hello, {}World", new Object[0]);
- assertEquals("Hello, {}World", capture.getMessage());
- }
-
- /**
- * Test LogSF.debug with single field pattern with string argument.
- */
- public void testDebugString() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- LogSF.debug(logger, "Hello, {}", "World");
- assertEquals("Hello, World", capture.getMessage());
- }
-
- /**
- * Test LogSF.debug with single field pattern with null argument.
- */
- public void testDebugNull() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- LogSF.debug(logger, "Hello, {}", (Object) null);
- assertEquals("Hello, null", capture.getMessage());
- }
-
- /**
- * Test LogSF.debug with single field pattern with int argument.
- */
- public void testDebugInt() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- int val = 42;
- LogSF.debug(logger, "Iteration {}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogSF.debug with single field pattern with byte argument.
- */
- public void testDebugByte() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- byte val = 42;
- LogSF.debug(logger, "Iteration {}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogSF.debug with single field pattern with short argument.
- */
- public void testDebugShort() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- short val = 42;
- LogSF.debug(logger, "Iteration {}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogSF.debug with single field pattern with long argument.
- */
- public void testDebugLong() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- long val = 42;
- LogSF.debug(logger, "Iteration {}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogSF.debug with single field pattern with char argument.
- */
- public void testDebugChar() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- char val = 'C';
- LogSF.debug(logger, "Iteration {}", val);
- assertEquals("Iteration C", capture.getMessage());
- }
-
- /**
- * Test LogSF.debug with single field pattern with boolean argument.
- */
- public void testDebugBoolean() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- boolean val = true;
- LogSF.debug(logger, "Iteration {}", val);
- assertEquals("Iteration true", capture.getMessage());
- }
-
- /**
- * Test LogSF.debug with single field pattern with float argument.
- */
- public void testDebugFloat() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- float val = 3.14f;
- LogSF.debug(logger, "Iteration {}", val);
- assertEquals("Iteration " + String.valueOf(val), capture.getMessage());
- }
-
- /**
- * Test LogSF.debug with single field pattern with double argument.
- */
- public void testDebugDouble() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- double val = 3.14;
- LogSF.debug(logger, "Iteration {}", val);
- assertEquals("Iteration " + String.valueOf(val), capture.getMessage());
- }
-
- /**
- * Test LogSF.debug with two arguments.
- */
- public void testDebugTwoArg() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- LogSF.debug(logger, "{}, {}.", "Hello", "World");
- assertEquals("Hello, World.", capture.getMessage());
-
- }
-
- /**
- * Test LogSF.debug with three arguments.
- */
- public void testDebugThreeArg() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- LogSF.debug(logger, "{}{} {}.", "Hello", ",", "World");
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogSF.debug with four arguments.
- */
- public void testDebugFourArg() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- LogSF.debug(logger, "{}{} {}{}", "Hello", ",", "World", ".");
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogSF.debug with Object[] argument.
- */
- public void testDebugArrayArg() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- Object[] args = new Object[] { "Hello", ",", "World", "." };
- LogSF.debug(logger, "{}{} {}{}", args);
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogSF.debug with null Object[] argument.
- */
- public void testDebugNullArrayArg() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- Object[] args = null;
- LogSF.debug(logger, "{}{} {}{}", args);
- assertEquals("{}{} {}{}", capture.getMessage());
- }
-
- /**
- * Test LogSF.info with null pattern.
- */
- public void testInfoNullPattern() {
- LogCapture capture = new LogCapture(Level.INFO);
- LogSF.info(logger, null, Math.PI);
- assertNull(capture.getMessage());
- }
-
- /**
- * Test LogSF.info with no-field pattern.
- */
- public void testInfoNoArg() {
- LogCapture capture = new LogCapture(Level.INFO);
- LogSF.info(logger, "Hello, World", Math.PI);
- assertEquals("Hello, World", capture.getMessage());
- }
-
- /**
- * Test LogSF.info with malformed pattern.
- */
- public void testInfoBadPattern() {
- LogCapture capture = new LogCapture(Level.INFO);
- LogSF.info(logger, "Hello, {.", Math.PI);
- assertEquals("Hello, {.", capture.getMessage());
- }
-
- /**
- * Test LogSF.info with missing argument.
- */
- public void testInfoMissingArg() {
- LogCapture capture = new LogCapture(Level.INFO);
- LogSF.info(logger, "Hello, {}World", new Object[0]);
- assertEquals("Hello, {}World", capture.getMessage());
- }
-
- /**
- * Test LogSF.info with single field pattern with string argument.
- */
- public void testInfoString() {
- LogCapture capture = new LogCapture(Level.INFO);
- LogSF.info(logger, "Hello, {}", "World");
- assertEquals("Hello, World", capture.getMessage());
- }
-
- /**
- * Test LogSF.info with single field pattern with null argument.
- */
- public void testInfoNull() {
- LogCapture capture = new LogCapture(Level.INFO);
- LogSF.info(logger, "Hello, {}", (Object) null);
- assertEquals("Hello, null", capture.getMessage());
- }
-
- /**
- * Test LogSF.info with single field pattern with int argument.
- */
- public void testInfoInt() {
- LogCapture capture = new LogCapture(Level.INFO);
- int val = 42;
- LogSF.info(logger, "Iteration {}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogSF.info with single field pattern with byte argument.
- */
- public void testInfoByte() {
- LogCapture capture = new LogCapture(Level.INFO);
- byte val = 42;
- LogSF.info(logger, "Iteration {}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogSF.info with single field pattern with short argument.
- */
- public void testInfoShort() {
- LogCapture capture = new LogCapture(Level.INFO);
- short val = 42;
- LogSF.info(logger, "Iteration {}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogSF.info with single field pattern with long argument.
- */
- public void testInfoLong() {
- LogCapture capture = new LogCapture(Level.INFO);
- long val = 42;
- LogSF.info(logger, "Iteration {}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogSF.info with single field pattern with char argument.
- */
- public void testInfoChar() {
- LogCapture capture = new LogCapture(Level.INFO);
- char val = 'C';
- LogSF.info(logger, "Iteration {}", val);
- assertEquals("Iteration C", capture.getMessage());
- }
-
- /**
- * Test LogSF.info with single field pattern with boolean argument.
- */
- public void testInfoBoolean() {
- LogCapture capture = new LogCapture(Level.INFO);
- boolean val = true;
- LogSF.info(logger, "Iteration {}", val);
- assertEquals("Iteration true", capture.getMessage());
- }
-
- /**
- * Test LogSF.info with single field pattern with float argument.
- */
- public void testInfoFloat() {
- LogCapture capture = new LogCapture(Level.INFO);
- float val = 3.14f;
- LogSF.info(logger, "Iteration {}", val);
- assertEquals("Iteration " + String.valueOf(val), capture.getMessage());
- }
-
- /**
- * Test LogSF.info with single field pattern with double argument.
- */
- public void testInfoDouble() {
- LogCapture capture = new LogCapture(Level.INFO);
- double val = 3.14;
- LogSF.info(logger, "Iteration {}", val);
- assertEquals("Iteration " + String.valueOf(val), capture.getMessage());
- }
-
- /**
- * Test LogSF.info with two arguments.
- */
- public void testInfoTwoArg() {
- LogCapture capture = new LogCapture(Level.INFO);
- LogSF.info(logger, "{}, {}.", "Hello", "World");
- assertEquals("Hello, World.", capture.getMessage());
-
- }
-
- /**
- * Test LogSF.info with three arguments.
- */
- public void testInfoThreeArg() {
- LogCapture capture = new LogCapture(Level.INFO);
- LogSF.info(logger, "{}{} {}.", "Hello", ",", "World");
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogSF.info with Object[] argument.
- */
- public void testInfoArrayArg() {
- LogCapture capture = new LogCapture(Level.INFO);
- Object[] args = new Object[] { "Hello", ",", "World", "." };
- LogSF.info(logger, "{}{} {}{}", args);
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogSF.warn with null pattern.
- */
- public void testWarnNullPattern() {
- LogCapture capture = new LogCapture(Level.WARN);
- LogSF.warn(logger, null, Math.PI);
- assertNull(capture.getMessage());
- }
-
- /**
- * Test LogSF.warn with no-field pattern.
- */
- public void testWarnNoArg() {
- LogCapture capture = new LogCapture(Level.WARN);
- LogSF.warn(logger, "Hello, World", Math.PI);
- assertEquals("Hello, World", capture.getMessage());
- }
-
- /**
- * Test LogSF.warn with malformed pattern.
- */
- public void testWarnBadPattern() {
- LogCapture capture = new LogCapture(Level.WARN);
- LogSF.warn(logger, "Hello, {.", Math.PI);
- assertEquals("Hello, {.", capture.getMessage());
- }
-
- /**
- * Test LogSF.warn with missing argument.
- */
- public void testWarnMissingArg() {
- LogCapture capture = new LogCapture(Level.WARN);
- LogSF.warn(logger, "Hello, {}World", new Object[0]);
- assertEquals("Hello, {}World", capture.getMessage());
- }
-
- /**
- * Test LogSF.warn with single field pattern with string argument.
- */
- public void testWarnString() {
- LogCapture capture = new LogCapture(Level.WARN);
- LogSF.warn(logger, "Hello, {}", "World");
- assertEquals("Hello, World", capture.getMessage());
- }
-
- /**
- * Test LogSF.warn with single field pattern with null argument.
- */
- public void testWarnNull() {
- LogCapture capture = new LogCapture(Level.WARN);
- LogSF.warn(logger, "Hello, {}", (Object) null);
- assertEquals("Hello, null", capture.getMessage());
- }
-
- /**
- * Test LogSF.warn with single field pattern with int argument.
- */
- public void testWarnInt() {
- LogCapture capture = new LogCapture(Level.WARN);
- int val = 42;
- LogSF.warn(logger, "Iteration {}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogSF.warn with single field pattern with byte argument.
- */
- public void testWarnByte() {
- LogCapture capture = new LogCapture(Level.WARN);
- byte val = 42;
- LogSF.warn(logger, "Iteration {}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogSF.warn with single field pattern with short argument.
- */
- public void testWarnShort() {
- LogCapture capture = new LogCapture(Level.WARN);
- short val = 42;
- LogSF.warn(logger, "Iteration {}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogSF.warn with single field pattern with long argument.
- */
- public void testWarnLong() {
- LogCapture capture = new LogCapture(Level.WARN);
- long val = 42;
- LogSF.warn(logger, "Iteration {}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogSF.warn with single field pattern with char argument.
- */
- public void testWarnChar() {
- LogCapture capture = new LogCapture(Level.WARN);
- char val = 'C';
- LogSF.warn(logger, "Iteration {}", val);
- assertEquals("Iteration C", capture.getMessage());
- }
-
- /**
- * Test LogSF.warn with single field pattern with boolean argument.
- */
- public void testWarnBoolean() {
- LogCapture capture = new LogCapture(Level.WARN);
- boolean val = true;
- LogSF.warn(logger, "Iteration {}", val);
- assertEquals("Iteration true", capture.getMessage());
- }
-
- /**
- * Test LogSF.warn with single field pattern with float argument.
- */
- public void testWarnFloat() {
- LogCapture capture = new LogCapture(Level.WARN);
- float val = 3.14f;
- LogSF.warn(logger, "Iteration {}", val);
- assertEquals("Iteration " + String.valueOf(val), capture.getMessage());
- }
-
- /**
- * Test LogSF.warn with single field pattern with double argument.
- */
- public void testWarnDouble() {
- LogCapture capture = new LogCapture(Level.WARN);
- double val = 3.14;
- LogSF.warn(logger, "Iteration {}", val);
- assertEquals("Iteration " + String.valueOf(val), capture.getMessage());
- }
-
- /**
- * Test LogSF.warn with two arguments.
- */
- public void testWarnTwoArg() {
- LogCapture capture = new LogCapture(Level.WARN);
- LogSF.warn(logger, "{}, {}.", "Hello", "World");
- assertEquals("Hello, World.", capture.getMessage());
-
- }
-
- /**
- * Test LogSF.warn with three arguments.
- */
- public void testWarnThreeArg() {
- LogCapture capture = new LogCapture(Level.WARN);
- LogSF.warn(logger, "{}{} {}.", "Hello", ",", "World");
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogSF.warn with Object[] argument.
- */
- public void testWarnFourArg() {
- LogCapture capture = new LogCapture(Level.WARN);
- LogSF.warn(logger, "{}{} {}{}",
- "Hello", ",", "World", "." );
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogSF.warn with Object[] argument.
- */
- public void testWarnArrayArg() {
- LogCapture capture = new LogCapture(Level.WARN);
- Object[] args = new Object[] { "Hello", ",", "World", "." };
- LogSF.warn(logger, "{}{} {}{}", args);
- assertEquals("Hello, World.", capture.getMessage());
- }
-
-
- /**
- * Test LogSF.log with null pattern.
- */
- public void testLogNullPattern() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogSF.log(logger, Level.ERROR, null, Math.PI);
- assertNull(capture.getMessage());
- }
-
- /**
- * Test LogSF.log with no-field pattern.
- */
- public void testLogNoArg() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogSF.log(logger, Level.ERROR, "Hello, World", Math.PI);
- assertEquals("Hello, World", capture.getMessage());
- }
-
- /**
- * Test LogSF.log with malformed pattern.
- */
- public void testLogBadPattern() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogSF.log(logger, Level.ERROR, "Hello, {.", Math.PI);
- assertEquals("Hello, {.", capture.getMessage());
- }
-
- /**
- * Test LogSF.log with missing argument.
- */
- public void testLogMissingArg() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogSF.log(logger, Level.ERROR, "Hello, {}World", new Object[0]);
- assertEquals("Hello, {}World", capture.getMessage());
- }
-
- /**
- * Test LogSF.log with single field pattern with string argument.
- */
- public void testLogString() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogSF.log(logger, Level.ERROR, "Hello, {}", "World");
- assertEquals("Hello, World", capture.getMessage());
- }
-
- /**
- * Test LogSF.log with single field pattern with null argument.
- */
- public void testLogNull() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogSF.log(logger, Level.ERROR, "Hello, {}", (Object) null);
- assertEquals("Hello, null", capture.getMessage());
- }
-
- /**
- * Test LogSF.log with single field pattern with int argument.
- */
- public void testLogInt() {
- LogCapture capture = new LogCapture(Level.ERROR);
- int val = 42;
- LogSF.log(logger, Level.ERROR, "Iteration {}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogSF.log with single field pattern with byte argument.
- */
- public void testLogByte() {
- LogCapture capture = new LogCapture(Level.ERROR);
- byte val = 42;
- LogSF.log(logger, Level.ERROR, "Iteration {}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogSF.log with single field pattern with short argument.
- */
- public void testLogShort() {
- LogCapture capture = new LogCapture(Level.ERROR);
- short val = 42;
- LogSF.log(logger, Level.ERROR, "Iteration {}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogSF.log with single field pattern with long argument.
- */
- public void testLogLong() {
- LogCapture capture = new LogCapture(Level.ERROR);
- long val = 42;
- LogSF.log(logger, Level.ERROR, "Iteration {}", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogSF.log with single field pattern with char argument.
- */
- public void testLogChar() {
- LogCapture capture = new LogCapture(Level.ERROR);
- char val = 'C';
- LogSF.log(logger, Level.ERROR, "Iteration {}", val);
- assertEquals("Iteration C", capture.getMessage());
- }
-
- /**
- * Test LogSF.log with single field pattern with boolean argument.
- */
- public void testLogBoolean() {
- LogCapture capture = new LogCapture(Level.ERROR);
- boolean val = true;
- LogSF.log(logger, Level.ERROR, "Iteration {}", val);
- assertEquals("Iteration true", capture.getMessage());
- }
-
- /**
- * Test LogSF.log with single field pattern with float argument.
- */
- public void testLogFloat() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogSF.log(logger, Level.ERROR, "Iteration {}", (float) Math.PI);
-
- String expected = "Iteration " + String.valueOf(new Float(Math.PI));
- assertEquals(expected, capture.getMessage());
- }
-
- /**
- * Test LogSF.log with single field pattern with double argument.
- */
- public void testLogDouble() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogSF.log(logger, Level.ERROR, "Iteration {}", Math.PI);
-
- String expected = "Iteration " + String.valueOf(new Double(Math.PI));
- assertEquals(expected, capture.getMessage());
- }
-
- /**
- * Test LogSF.log with two arguments.
- */
- public void testLogTwoArg() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogSF.log(logger, Level.ERROR, "{}, {}.", "Hello", "World");
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogSF.log with three arguments.
- */
- public void testLogThreeArg() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogSF.log(logger, Level.ERROR, "{}{} {}.", "Hello", ",", "World");
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogSF.log with four arguments.
- */
- public void testLogFourArg() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogSF.log(logger, Level.ERROR, "{}{} {}{}", "Hello", ",", "World", ".");
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogSF.log with Object[] argument.
- */
- public void testLogArrayArg() {
- LogCapture capture = new LogCapture(Level.ERROR);
- Object[] args = new Object[] { "Hello", ",", "World", "." };
- LogSF.log(logger, Level.ERROR, "{}{} {}{}", args);
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Bundle name for resource bundle tests.
- */
- private static final String BUNDLE_NAME =
- "org.apache.log4j.TestLogSFPatterns";
-
- /**
- * Test LogSF.logrb with null bundle name.
- */
- public void testLogrbNullBundle() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogSF.logrb(logger, Level.ERROR, null, "Iteration0", Math.PI);
- assertEquals("Iteration0", capture.getMessage());
- }
-
- /**
- * Test LogSF.logrb with null key.
- */
- public void testLogrbNullKey() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogSF.logrb(logger, Level.ERROR, BUNDLE_NAME, null, Math.PI);
- assertNull(capture.getMessage());
- }
-
- /**
- * Test LogSF.logrb with no-field pattern.
- */
- public void testLogrbNoArg() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogSF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Hello1", Math.PI);
- assertEquals("Hello, World", capture.getMessage());
- }
-
- /**
- * Test LogSF.logrb with malformed pattern.
- */
- public void testLogrbBadPattern() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogSF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Malformed", Math.PI);
- assertEquals("Hello, {.", capture.getMessage());
- }
-
- /**
- * Test LogSF.logrb with missing argument.
- */
- public void testLogrbMissingArg() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogSF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Hello2", new Object[0]);
- assertEquals("Hello, {}World", capture.getMessage());
- }
-
- /**
- * Test LogSF.logrb with single field pattern with string argument.
- */
- public void testLogrbString() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogSF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Hello3", "World");
- assertEquals("Hello, World", capture.getMessage());
- }
-
- /**
- * Test LogSF.logrb with single field pattern with null argument.
- */
- public void testLogrbNull() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogSF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Hello3", (Object) null);
- assertEquals("Hello, null", capture.getMessage());
- }
-
- /**
- * Test LogSF.logrb with single field pattern with int argument.
- */
- public void testLogrbInt() {
- LogCapture capture = new LogCapture(Level.ERROR);
- int val = 42;
- LogSF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Iteration0", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogSF.logrb with single field pattern with byte argument.
- */
- public void testLogrbByte() {
- LogCapture capture = new LogCapture(Level.ERROR);
- byte val = 42;
- LogSF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Iteration0", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogSF.logrb with single field pattern with short argument.
- */
- public void testLogrbShort() {
- LogCapture capture = new LogCapture(Level.ERROR);
- short val = 42;
- LogSF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Iteration0", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogSF.logrb with single field pattern with long argument.
- */
- public void testLogrbLong() {
- LogCapture capture = new LogCapture(Level.ERROR);
- long val = 42;
- LogSF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Iteration0", val);
- assertEquals("Iteration 42", capture.getMessage());
- }
-
- /**
- * Test LogSF.logrb with single field pattern with char argument.
- */
- public void testLogrbChar() {
- LogCapture capture = new LogCapture(Level.ERROR);
- char val = 'C';
- LogSF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Iteration0", val);
- assertEquals("Iteration C", capture.getMessage());
- }
-
- /**
- * Test LogSF.logrb with single field pattern with boolean argument.
- */
- public void testLogrbBoolean() {
- LogCapture capture = new LogCapture(Level.ERROR);
- boolean val = true;
- LogSF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Iteration0", val);
- assertEquals("Iteration true", capture.getMessage());
- }
-
- /**
- * Test LogSF.logrb with single field pattern with float argument.
- */
- public void testLogrbFloat() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogSF.logrb(logger, Level.ERROR, BUNDLE_NAME,
- "Iteration0", (float) Math.PI);
-
- String expected = "Iteration " + String.valueOf(new Float(Math.PI));
- assertEquals(expected, capture.getMessage());
- }
-
- /**
- * Test LogSF.logrb with single field pattern with double argument.
- */
- public void testLogrbDouble() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogSF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Iteration0", Math.PI);
-
- String expected = "Iteration " + String.valueOf(new Double(Math.PI));
- assertEquals(expected, capture.getMessage());
- }
-
- /**
- * Test LogSF.logrb with two arguments.
- */
- public void testLogrbTwoArg() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogSF.logrb(logger, Level.ERROR,
- BUNDLE_NAME, "Hello4", "Hello", "World");
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogSF.logrb with three arguments.
- */
- public void testLogrbThreeArg() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogSF.logrb(logger, Level.ERROR,
- BUNDLE_NAME, "Hello5", "Hello", ",", "World");
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogSF.logrb with four arguments.
- */
- public void testLogrbFourArg() {
- LogCapture capture = new LogCapture(Level.ERROR);
- LogSF.logrb(logger, Level.ERROR,
- BUNDLE_NAME, "Hello6", "Hello", ",", "World", ".");
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test LogSF.logrb with Object[] argument.
- */
- public void testLogrbArrayArg() {
- LogCapture capture = new LogCapture(Level.ERROR);
- Object[] args = new Object[] { "Hello", ",", "World", "." };
- LogSF.logrb(logger, Level.ERROR,
- BUNDLE_NAME, "Hello6", args);
- assertEquals("Hello, World.", capture.getMessage());
- }
-
- /**
- * Test \\{ escape sequence when only one parameter is present.
- *
- */
- public void testEscapeOneParam() {
- LogCapture capture = new LogCapture(Level.INFO);
- LogSF.info(logger, "\\{}\\{{}}, World}\\{","Hello");
- assertEquals("{}{Hello}, World}{", capture.getMessage());
- }
-
- /**
- * Test \\{ escape sequence when more than one parameter is present.
- *
- */
- public void testEscapeTwoParam() {
- LogCapture capture = new LogCapture(Level.INFO);
- LogSF.info(logger, "\\{}\\{{}}, {}}{}\\{","Hello", "World");
- assertEquals("{}{Hello}, World}{}{", capture.getMessage());
- }
-}
diff --git a/src/test/java/org/apache/log4j/TestLogXF.java b/src/test/java/org/apache/log4j/TestLogXF.java
deleted file mode 100644
index e3429ae..0000000
--- a/src/test/java/org/apache/log4j/TestLogXF.java
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.log4j;
-
-import junit.framework.TestCase;
-
-
-/**
- * Unit test for LogXF.
- */
-public class TestLogXF extends TestCase {
- /**
- * Logger.
- */
- private final Logger logger = Logger.getLogger(
- "org.apache.log4j.formatter.TestLogXF");
-
- /**
- * Create the test case
- *
- * @param testName name of the test case
- */
- public TestLogXF(String testName) {
- super(testName);
- }
-
-
- /**
- * Post test clean up.
- */
- public void tearDown() {
- LogManager.resetConfiguration();
- }
-
- private static class BadStringifier {
- private BadStringifier() {}
- public static BadStringifier INSTANCE = new BadStringifier();
- public String toString() {
- throw new NullPointerException();
- }
- }
-
-
- /**
- * Test LogXF.entering with null class and method.
- */
- public void testEnteringNullNull() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- logger.setLevel(Level.DEBUG);
- LogXF.entering(logger, null, null);
- assertEquals("null.null ENTRY", capture.getMessage());
- }
-
-
- /**
- * Test LogXF.entering with null class, method and parameter.
- */
- public void testEnteringNullNullNull() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- logger.setLevel(Level.DEBUG);
- LogXF.entering(logger, null, null, (String) null);
- assertEquals("null.null ENTRY null", capture.getMessage());
- }
-
- /**
- * Test LogXF.entering with null class, method and parameters.
- */
- public void testEnteringNullNullNullArray() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- logger.setLevel(Level.DEBUG);
- LogXF.entering(logger, null, null, (Object[]) null);
- assertEquals("null.null ENTRY {}", capture.getMessage());
- }
-
- /**
- * Test LogXF.entering with class and method.
- */
- public void testEntering() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- logger.setLevel(Level.DEBUG);
- LogXF.entering(logger, "SomeClass", "someMethod");
- assertEquals("SomeClass.someMethod ENTRY", capture.getMessage());
- }
-
- /**
- * Test LogXF.entering with class, method and parameter.
- */
- public void testEnteringWithParam() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- logger.setLevel(Level.DEBUG);
- LogXF.entering(logger, "SomeClass", "someMethod", "someParam");
- assertEquals("SomeClass.someMethod ENTRY someParam", capture.getMessage());
- }
-
- /**
- * Test LogXF.entering with class, method and bad parameter.
- */
- public void testEnteringWithBadParam() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- logger.setLevel(Level.DEBUG);
- LogXF.entering(logger, "SomeClass", "someMethod", BadStringifier.INSTANCE);
- assertEquals("SomeClass.someMethod ENTRY ?", capture.getMessage());
- }
-
- /**
- * Test LogXF.entering with class, method and bad parameters.
- */
- public void testEnteringWithBadParams() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- logger.setLevel(Level.DEBUG);
- LogXF.entering(logger, "SomeClass", "someMethod", new Object[]{"param1",BadStringifier.INSTANCE});
- assertEquals("SomeClass.someMethod ENTRY {param1,?}", capture.getMessage());
- }
-
-
- /**
- * Test LogXF.exiting with null class and method.
- */
- public void testExitingNullNull() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- logger.setLevel(Level.DEBUG);
- LogXF.exiting(logger, null, null);
- assertEquals("null.null RETURN", capture.getMessage());
- }
-
-
- /**
- * Test LogXF.exiting with null class, method and parameter.
- */
- public void testExitingNullNullNull() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- logger.setLevel(Level.DEBUG);
- LogXF.exiting(logger, null, null, (String) null);
- assertEquals("null.null RETURN null", capture.getMessage());
- }
-
-
- /**
- * Test LogXF.exiting with class and method.
- */
- public void testExiting() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- logger.setLevel(Level.DEBUG);
- LogXF.exiting(logger, "SomeClass", "someMethod");
- assertEquals("SomeClass.someMethod RETURN", capture.getMessage());
- }
-
- /**
- * Test LogXF.exiting with class, method and return value.
- */
- public void testExitingWithValue() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- logger.setLevel(Level.DEBUG);
- LogXF.exiting(logger, "SomeClass", "someMethod", "someValue");
- assertEquals("SomeClass.someMethod RETURN someValue", capture.getMessage());
- }
-
- /**
- * Test LogXF.exiting with class, method and bad return value.
- */
- public void testExitingWithBadValue() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- logger.setLevel(Level.DEBUG);
- LogXF.exiting(logger, "SomeClass", "someMethod", BadStringifier.INSTANCE);
- assertEquals("SomeClass.someMethod RETURN ?", capture.getMessage());
- }
-
-
- /**
- * Test LogXF.throwing with null class, method and throwable.
- */
- public void testThrowingNullNullNull() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- logger.setLevel(Level.DEBUG);
- LogXF.throwing(logger, null, null, null);
- assertEquals("null.null THROW", capture.getMessage());
- }
-
-
- /**
- * Test LogXF.exiting with class and method.
- */
- public void testThrowing() {
- LogCapture capture = new LogCapture(Level.DEBUG);
- logger.setLevel(Level.DEBUG);
- LogXF.throwing(logger, "SomeClass", "someMethod", new IllegalArgumentException());
- assertEquals("SomeClass.someMethod THROW", capture.getMessage());
- }
-}
diff --git a/src/test/java/org/apache/log4j/pattern/CachedDateFormatTest.java b/src/test/java/org/apache/log4j/pattern/CachedDateFormatTest.java
deleted file mode 100644
index 2ad4cdf..0000000
--- a/src/test/java/org/apache/log4j/pattern/CachedDateFormatTest.java
+++ /dev/null
@@ -1,393 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.log4j.pattern;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import org.apache.log4j.pattern.CachedDateFormat;
-
-import java.text.DateFormat;
-import java.util.TimeZone;
-import java.util.Date;
-import java.text.SimpleDateFormat;
-import java.util.Locale;
-import java.util.Calendar;
-
-/**
- Unit test {@link AbsoluteTimeDateFormat}.
- @author Curt Arnold
- */
-public final class CachedDateFormatTest
- extends TestCase {
-
- /**
- * Test constructor
- * @param name String test name
- */
- public CachedDateFormatTest(String name) {
- super(name);
- }
-
- private static DateFormat createAbsoluteTimeDateFormat(TimeZone timeZone) {
- DateFormat df = new SimpleDateFormat("HH:mm:ss,SSS");
- df.setTimeZone(timeZone);
- return df;
- }
-
-
- /**
- * Timezone representing GMT.
- */
- private static final TimeZone GMT = TimeZone.getTimeZone("GMT");
-
- /**
- * Timezone for Chicago, Ill. USA.
- */
- private static final TimeZone CHICAGO = TimeZone.getTimeZone(
- "America/Chicago");
-
- /**
- * Test multiple calls in close intervals.
- */
- public void test1() {
- // subsequent calls within one minute
- // are optimized to reuse previous formatted value
- // make a couple of nearly spaced calls
- DateFormat gmtFormat = new CachedDateFormat(createAbsoluteTimeDateFormat(GMT), 1000);
- long ticks = 12601L * 86400000L;
- Date jul1 = new Date(ticks);
- assertEquals("00:00:00,000", gmtFormat.format(jul1));
- Date plus8ms = new Date(ticks + 8);
- assertEquals("00:00:00,008", gmtFormat.format(plus8ms));
- Date plus17ms = new Date(ticks + 17);
- assertEquals("00:00:00,017", gmtFormat.format(plus17ms));
- Date plus237ms = new Date(ticks + 237);
- assertEquals("00:00:00,237", gmtFormat.format(plus237ms));
- Date plus1415ms = new Date(ticks + 1415);
- assertEquals("00:00:01,415", gmtFormat.format(plus1415ms));
- }
-
- /**
- * Check for interaction between caches.
- */
- public void test2() {
- Date jul2 = new Date(12602L * 86400000L);
- DateFormat gmtFormat = new CachedDateFormat(createAbsoluteTimeDateFormat(GMT), 1000);
- DateFormat chicagoFormat = new CachedDateFormat(createAbsoluteTimeDateFormat(CHICAGO), 1000);
- assertEquals("00:00:00,000", gmtFormat.format(jul2));
- assertEquals("19:00:00,000", chicagoFormat.format(jul2));
- assertEquals("00:00:00,000", gmtFormat.format(jul2));
- }
-
- /**
- * Test multiple calls in close intervals prior to 1 Jan 1970.
- */
- public void test3() {
- // subsequent calls within one minute
- // are optimized to reuse previous formatted value
- // make a couple of nearly spaced calls
- DateFormat gmtFormat = new CachedDateFormat(
- createAbsoluteTimeDateFormat(GMT), 1000);
- //
- // if the first call was exactly on an integral
- // second, it would not test the round toward zero compensation
- long ticks = -7L * 86400000L;
- Date jul1 = new Date(ticks + 8);
- assertEquals("00:00:00,008", gmtFormat.format(jul1));
- Date plus8ms = new Date(ticks + 16);
- assertEquals("00:00:00,016", gmtFormat.format(plus8ms));
- Date plus17ms = new Date(ticks + 23);
- assertEquals("00:00:00,023", gmtFormat.format(plus17ms));
- Date plus237ms = new Date(ticks + 245);
- assertEquals("00:00:00,245", gmtFormat.format(plus237ms));
- Date plus1415ms = new Date(ticks + 1423);
- assertEquals("00:00:01,423", gmtFormat.format(plus1415ms));
- }
-
- public void test4() {
- // subsequent calls within one minute are optimized to reuse previous
- // formatted value. make a couple of nearly spaced calls
- // (Note: 'Z' is JDK 1.4, using 'z' instead.)
- SimpleDateFormat baseFormat =
- new SimpleDateFormat("EEE, MMM dd, HH:mm:ss.SSS z", Locale.ENGLISH);
- DateFormat cachedFormat = new CachedDateFormat(baseFormat, 1000);
- //
- // use a date in 2000 to attempt to confuse the millisecond locator
- long ticks = 11141L * 86400000L;
- Date jul1 = new Date(ticks);
- assertEquals(baseFormat.format(jul1), cachedFormat.format(jul1));
- Date plus8ms = new Date(ticks + 8);
- baseFormat.format(plus8ms);
- cachedFormat.format(plus8ms);
- assertEquals(baseFormat.format(plus8ms), cachedFormat.format(plus8ms));
- Date plus17ms = new Date(ticks + 17);
- assertEquals(baseFormat.format(plus17ms), cachedFormat.format(plus17ms));
- Date plus237ms = new Date(ticks + 237);
- assertEquals(baseFormat.format(plus237ms), cachedFormat.format(plus237ms));
- Date plus1415ms = new Date(ticks + 1415);
- assertEquals(baseFormat.format(plus1415ms), cachedFormat.format(plus1415ms));
- }
-
- public void test5() {
- // subsequent calls within one minute
- // are optimized to reuse previous formatted value
- // make a couple of nearly spaced calls
- // (Note: 'Z' is JDK 1.4, using 'z' instead.)
- Locale thai = new Locale("th", "TH");
- SimpleDateFormat baseFormat =
- new SimpleDateFormat("EEE, MMM dd, HH:mm:ss.SSS z", thai);
- DateFormat cachedFormat = new CachedDateFormat(baseFormat, 1000);
- //
- // use a date in the year 2000 CE to attempt to confuse the millisecond locator
- long ticks = 11141L * 86400000L;
-
- String sx;
- Date jul1 = new Date(ticks);
- sx = cachedFormat.format(jul1);
- System.out.println(baseFormat.format(jul1));
- System.out.println(sx);
- assertEquals(baseFormat.format(jul1), sx);
-
- sx = cachedFormat.format(jul1);
- System.out.println(baseFormat.format(jul1));
- System.out.println(sx);
- assertEquals(baseFormat.format(jul1), sx);
-
-
- Date plus8ms = new Date(ticks + 8);
- sx = cachedFormat.format(plus8ms);
- System.out.println(baseFormat.format(plus8ms));
- System.out.println(sx);
-
- assertEquals(baseFormat.format(plus8ms), sx);
-
- Date plus17ms = new Date(ticks + 17);
- assertEquals(baseFormat.format(plus17ms), cachedFormat.format(plus17ms));
-
- Date plus237ms = new Date(ticks + 237);
- assertEquals(baseFormat.format(plus237ms), cachedFormat.format(plus237ms));
-
- Date plus1415ms = new Date(ticks + 1415);
- assertEquals(baseFormat.format(plus1415ms), cachedFormat.format(plus1415ms));
- }
-
- /**
- * Checks that getNumberFormat does not return null.
- */
- public void test6() {
- assertNotNull(new CachedDateFormat(new SimpleDateFormat(), 1000).getNumberFormat());
- }
-
- /**
- * Set time zone on cached and check that it is effective.
- */
- public void test8() {
- DateFormat baseFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS");
- baseFormat.setTimeZone(GMT);
- DateFormat cachedFormat = new CachedDateFormat(baseFormat, 1000);
- Date jul4 = new Date(12603L * 86400000L);
- assertEquals("2004-07-04 00:00:00,000", cachedFormat.format(jul4));
- cachedFormat.setTimeZone(TimeZone.getTimeZone("GMT-6"));
- assertEquals("2004-07-03 18:00:00,000", cachedFormat.format(jul4));
- }
-
-
- /**
- * Test of caching when less than three millisecond digits are specified.
- */
- public void test9() {
- // (Note: 'Z' is JDK 1.4, using 'z' instead.)
- DateFormat baseFormat = new SimpleDateFormat("yyyy-MMMM-dd HH:mm:ss,SS z", Locale.US);
- DateFormat cachedFormat = new CachedDateFormat(baseFormat, 1000);
- TimeZone cet = TimeZone.getTimeZone("GMT+1");
- cachedFormat.setTimeZone(cet);
-
- Calendar c = Calendar.getInstance();
- c.set(2004, Calendar.DECEMBER, 12, 20, 0);
- c.set(Calendar.SECOND, 37);
- c.set(Calendar.MILLISECOND, 23);
- c.setTimeZone(cet);
-
- String expected = baseFormat.format(c.getTime());
- String s = cachedFormat.format(c.getTime());
- assertEquals(expected, s);
-
- c.set(2005, Calendar.JANUARY, 1, 0, 0);
- c.set(Calendar.SECOND, 13);
- c.set(Calendar.MILLISECOND, 905);
-
- expected = baseFormat.format(c.getTime());
- s = cachedFormat.format(c.getTime());
- assertEquals(expected, s);
- }
-
-
- /**
- * Test when millisecond position moves but length remains constant.
- */
- public void test10() {
- DateFormat baseFormat = new SimpleDateFormat("MMMM SSS EEEEEE", Locale.US);
- DateFormat cachedFormat = new CachedDateFormat(baseFormat, 1000);
- TimeZone cet = TimeZone.getTimeZone("GMT+1");
- cachedFormat.setTimeZone(cet);
-
- Calendar c = Calendar.getInstance();
- c.set(2004, Calendar.OCTOBER, 5, 20, 0);
- c.set(Calendar.SECOND, 37);
- c.set(Calendar.MILLISECOND, 23);
- c.setTimeZone(cet);
-
- String expected = baseFormat.format(c.getTime());
- String s = cachedFormat.format(c.getTime());
- assertEquals(expected, s);
-
- c.set(2004, Calendar.NOVEMBER, 1, 0, 0);
- c.set(Calendar.MILLISECOND, 23);
- expected = baseFormat.format(c.getTime());
- s = cachedFormat.format(c.getTime());
- assertEquals(expected, s);
-
-
- c.set(Calendar.MILLISECOND, 984);
- expected = baseFormat.format(c.getTime());
- s = cachedFormat.format(c.getTime());
- assertEquals(expected, s);
- }
-
- /**
- * Test that tests if caching is skipped if only "SS"
- * is specified.
- */
- public void test11() {
- //
- // Earlier versions could be tricked by "SS0" patterns.
- //
- String badPattern = "ss,SS0";
- SimpleDateFormat simpleFormat = new SimpleDateFormat(badPattern);
- SimpleDateFormat baseFormat = new SimpleDateFormat(badPattern);
- DateFormat gmtFormat = new CachedDateFormat(simpleFormat, 1000);
- gmtFormat.setTimeZone(GMT);
- baseFormat.setTimeZone(GMT);
-
- //
- // The first request has to 100 ms after an ordinal second
- // to push the literal zero out of the pattern check
- long ticks = 11142L * 86400000L;
- Date jul2 = new Date(ticks + 120);
- String expected = baseFormat.format(jul2);
- assertEquals(expected, gmtFormat.format(jul2));
- jul2.setTime(ticks + 87);
-
-
- //
- // Cache gives 00,087
- expected = baseFormat.format(jul2);
- assertEquals(expected, gmtFormat.format(jul2));
-
- }
-
- /**
- * Check pattern location for ISO8601
- */
- public void test12() {
- SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS");
- long ticks = 11142L * 86400000L;
- String formatted = df.format(new Date(ticks));
- int millisecondStart = CachedDateFormat.findMillisecondStart(ticks, formatted, df);
- assertEquals(20, millisecondStart);
- }
-
- /**
- * Check pattern location for DATE
- */
- public void test13() {
- SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
- long ticks = 11142L * 86400000L;
- String formatted = df.format(new Date(ticks));
- int millisecondStart = CachedDateFormat.findMillisecondStart(ticks, formatted, df);
- assertEquals(CachedDateFormat.NO_MILLISECONDS, millisecondStart);
- }
-
- /**
- * Check pattern location for ABSOLUTE
- */
- public void test14() {
- SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss,SSS");
- long ticks = 11142L * 86400000L;
- String formatted = df.format(new Date(ticks));
- int millisecondStart = CachedDateFormat.findMillisecondStart(ticks, formatted, df);
- assertEquals(9, millisecondStart);
- }
-
- /**
- * Check pattern location for single S
- */
- public void test15() {
- SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss,S");
- long ticks = 11142L * 86400000L;
- String formatted = df.format(new Date(ticks));
- int millisecondStart = CachedDateFormat.findMillisecondStart(ticks, formatted, df);
- assertEquals(CachedDateFormat.UNRECOGNIZED_MILLISECONDS, millisecondStart);
- }
-
- /**
- * Check pattern location for single SS
- */
- public void test16() {
- SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss,SS");
- long ticks = 11142L * 86400000L;
- String formatted = df.format(new Date(ticks));
- int millisecondStart = CachedDateFormat.findMillisecondStart(ticks, formatted, df);
- assertEquals(CachedDateFormat.UNRECOGNIZED_MILLISECONDS, millisecondStart);
- }
-
-
- /**
- * Check caching when multiple SSS appear in pattern
- */
- public void test17() {
- Date jul2 = new Date(12602L * 86400000L);
- String badPattern = "HH:mm:ss,SSS HH:mm:ss,SSS";
- SimpleDateFormat simpleFormat = new SimpleDateFormat(badPattern);
- simpleFormat.setTimeZone(GMT);
- DateFormat cachedFormat = new CachedDateFormat(simpleFormat, 1000);
- String s = cachedFormat.format(jul2);
- assertEquals("00:00:00,000 00:00:00,000", s);
- jul2.setTime(jul2.getTime() + 120);
- assertEquals("00:00:00,120 00:00:00,120", simpleFormat.format(jul2));
- s = cachedFormat.format(jul2);
- //
- // TODO: why is this returning ,120 ... , 120
- //
- //assertEquals("00:00:00,120 00:00:00,000", s) ;
-
- int maxValid = CachedDateFormat.getMaximumCacheValidity(badPattern);
- assertEquals(1, maxValid);
- }
-
-
- public static Test xsuite() {
- TestSuite suite = new TestSuite();
- suite.addTest(new CachedDateFormatTest("test5"));
- //suite.addTest(new CachedDateFormatTest("testS2"));
- return suite;
- }
-
-}
diff --git a/src/test/java/org/apache/log4j/pattern/NameAbbreviatorTest.java b/src/test/java/org/apache/log4j/pattern/NameAbbreviatorTest.java
deleted file mode 100644
index 7ced8f5..0000000
--- a/src/test/java/org/apache/log4j/pattern/NameAbbreviatorTest.java
+++ /dev/null
@@ -1,336 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.log4j.pattern;
-
-import junit.framework.TestCase;
-
-
-/**
- * Tests for NameAbbrevator.
- *
- */
-public class NameAbbreviatorTest extends TestCase {
- /**
- * Create a new instance.
- *
- * @param name test name
- */
- public NameAbbreviatorTest(final String name) {
- super(name);
- }
-
- /**
- * Check that getDefaultAbbreviator does not return null.
- *
- */
- public void testGetDefault() {
- NameAbbreviator abbrev = NameAbbreviator.getDefaultAbbreviator();
- assertNotNull(abbrev);
- }
-
- /**
- * Check that "0" drops all name content.
- *
- */
- public void testZero() {
- NameAbbreviator abbrev = NameAbbreviator.getAbbreviator("0");
- StringBuffer buf = new StringBuffer("DEBUG - ");
- int fieldStart = buf.length();
- buf.append("org.example.foo.bar");
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - ", buf.toString());
- }
-
- /**
- * Check that getAbbreviator(" ") returns default abbreviator.
- *
- */
- public void testBlank() {
- NameAbbreviator abbrev = NameAbbreviator.getAbbreviator(" ");
- NameAbbreviator defaultAbbrev = NameAbbreviator.getDefaultAbbreviator();
- assertTrue(abbrev == defaultAbbrev);
- }
-
- /**
- * Check that getAbbreviator("1").abbreviate() drops all but the final name element.
- *
- */
- public void testOne() {
- NameAbbreviator abbrev = NameAbbreviator.getAbbreviator("1");
- StringBuffer buf = new StringBuffer("DEBUG - ");
- int fieldStart = buf.length();
- buf.append("org.example.foo.bar");
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - bar", buf.toString());
-
- buf.setLength(0);
- buf.append("DEBUG - ");
- fieldStart = buf.length();
- buf.append("bar");
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - bar", buf.toString());
-
- buf.setLength(0);
- buf.append("DEBUG - ");
- fieldStart = buf.length();
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - ", buf.toString());
- }
-
- /**
- * Check that blanks are trimmed in evaluating abbreviation pattern.
- */
- public void testBlankOne() {
- NameAbbreviator abbrev = NameAbbreviator.getAbbreviator(" 1 ");
- StringBuffer buf = new StringBuffer("DEBUG - ");
- int fieldStart = buf.length();
- buf.append("org.example.foo.bar");
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - bar", buf.toString());
-
- buf.setLength(0);
- buf.append("DEBUG - ");
- fieldStart = buf.length();
- buf.append("bar");
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - bar", buf.toString());
-
- buf.setLength(0);
- buf.append("DEBUG - ");
- fieldStart = buf.length();
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - ", buf.toString());
- }
-
- /**
- * Check that getAbbreviator("2").abbreviate drops all but the last two elements.
- *
- */
- public void testTwo() {
- NameAbbreviator abbrev = NameAbbreviator.getAbbreviator("2");
- StringBuffer buf = new StringBuffer("DEBUG - ");
- int fieldStart = buf.length();
- buf.append("org.example.foo.bar");
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - foo.bar", buf.toString());
-
- buf.setLength(0);
- buf.append("DEBUG - ");
- fieldStart = buf.length();
- buf.append("foo.bar");
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - foo.bar", buf.toString());
-
- buf.setLength(0);
- buf.append("DEBUG - ");
- fieldStart = buf.length();
- buf.append("bar");
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - bar", buf.toString());
- }
-
- /**
- * Check that getAbbreviator("1.").abbreviate abbreviates non-final elements
- * to one character.
- *
- */
- public void testOneDot() {
- NameAbbreviator abbrev = NameAbbreviator.getAbbreviator("1.");
- StringBuffer buf = new StringBuffer("DEBUG - ");
- int fieldStart = buf.length();
- buf.append("org.example.foo.bar");
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - o.e.f.bar", buf.toString());
-
- buf.setLength(0);
- buf.append("DEBUG - ");
- fieldStart = buf.length();
- buf.append("org.example.foo.");
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - o.e.f.", buf.toString());
-
-
- buf.setLength(0);
- buf.append("DEBUG - ");
- fieldStart = buf.length();
- buf.append("foo.bar");
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - f.bar", buf.toString());
-
- buf.setLength(0);
- buf.append("DEBUG - ");
- fieldStart = buf.length();
- buf.append("bar");
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - bar", buf.toString());
-
- buf.setLength(0);
- buf.append("DEBUG - ");
- fieldStart = buf.length();
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - ", buf.toString());
-
- buf.setLength(0);
- buf.append("DEBUG - ");
- fieldStart = buf.length();
- buf.append(".");
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - .", buf.toString());
- }
-
- /**
- * Check that getAbbreviator("1~.").abbreviate abbreviates non-final elements
- * to one character and a tilde.
- *
- */
- public void testOneTildeDot() {
- NameAbbreviator abbrev = NameAbbreviator.getAbbreviator("1~.");
- StringBuffer buf = new StringBuffer("DEBUG - ");
- int fieldStart = buf.length();
- buf.append("org.example.foo.bar");
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - o~.e~.f~.bar", buf.toString());
-
- buf.setLength(0);
- buf.append("DEBUG - ");
- fieldStart = buf.length();
- buf.append("org.example.foo.");
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - o~.e~.f~.", buf.toString());
-
- buf.setLength(0);
- buf.append("DEBUG - ");
- fieldStart = buf.length();
- buf.append("foo.bar");
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - f~.bar", buf.toString());
-
- buf.setLength(0);
- buf.append("DEBUG - ");
- fieldStart = buf.length();
- buf.append("bar");
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - bar", buf.toString());
-
- buf.setLength(0);
- buf.append("DEBUG - ");
- fieldStart = buf.length();
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - ", buf.toString());
-
-
- buf.setLength(0);
- buf.append("DEBUG - ");
- fieldStart = buf.length();
- buf.append(".");
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - .", buf.toString());
-
-
- buf.setLength(0);
- buf.append("DEBUG - ");
- fieldStart = buf.length();
- buf.append("o.e.f.bar");
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - o.e.f.bar", buf.toString());
- }
-
- /**
- * Check that getAbbreviator("1.*.2").abbreviate drops all but the first
- * character from the first element, uses all of the second element and
- * drops all but the first two characters of the rest of the non-final elements.
- *
- */
- public void testMulti() {
- NameAbbreviator abbrev = NameAbbreviator.getAbbreviator("1.*.2");
- StringBuffer buf = new StringBuffer("DEBUG - ");
- int fieldStart = buf.length();
- buf.append("org.example.foo.bar");
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - o.example.fo.bar", buf.toString());
-
- buf.setLength(0);
- buf.append("DEBUG - ");
- fieldStart = buf.length();
- buf.append("org.example.foo.");
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - o.example.fo.", buf.toString());
-
- buf.setLength(0);
- buf.append("DEBUG - ");
- fieldStart = buf.length();
- buf.append("foo.bar");
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - f.bar", buf.toString());
-
- buf.setLength(0);
- buf.append("DEBUG - ");
- fieldStart = buf.length();
- buf.append("bar");
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - bar", buf.toString());
-
- buf.setLength(0);
- buf.append("DEBUG - ");
- fieldStart = buf.length();
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - ", buf.toString());
-
- buf.setLength(0);
- buf.append("DEBUG - ");
- fieldStart = buf.length();
- buf.append(".");
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - .", buf.toString());
- }
-
- /**
- * Check that getAbbreviator("-1").abbreviate() drops first name element.
- *
- */
- public void testMinusOne() {
- NameAbbreviator abbrev = NameAbbreviator.getAbbreviator("-1");
- StringBuffer buf = new StringBuffer("DEBUG - ");
- int fieldStart = buf.length();
- buf.append("org.example.foo.bar");
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - example.foo.bar", buf.toString());
-
- buf.setLength(0);
- buf.append("DEBUG - ");
- fieldStart = buf.length();
- buf.append("bar");
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - bar", buf.toString());
-
- buf.setLength(0);
- buf.append("DEBUG - ");
- fieldStart = buf.length();
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - ", buf.toString());
-
- buf.setLength(0);
- buf.append("DEBUG - ");
- fieldStart = buf.length();
- buf.append(".");
- abbrev.abbreviate(fieldStart, buf);
- assertEquals("DEBUG - ", buf.toString());
-
- }
-
-}
diff --git a/src/test/java/org/apache/log4j/pattern/Num343PatternConverter.java b/src/test/java/org/apache/log4j/pattern/Num343PatternConverter.java
deleted file mode 100644
index 27a58bd..0000000
--- a/src/test/java/org/apache/log4j/pattern/Num343PatternConverter.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.log4j.pattern;
-
-import org.apache.log4j.spi.LoggingEvent;
-
-
-public class Num343PatternConverter extends LoggingEventPatternConverter {
-
- private Num343PatternConverter() {
- super("Num34", "num34");
- }
- private static final Num343PatternConverter INSTANCE = new Num343PatternConverter();
-
- public static PatternConverter newInstance(final String[] options) {
- return INSTANCE;
- }
-
- public void format(LoggingEvent event, StringBuffer toAppendTo) {
- toAppendTo.append("343");
- }
-
-}