org.apache.logging.log4j.junit.LoggerContextRule Java Examples
The following examples show how to use
org.apache.logging.log4j.junit.LoggerContextRule.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CompositeConfigurationTest.java From logging-log4j2 with Apache License 2.0 | 6 votes |
@Test public void testAppenderRefFilterMerge() { final LoggerContextRule lcr = new LoggerContextRule( "classpath:log4j-comp-logger-ref.xml,log4j-comp-logger-ref.json"); final Statement test = new Statement() { @Override public void evaluate() throws Throwable { final CompositeConfiguration config = (CompositeConfiguration) lcr.getConfiguration(); final List<AppenderRef> appenderRefList = config.getLogger("cat1").getAppenderRefs(); final AppenderRef appenderRef = getAppenderRef(appenderRefList, "STDOUT"); assertTrue("Expected cat1 STDOUT appenderRef to have a regex filter", appenderRef.getFilter() != null && appenderRef.getFilter() instanceof RegexFilter); } }; runTest(lcr, test); }
Example #2
Source File: CompositeConfigurationTest.java From logging-log4j2 with Apache License 2.0 | 6 votes |
@Test public void testAttributeMergeForLoggers() { final LoggerContextRule lcr = new LoggerContextRule("classpath:log4j-comp-logger-root.xml,log4j-comp-logger-attr-override.json"); final Statement test = new Statement() { @Override public void evaluate() throws Throwable { final CompositeConfiguration config = (CompositeConfiguration) lcr.getConfiguration(); //Test for Root log level override assertEquals("Expected Root logger log level to be WARN", Level.WARN, config.getRootLogger().getLevel()); //Test for cat2 level override final LoggerConfig cat2 = config.getLogger("cat2"); assertEquals("Expected cat2 log level to be INFO", Level.INFO, cat2.getLevel()); //Test for cat2 additivity override assertTrue("Expected cat2 additivity to be true", cat2.isAdditive()); //Regression //Check level on cat3 (not present in root config) assertEquals("Expected cat3 log level to be ERROR", Level.ERROR, config.getLogger("cat3").getLevel()); //Check level on cat1 (not present in overridden config) assertEquals("Expected cat1 log level to be DEBUG", Level.DEBUG, config.getLogger("cat1").getLevel()); } }; runTest(lcr, test); }
Example #3
Source File: CompositeConfigurationTest.java From logging-log4j2 with Apache License 2.0 | 6 votes |
@Test public void testAttributeCheckWhenMergingConfigurations() { final LoggerContextRule lcr = new LoggerContextRule("classpath:log4j-comp-root-loggers.xml,log4j-comp-logger.json"); final Statement test = new Statement() { @Override public void evaluate() throws Throwable { try { final CompositeConfiguration config = (CompositeConfiguration) lcr.getConfiguration(); Assert.assertNotNull(config); } catch (final NullPointerException e) { fail("Should not throw NullPointerException when there are different nodes."); } } }; runTest(lcr, test); }
Example #4
Source File: JdbcAppenderMapMessageDataSourceTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
protected JdbcAppenderMapMessageDataSourceTest(final JdbcRule jdbcRule) { // @formatter:off this.rules = RuleChain.emptyRuleChain() .around(new JndiRule("java:/comp/env/jdbc/TestDataSourceAppender", createMockDataSource())) .around(jdbcRule) .around(new LoggerContextRule("org/apache/logging/log4j/jdbc/appender/log4j2-data-source-map-message.xml")); // @formatter:on this.jdbcRule = jdbcRule; }
Example #5
Source File: RandomAccessFileAppenderTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
public RandomAccessFileAppenderTest(final String testName, final boolean locationEnabled, final String type) { this.init = new LoggerContextRule(testName + type); this.logFile = new File("target", testName + ".log"); this.files = new CleanFiles(this.logFile); this.locationEnabled = locationEnabled; this.chain = RuleChain.outerRule(files).around(init); }
Example #6
Source File: CompositeConfigurationTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
private void runTest(final LoggerContextRule rule, final Statement statement) { try { rule.apply(statement, Description .createTestDescription(getClass(), Thread.currentThread().getStackTrace()[1].getMethodName())) .evaluate(); } catch (final Throwable e) { Throwables.rethrow(e); } }
Example #7
Source File: CompositeConfigurationTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Test public void compositeLogger() { final LoggerContextRule lcr = new LoggerContextRule("classpath:log4j-comp-logger.xml,log4j-comp-logger.json"); final Statement test = new Statement() { @Override public void evaluate() throws Throwable { final CompositeConfiguration config = (CompositeConfiguration) lcr.getConfiguration(); Map<String, Appender> appendersMap = config.getLogger("cat1").getAppenders(); assertEquals("Expected 2 Appender references for cat1 but got " + appendersMap.size(), 2, appendersMap.size()); assertTrue(appendersMap.get("STDOUT") instanceof ConsoleAppender); Filter loggerFilter = config.getLogger("cat1").getFilter(); assertTrue(loggerFilter instanceof RegexFilter); assertEquals(loggerFilter.getOnMatch(), Filter.Result.DENY); appendersMap = config.getLogger("cat2").getAppenders(); assertEquals("Expected 1 Appender reference for cat2 but got " + appendersMap.size(), 1, appendersMap.size()); assertTrue(appendersMap.get("File") instanceof FileAppender); appendersMap = config.getLogger("cat3").getAppenders(); assertEquals("Expected 1 Appender reference for cat3 but got " + appendersMap.size(), 1, appendersMap.size()); assertTrue(appendersMap.get("File") instanceof FileAppender); appendersMap = config.getRootLogger().getAppenders(); assertEquals("Expected 2 Appender references for the root logger but got " + appendersMap.size(), 2, appendersMap.size()); assertTrue(appendersMap.get("File") instanceof FileAppender); assertTrue(appendersMap.get("STDOUT") instanceof ConsoleAppender); assertEquals("Expected COMPOSITE_SOURCE for composite configuration but got " + config.getConfigurationSource(), config.getConfigurationSource(), ConfigurationSource.COMPOSITE_SOURCE); } }; runTest(lcr, test); }
Example #8
Source File: AbstractJdbcAppenderDataSourceTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
protected AbstractJdbcAppenderDataSourceTest(final JdbcRule jdbcRule) { this.rules = RuleChain.emptyRuleChain() .around(new JndiRule("java:/comp/env/jdbc/TestDataSourceAppender", createMockDataSource())) .around(jdbcRule) .around(new LoggerContextRule( "org/apache/logging/log4j/jdbc/appender/log4j2-data-source.xml")); this.jdbcRule = jdbcRule; }
Example #9
Source File: AbstractJdbcAppenderFactoryMethodTest.java From logging-log4j2 with Apache License 2.0 | 4 votes |
protected AbstractJdbcAppenderFactoryMethodTest(final JdbcRule jdbcRule, final String databaseType) { this.rules = RuleChain.emptyRuleChain().around(jdbcRule).around(new LoggerContextRule( "org/apache/logging/log4j/jdbc/appender/log4j2-" + databaseType + "-factory-method.xml")); this.jdbcRule = jdbcRule; }
Example #10
Source File: JdbcAppenderColumnMappingPatternTest.java From logging-log4j2 with Apache License 2.0 | 4 votes |
protected JdbcAppenderColumnMappingPatternTest(final JdbcRule jdbcRule) { this.rules = RuleChainFactory.create(jdbcRule, new LoggerContextRule( "org/apache/logging/log4j/jdbc/appender/log4j2-dm-column-mapping-pattern.xml")); this.jdbcRule = jdbcRule; }
Example #11
Source File: JdbcAppenderColumnMappingLiteralTest.java From logging-log4j2 with Apache License 2.0 | 4 votes |
protected JdbcAppenderColumnMappingLiteralTest(final JdbcRule jdbcRule) { this.rules = RuleChainFactory.create(jdbcRule, new LoggerContextRule("org/apache/logging/log4j/jdbc/appender/log4j2-dm-column-mapping-literal.xml")); this.jdbcRule = jdbcRule; }
Example #12
Source File: RandomRollingAppenderOnStartupTest.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public RandomRollingAppenderOnStartupTest(final String configFile) { this.loggerContextRule = LoggerContextRule.createShutdownTimeoutLoggerContextRule(configFile); }
Example #13
Source File: DataSourceConnectionSourceTest.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public DataSourceConnectionSourceTest(final String jndiURL) { this.rules = RuleChain.outerRule(new JndiRule(jndiURL, dataSource)) .around(new LoggerContextRule(CONFIG)); this.jndiURL = jndiURL; }
Example #14
Source File: ScriptRefFilterTest.java From logging-log4j2 with Apache License 2.0 | 4 votes |
@Override public LoggerContextRule getContext() { return context; }
Example #15
Source File: ScriptFilterTest.java From logging-log4j2 with Apache License 2.0 | 4 votes |
@Override public LoggerContextRule getContext() { return context; }
Example #16
Source File: ScriptFileFilterTest.java From logging-log4j2 with Apache License 2.0 | 4 votes |
@Override public LoggerContextRule getContext() { return context; }
Example #17
Source File: ScriptFileFilterPropertiesTest.java From logging-log4j2 with Apache License 2.0 | 4 votes |
@Override public LoggerContextRule getContext() { return context; }
Example #18
Source File: AsyncAppenderTest.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public AsyncAppenderTest(final String configFileName) { context = new LoggerContextRule(configFileName); }
Example #19
Source File: ScriptAppenderSelectorTest.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public ScriptAppenderSelectorTest(final String configLocation) { this.loggerContextRule = new LoggerContextRule(configLocation); }
Example #20
Source File: RollingAppenderNoUnconditionalDeleteTest.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public RollingAppenderNoUnconditionalDeleteTest(final String configFile, final String dir) { this.directory = new File(dir); this.loggerContextRule = LoggerContextRule.createShutdownTimeoutLoggerContextRule(configFile); deleteDir(); deleteDirParent(); }
Example #21
Source File: RollingAppenderCountTest.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public RollingAppenderCountTest() { this.loggerContextRule = LoggerContextRule.createShutdownTimeoutLoggerContextRule(CONFIG); }
Example #22
Source File: XmlCompleteFileAppenderTest.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public XmlCompleteFileAppenderTest(final Class<ContextSelector> contextSelector) { this.loggerContextRule = new LoggerContextRule("XmlCompleteFileAppenderTest.xml", contextSelector); this.cleanFiles = new CleanFiles(logFile); this.ruleChain = RuleChain.outerRule(cleanFiles).around(loggerContextRule); }
Example #23
Source File: RollingAppenderSizeTest.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public RollingAppenderSizeTest(final String configFile, final String fileExtension, final boolean createOnDemand) { this.fileExtension = fileExtension; this.createOnDemand = createOnDemand; this.loggerContextRule = LoggerContextRule.createShutdownTimeoutLoggerContextRule(configFile); this.chain = loggerContextRule.withCleanFoldersRule(DIR); }
Example #24
Source File: RollingAppenderOnStartupTest.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public RollingAppenderOnStartupTest() { this.loggerContextRule = LoggerContextRule.createShutdownTimeoutLoggerContextRule(CONFIG); }
Example #25
Source File: RoutesScriptAppenderTest.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public RoutesScriptAppenderTest(final String configLocation, final boolean expectBindingEntries) { this.loggerContextRule = new LoggerContextRule(configLocation); this.expectBindingEntries = expectBindingEntries; }
Example #26
Source File: DefaultRouteScriptAppenderTest.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public DefaultRouteScriptAppenderTest(final String configLocation, final boolean expectBindingEntries) { this.loggerContextRule = new LoggerContextRule(configLocation); this.expectBindingEntries = expectBindingEntries; }
Example #27
Source File: XIncludeTest.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public XIncludeTest(final String configFileName, final String logFileName) { this.logFileName = logFileName; this.init = new LoggerContextRule(configFileName); this.rules = RuleChain.outerRule(new CleanFiles(logFileName)).around(this.init); }
Example #28
Source File: ConfigurationTest.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public ConfigurationTest(final String configFileName, final String logFileName) { this.logFileName = logFileName; this.init = new LoggerContextRule(configFileName); rules = RuleChain.outerRule(new CleanFiles(logFileName)).around(this.init); }
Example #29
Source File: CsvParameterLayoutTest.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public CsvParameterLayoutTest(final LoggerContextRule contextRule) { this.init = contextRule; }
Example #30
Source File: CsvParameterLayoutTest.java From logging-log4j2 with Apache License 2.0 | 4 votes |
@Parameterized.Parameters(name = "{0}") public static Collection<Object[]> data() { return Arrays.asList(new Object[][] { { new LoggerContextRule("csvParamsSync.xml"), }, { new LoggerContextRule("csvParamsMixedAsync.xml"), }, }); }