LevelMatchFilterTestCasepublic class LevelMatchFilterTestCase extends TestCase Test case for varia/LevelMatchFilter.java. |
Fields Summary |
---|
static String | ACCEPT_FILE | static String | ACCEPT_FILTERED | static String | ACCEPT_WITNESS | static String | DENY_FILE | static String | DENY_FILTERED | static String | DENY_WITNESS | Logger | root | Logger | logger |
Constructors Summary |
---|
public LevelMatchFilterTestCase(String name)
super(name);
|
Methods Summary |
---|
public void | accept()
// set up appender
Layout layout = new SimpleLayout();
Appender appender = new FileAppender(layout, ACCEPT_FILE, false);
// create LevelMatchFilter
LevelMatchFilter matchFilter = new LevelMatchFilter();
// attach match filter to appender
appender.addFilter(matchFilter);
// attach DenyAllFilter to end of filter chain to deny neutral
// (non matching) messages
appender.addFilter(new DenyAllFilter());
// set appender on root and set level to debug
root.addAppender(appender);
root.setLevel(Level.TRACE);
Level[] levelArray = new Level[] {Level.TRACE, Level.DEBUG, Level.INFO, Level.WARN,
Level.ERROR, Level.FATAL};
for (int x = 0; x < levelArray.length; x++) {
// set the level to match
matchFilter.setLevelToMatch(levelArray[x].toString());
common("pass " + x + "; filter set to accept only "
+ levelArray[x].toString() + " msgs");
}
Transformer.transform(ACCEPT_FILE, ACCEPT_FILTERED, new LineNumberFilter());
assertTrue(Compare.compare(ACCEPT_FILTERED, ACCEPT_WITNESS));
| void | common(java.lang.String msg)
Logger logger = Logger.getLogger("test");
logger.trace(msg);
logger.debug(msg);
logger.info(msg);
logger.warn(msg);
logger.error(msg);
logger.fatal(msg);
| public void | deny()
// set up appender
Layout layout = new SimpleLayout();
Appender appender = new FileAppender(layout, DENY_FILE, false);
// create LevelMatchFilter, set to deny matches
LevelMatchFilter matchFilter = new LevelMatchFilter();
matchFilter.setAcceptOnMatch(false);
// attach match filter to appender
appender.addFilter(matchFilter);
// set appender on root and set level to debug
root.addAppender(appender);
root.setLevel(Level.TRACE);
Level[] levelArray = new Level[] {Level.TRACE, Level.DEBUG, Level.INFO, Level.WARN,
Level.ERROR, Level.FATAL};
for (int x = 0; x < levelArray.length; x++) {
// set the level to match
matchFilter.setLevelToMatch(levelArray[x].toString());
common("pass " + x + "; filter set to deny only " + levelArray[x].toString()
+ " msgs");
}
Transformer.transform(DENY_FILE, DENY_FILTERED, new LineNumberFilter());
assertTrue(Compare.compare(DENY_FILTERED, DENY_WITNESS));
| public void | setUp()
root = Logger.getRootLogger();
root.removeAllAppenders();
| public static junit.framework.Test | suite()
TestSuite suite = new TestSuite();
suite.addTest(new LevelMatchFilterTestCase("accept"));
suite.addTest(new LevelMatchFilterTestCase("deny"));
return suite;
| public void | tearDown()
root.getLoggerRepository().resetConfiguration();
|
|