DOMTestCasepublic class DOMTestCase extends TestCase
Fields Summary |
---|
static String | TEMP_A1 | static String | TEMP_A2 | static String | FILTERED_A1 | static String | FILTERED_A2 | static String | EXCEPTION1 | static String | EXCEPTION2 | static String | EXCEPTION3 | static String | EXCEPTION4 | static String | EXCEPTION5 | static String | TEST1_1A_PAT | static String | TEST1_1B_PAT | static String | TEST1_2_PAT | Logger | root | Logger | logger |
Constructors Summary |
---|
public DOMTestCase(String name)
super(name);
|
Methods Summary |
---|
void | common()
String oldThreadName = Thread.currentThread().getName();
Thread.currentThread().setName("main");
int i = -1;
logger.trace("Message " + ++i);
root.trace("Message " + i);
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);
root.debug("Message " + i, e);
logger.error("Message " + ++i, e);
root.error("Message " + i, e);
Thread.currentThread().setName(oldThreadName);
| public void | setUp()
root = Logger.getRootLogger();
logger = Logger.getLogger(DOMTestCase.class);
| public void | tearDown()
root.getLoggerRepository().resetConfiguration();
| public void | test1()
DOMConfigurator.configure("input/xml/DOMTestCase1.xml");
common();
ControlFilter cf1 = new ControlFilter(new String[]{TEST1_1A_PAT, TEST1_1B_PAT,
EXCEPTION1, EXCEPTION2, EXCEPTION3, EXCEPTION4, EXCEPTION5});
ControlFilter cf2 = new ControlFilter(new String[]{TEST1_2_PAT,
EXCEPTION1, EXCEPTION2, EXCEPTION3, EXCEPTION4, EXCEPTION5});
Transformer.transform(
TEMP_A1, FILTERED_A1,
new Filter[] {
cf1, new LineNumberFilter(), new SunReflectFilter(),
new JunitTestRunnerFilter()
});
Transformer.transform(
TEMP_A2, FILTERED_A2,
new Filter[] {
cf2, new LineNumberFilter(), new ISO8601Filter(),
new SunReflectFilter(), new JunitTestRunnerFilter()
});
assertTrue(Compare.compare(FILTERED_A1, "witness/dom.A1.1"));
assertTrue(Compare.compare(FILTERED_A2, "witness/dom.A2.1"));
| public void | test4()Tests processing of external entities in XML file.
DOMConfigurator.configure("input/xml/DOMTest4.xml");
common();
ControlFilter cf1 = new ControlFilter(new String[]{TEST1_1A_PAT, TEST1_1B_PAT,
EXCEPTION1, EXCEPTION2, EXCEPTION3, EXCEPTION4, EXCEPTION5});
ControlFilter cf2 = new ControlFilter(new String[]{TEST1_2_PAT,
EXCEPTION1, EXCEPTION2, EXCEPTION3, EXCEPTION4, EXCEPTION5});
Transformer.transform(
TEMP_A1 + ".4", FILTERED_A1 + ".4",
new Filter[] {
cf1, new LineNumberFilter(), new SunReflectFilter(),
new JunitTestRunnerFilter()
});
Transformer.transform(
TEMP_A2 + ".4", FILTERED_A2 + ".4",
new Filter[] {
cf2, new LineNumberFilter(), new ISO8601Filter(),
new SunReflectFilter(), new JunitTestRunnerFilter()
});
assertTrue(Compare.compare(FILTERED_A1 + ".4", "witness/dom.A1.4"));
assertTrue(Compare.compare(FILTERED_A2 + ".4", "witness/dom.A2.4"));
| public void | testCategoryFactory1()Tests that loggers mentioned in logger elements
use the specified categoryFactory. See bug 33708.
DOMConfigurator.configure("input/xml/categoryfactory1.xml");
//
// logger explicitly mentioned in configuration,
// should be a CustomLogger
Logger logger1 = Logger.getLogger("org.apache.log4j.xml.DOMTestCase.testCategoryFactory1.1");
assertTrue(logger1 instanceof CustomLogger);
//
// logger not explicitly mentioned in configuration,
// should use default factory
Logger logger2 = Logger.getLogger("org.apache.log4j.xml.DOMTestCase.testCategoryFactory1.2");
assertFalse(logger2 instanceof CustomLogger);
| public void | testCategoryFactory2()Tests that loggers mentioned in logger-ref elements
use the specified categoryFactory. See bug 33708.
DOMConfigurator.configure("input/xml/categoryfactory2.xml");
//
// logger explicitly mentioned in configuration,
// should be a CustomLogger
Logger logger1 = Logger.getLogger("org.apache.log4j.xml.DOMTestCase.testCategoryFactory2.1");
assertTrue(logger1 instanceof CustomLogger);
//
// logger not explicitly mentioned in configuration,
// should use default factory
Logger logger2 = Logger.getLogger("org.apache.log4j.xml.DOMTestCase.testCategoryFactory2.2");
assertFalse(logger2 instanceof CustomLogger);
| public void | testConfigureAndWatch()Test checks that configureAndWatch does initial configuration, see bug 33502.
DOMConfigurator.configureAndWatch("input/xml/DOMTestCase1.xml");
assertNotNull(Logger.getRootLogger().getAppender("A1"));
| public void | testLoggerFactory1()Tests that loggers mentioned in logger elements
use the specified loggerFactory. See bug 33708.
DOMConfigurator.configure("input/xml/loggerfactory1.xml");
//
// logger explicitly mentioned in configuration,
// should be a CustomLogger
Logger logger1 = Logger.getLogger("org.apache.log4j.xml.DOMTestCase.testLoggerFactory1.1");
assertTrue(logger1 instanceof CustomLogger);
//
// logger not explicitly mentioned in configuration,
// should use default factory
Logger logger2 = Logger.getLogger("org.apache.log4j.xml.DOMTestCase.testLoggerFactory1.2");
assertFalse(logger2 instanceof CustomLogger);
| public void | testReset()Tests that reset="true" on log4j:configuration element resets
repository before configuration.
VectorAppender appender = new VectorAppender();
appender.setName("V1");
Logger.getRootLogger().addAppender(appender);
DOMConfigurator.configure("input/xml/testReset.xml");
assertNull(Logger.getRootLogger().getAppender("V1"));
|
|