You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2020/09/13 18:03:08 UTC
[logging-log4j2] branch master updated: Migrate more config tests
to JUnit 5
This is an automated email from the ASF dual-hosted git repository.
mattsicker pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/master by this push:
new 7c630ac Migrate more config tests to JUnit 5
7c630ac is described below
commit 7c630acb36119a5cc6b33dc2759890840d3b2a6d
Author: Matt Sicker <bo...@gmail.com>
AuthorDate: Sun Sep 13 13:02:35 2020 -0500
Migrate more config tests to JUnit 5
Signed-off-by: Matt Sicker <bo...@gmail.com>
---
.../config/builder/ConfigurationAssemblerTest.java | 28 +++----
.../config/builder/ConfigurationBuilderTest.java | 14 ++--
.../core/config/plugins/LegacyPluginTest.java | 31 +++-----
.../plugins/util/PluginManagerPackagesTest.java | 26 +++----
.../validators/RequiredValidatorTest.java | 10 +--
.../validators/ValidHostValidatorTest.java | 20 ++---
.../validators/ValidPortValidatorTest.java | 10 +--
.../ValidatingPluginWithFailoverTest.java | 12 +--
.../ValidatingPluginWithGenericBuilderTest.java | 14 ++--
...ngPluginWithGenericSubclassFoo1BuilderTest.java | 14 ++--
.../ValidatingPluginWithTypedBuilderTest.java | 14 ++--
.../PropertiesConfigurationRootLoggerOnlyTest.java | 60 ---------------
.../properties/PropertiesConfigurationTest.java | 85 +++++++++++++++++-----
...rtiesConfigurationTrailingSpaceOnLevelTest.java | 67 -----------------
.../properties/RollingFilePropertiesTest.java | 60 ---------------
.../core/config/xml/XmlConfigurationPropsTest.java | 22 +++---
...Security.java => XmlConfigurationSecurity.java} | 13 +++-
.../log4j/core/config/xml/XmlLoggerPropsTest.java | 72 ++++++++----------
.../log4j/core/config/xml/XmlSchemaTest.java | 59 ++++++++-------
19 files changed, 234 insertions(+), 397 deletions(-)
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/builder/ConfigurationAssemblerTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/builder/ConfigurationAssemblerTest.java
index 3859393..ac40a48 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/builder/ConfigurationAssemblerTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/builder/ConfigurationAssemblerTest.java
@@ -16,11 +16,6 @@
*/
package org.apache.logging.log4j.core.config.builder;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
import java.util.List;
import java.util.Map;
@@ -43,11 +38,12 @@ import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
import org.apache.logging.log4j.core.filter.ThresholdFilter;
import org.apache.logging.log4j.core.layout.PatternLayout;
import org.apache.logging.log4j.core.util.Constants;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.junit.jupiter.api.Assertions.*;
-/**
- *
- */
public class ConfigurationAssemblerTest {
@Test
@@ -85,16 +81,16 @@ public class ConfigurationAssemblerTest {
assertNotNull(config);
assertNotNull(config.getName());
assertFalse(config.getName().isEmpty());
- assertNotNull("No configuration created", config);
- assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED);
+ assertNotNull(config, "No configuration created");
+ assertEquals(config.getState(), LifeCycle.State.STARTED, "Incorrect State: " + config.getState());
final Map<String, Appender> appenders = config.getAppenders();
assertNotNull(appenders);
- assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 1);
+ assertEquals(appenders.size(), 1, "Incorrect number of Appenders: " + appenders.size());
final ConsoleAppender consoleAppender = (ConsoleAppender)appenders.get("Stdout");
final PatternLayout gelfLayout = (PatternLayout)consoleAppender.getLayout();
final Map<String, LoggerConfig> loggers = config.getLoggers();
assertNotNull(loggers);
- assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2);
+ assertEquals(loggers.size(), 2, "Incorrect number of LoggerConfigs: " + loggers.size());
final LoggerConfig rootLoggerConfig = loggers.get("");
assertEquals(Level.ERROR, rootLoggerConfig.getLevel());
assertFalse(rootLoggerConfig.isIncludeLocation());
@@ -102,10 +98,10 @@ public class ConfigurationAssemblerTest {
assertEquals(Level.DEBUG, loggerConfig.getLevel());
assertTrue(loggerConfig.isIncludeLocation());
final Filter filter = config.getFilter();
- assertNotNull("No Filter", filter);
- assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter);
+ assertNotNull(filter, "No Filter");
+ assertThat(filter, instanceOf(ThresholdFilter.class));
final List<CustomLevelConfig> customLevels = config.getCustomLevels();
- assertNotNull("No CustomLevels", filter);
+ assertNotNull(filter, "No CustomLevels");
assertEquals(1, customLevels.size());
final CustomLevelConfig customLevel = customLevels.get(0);
assertEquals("Panic", customLevel.getLevelName());
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/builder/ConfigurationBuilderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/builder/ConfigurationBuilderTest.java
index a620c30..40c0717 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/builder/ConfigurationBuilderTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/builder/ConfigurationBuilderTest.java
@@ -16,8 +16,6 @@
*/
package org.apache.logging.log4j.core.config.builder;
-import java.util.concurrent.TimeUnit;
-
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.appender.ConsoleAppender;
@@ -25,10 +23,13 @@ import org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory;
import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledOnOs;
+import org.junit.jupiter.api.condition.OS;
+
+import java.util.concurrent.TimeUnit;
-import static org.junit.Assert.*;
-import static org.junit.Assume.assumeTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class ConfigurationBuilderTest {
@@ -94,10 +95,9 @@ public class ConfigurationBuilderTest {
INDENT + "</Loggers>" + EOL +
"</Configuration>" + EOL;
- // TODO make test run properly on Windows
@Test
+ @DisabledOnOs(OS.WINDOWS) // TODO make test run properly on Windows
public void testXmlConstructing() throws Exception {
- assumeTrue(System.lineSeparator().length() == 1); // Only run test on platforms with single character line endings (such as Linux), not on Windows
final ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder();
addTestFixtures("config name", builder);
final String xmlConfiguration = builder.toXmlConfiguration();
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/LegacyPluginTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/LegacyPluginTest.java
index 3aad3c6..757089f 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/LegacyPluginTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/LegacyPluginTest.java
@@ -19,43 +19,34 @@ package org.apache.logging.log4j.core.config.plugins;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.Layout;
import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.core.config.xml.XmlConfiguration;
-import org.apache.logging.log4j.spi.LoggerContext;
-import org.junit.Test;
+import org.apache.logging.log4j.junit.LoggerContextSource;
+import org.junit.jupiter.api.Test;
import java.util.Map;
-import static org.junit.Assert.*;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.junit.jupiter.api.Assertions.*;
-/**
- * Class Description goes here.
- */
+@LoggerContextSource("legacy-plugins.xml")
public class LegacyPluginTest {
- private static final String CONFIG_FILE = "legacy-plugins.xml";
-
@Test
- public void testLegacy() throws Exception {
- LoggerContext context = Configurator.initialize("LegacyTest", null, CONFIG_FILE);
- assertNotNull("No Logger Context", context);
- Configuration configuration = ((org.apache.logging.log4j.core.LoggerContext) context).getConfiguration();
- assertNotNull("No Configuration", configuration);
- assertTrue("Incorrect Configuration class " + configuration.getClass().getName(),
- configuration instanceof XmlConfiguration);
+ public void testLegacy(final Configuration configuration) throws Exception {
+ assertThat(configuration, instanceOf(XmlConfiguration.class));
for (Map.Entry<String, Appender> entry : configuration.getAppenders().entrySet()) {
if (entry.getKey().equalsIgnoreCase("console")) {
Layout layout = entry.getValue().getLayout();
assertNotNull("No layout for Console Appender");
String name = layout.getClass().getSimpleName();
- assertTrue("Incorrect Layout class. Expected LogstashLayout, Actual " + name,
- name.equals("LogstashLayout"));
+ assertEquals("LogstashLayout", name, "Incorrect Layout class. Expected LogstashLayout, Actual " + name);
} else if (entry.getKey().equalsIgnoreCase("customConsole")) {
Layout layout = entry.getValue().getLayout();
assertNotNull("No layout for CustomConsole Appender");
String name = layout.getClass().getSimpleName();
- assertTrue("Incorrect Layout class. Expected CustomConsoleLayout, Actual " + name,
- name.equals("CustomConsoleLayout"));
+ assertEquals("CustomConsoleLayout",
+ name, "Incorrect Layout class. Expected CustomConsoleLayout, Actual " + name);
}
}
}
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/PluginManagerPackagesTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/PluginManagerPackagesTest.java
index c55b45e..7e4aae3 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/PluginManagerPackagesTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/PluginManagerPackagesTest.java
@@ -16,13 +16,11 @@
*/
package org.apache.logging.log4j.core.config.plugins.util;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import java.util.Locale;
@@ -41,15 +39,17 @@ import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.status.StatusLogger;
import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.AfterClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
public class PluginManagerPackagesTest {
private static Configuration config;
private static ListAppender listAppender;
private static LoggerContext ctx;
- @AfterClass
+ @AfterAll
public static void cleanupClass() {
System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
ctx.reconfigure();
@@ -64,9 +64,9 @@ public class PluginManagerPackagesTest {
// So we don't create the custom plugin class until this test is run.
final File orig = new File("target/test-classes/customplugin/FixedStringLayout.java.source");
final File f = new File(orig.getParentFile(), "FixedStringLayout.java");
- assertTrue("renamed source file failed", orig.renameTo(f));
+ assertTrue(orig.renameTo(f), "renamed source file failed");
compile(f);
- assertTrue("reverted source file failed", f.renameTo(orig));
+ assertTrue(f.renameTo(orig), "reverted source file failed");
// load the compiled class
Class.forName("customplugin.FixedStringLayout");
@@ -81,7 +81,7 @@ public class PluginManagerPackagesTest {
logger.info("this message is ignored");
final List<String> messages = listAppender.getMessages();
- assertEquals(messages.toString(), 1, messages.size());
+ assertEquals(1, messages.size(), messages.toString());
assertEquals("abc123XYZ", messages.get(0));
}
@@ -91,12 +91,12 @@ public class PluginManagerPackagesTest {
final DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
final List<String> errors = new ArrayList<>();
try (final StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null)) {
- final Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromFiles(Arrays
- .asList(f));
+ final Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromFiles(
+ Collections.singletonList(f));
// compile generated source
// (switch off annotation processing: no need to create Log4j2Plugins.dat)
- final List<String> options = Arrays.asList("-proc:none");
+ final List<String> options = Collections.singletonList("-proc:none");
compiler.getTask(null, fileManager, diagnostics, options, null, compilationUnits).call();
// check we don't have any compilation errors
@@ -106,6 +106,6 @@ public class PluginManagerPackagesTest {
}
}
}
- assertTrue(errors.toString(), errors.isEmpty());
+ assertTrue(errors.isEmpty(), errors.toString());
}
}
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/validation/validators/RequiredValidatorTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/validation/validators/RequiredValidatorTest.java
index c2dd9d4..97bfe36 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/validation/validators/RequiredValidatorTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/validation/validators/RequiredValidatorTest.java
@@ -22,10 +22,10 @@ import org.apache.logging.log4j.core.config.plugins.util.PluginBuilder;
import org.apache.logging.log4j.plugins.util.PluginManager;
import org.apache.logging.log4j.plugins.util.PluginType;
import org.apache.logging.log4j.plugins.validation.ValidatingPlugin;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
public class RequiredValidatorTest {
@@ -33,12 +33,12 @@ public class RequiredValidatorTest {
private Node node;
@SuppressWarnings("unchecked")
- @Before
+ @BeforeEach
public void setUp() throws Exception {
final PluginManager manager = new PluginManager("Test");
manager.collectPlugins();
plugin = (PluginType<ValidatingPlugin>) manager.getPluginType("Validator");
- assertNotNull("Rebuild this module to make sure annotation processing kicks in.", plugin);
+ assertNotNull(plugin, "Rebuild this module to make sure annotation processing kicks in.");
node = new Node(null, "Validator", plugin);
}
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/validation/validators/ValidHostValidatorTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/validation/validators/ValidHostValidatorTest.java
index 049cc23..4098b19 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/validation/validators/ValidHostValidatorTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/validation/validators/ValidHostValidatorTest.java
@@ -17,34 +17,34 @@
package org.apache.logging.log4j.core.config.plugins.validation.validators;
import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.junit.StatusLoggerLevelExtension;
import org.apache.logging.log4j.plugins.Node;
import org.apache.logging.log4j.core.config.NullConfiguration;
import org.apache.logging.log4j.core.config.plugins.util.PluginBuilder;
import org.apache.logging.log4j.plugins.util.PluginManager;
import org.apache.logging.log4j.plugins.util.PluginType;
import org.apache.logging.log4j.plugins.validation.HostAndPort;
-import org.apache.logging.log4j.junit.StatusLoggerRule;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
public class ValidHostValidatorTest {
- @Rule
- public StatusLoggerRule rule = new StatusLoggerRule(Level.FATAL);
+ @RegisterExtension
+ static StatusLoggerLevelExtension extension = new StatusLoggerLevelExtension(Level.FATAL);
private PluginType<HostAndPort> plugin;
private Node node;
@SuppressWarnings("unchecked")
- @Before
+ @BeforeEach
public void setUp() throws Exception {
final PluginManager manager = new PluginManager("Test");
manager.collectPlugins();
plugin = (PluginType<HostAndPort>) manager.getPluginType("HostAndPort");
- assertNotNull("Rebuild this module to ensure annotation processing has been done.", plugin);
+ assertNotNull(plugin, "Rebuild this module to ensure annotation processing has been done.");
node = new Node(null, "HostAndPort", plugin);
}
@@ -58,7 +58,7 @@ public class ValidHostValidatorTest {
node.getAttributes().put("host", "256.256.256.256");
node.getAttributes().put("port", "1");
final HostAndPort plugin = buildPlugin();
- assertNull("Expected null, but got: " + plugin, plugin);
+ assertNull(plugin, "Expected null, but got: " + plugin);
}
@Test
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/validation/validators/ValidPortValidatorTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/validation/validators/ValidPortValidatorTest.java
index 208010a..3a4146d 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/validation/validators/ValidPortValidatorTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/validation/validators/ValidPortValidatorTest.java
@@ -22,22 +22,22 @@ import org.apache.logging.log4j.plugins.Node;
import org.apache.logging.log4j.plugins.util.PluginManager;
import org.apache.logging.log4j.plugins.util.PluginType;
import org.apache.logging.log4j.plugins.validation.HostAndPort;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
public class ValidPortValidatorTest {
private PluginType<HostAndPort> plugin;
private Node node;
@SuppressWarnings("unchecked")
- @Before
+ @BeforeEach
public void setUp() throws Exception {
final PluginManager manager = new PluginManager("Test");
manager.collectPlugins();
plugin = (PluginType<HostAndPort>) manager.getPluginType("HostAndPort");
- assertNotNull("Rebuild this module to ensure annotation processing has been done.", plugin);
+ assertNotNull(plugin, "Rebuild this module to ensure annotation processing has been done.");
node = new Node(null, "HostAndPort", plugin);
node.getAttributes().put("host", "localhost");
}
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/validation/validators/ValidatingPluginWithFailoverTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/validation/validators/ValidatingPluginWithFailoverTest.java
index 744231f..f6c6086 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/validation/validators/ValidatingPluginWithFailoverTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/validation/validators/ValidatingPluginWithFailoverTest.java
@@ -29,14 +29,16 @@ import org.apache.logging.log4j.plugins.util.PluginType;
import org.apache.logging.log4j.status.StatusData;
import org.apache.logging.log4j.status.StatusListener;
import org.apache.logging.log4j.status.StatusLogger;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.emptyCollectionOf;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
public class ValidatingPluginWithFailoverTest {
@@ -44,12 +46,12 @@ public class ValidatingPluginWithFailoverTest {
private Node node;
@SuppressWarnings("unchecked")
- @Before
+ @BeforeEach
public void setUp() throws Exception {
final PluginManager manager = new PluginManager(Core.CATEGORY_NAME);
manager.collectPlugins();
plugin = (PluginType<FailoverAppender>) manager.getPluginType("failover");
- assertNotNull("Rebuild this module to make sure annotation processing kicks in.", plugin);
+ assertNotNull(plugin, "Rebuild this module to make sure annotation processing kicks in.");
AppenderRef appenderRef = AppenderRef.createAppenderRef("List", Level.ALL, null);
node = new Node(null, "failover", plugin);
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/validation/validators/ValidatingPluginWithGenericBuilderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/validation/validators/ValidatingPluginWithGenericBuilderTest.java
index 814ac68..4c42a7b 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/validation/validators/ValidatingPluginWithGenericBuilderTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/validation/validators/ValidatingPluginWithGenericBuilderTest.java
@@ -16,18 +16,16 @@
*/
package org.apache.logging.log4j.core.config.plugins.validation.validators;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
import org.apache.logging.log4j.plugins.Node;
import org.apache.logging.log4j.core.config.NullConfiguration;
import org.apache.logging.log4j.core.config.plugins.util.PluginBuilder;
import org.apache.logging.log4j.plugins.util.PluginManager;
import org.apache.logging.log4j.plugins.util.PluginType;
import org.apache.logging.log4j.plugins.validation.ValidatingPluginWithGenericBuilder;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
public class ValidatingPluginWithGenericBuilderTest {
@@ -35,12 +33,12 @@ public class ValidatingPluginWithGenericBuilderTest {
private Node node;
@SuppressWarnings("unchecked")
- @Before
+ @BeforeEach
public void setUp() throws Exception {
final PluginManager manager = new PluginManager("Test");
manager.collectPlugins();
plugin = (PluginType<ValidatingPluginWithGenericBuilder>) manager.getPluginType("ValidatingPluginWithGenericBuilder");
- assertNotNull("Rebuild this module to make sure annotation processing kicks in.", plugin);
+ assertNotNull(plugin, "Rebuild this module to make sure annotation processing kicks in.");
node = new Node(null, "Validator", plugin);
}
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/validation/validators/ValidatingPluginWithGenericSubclassFoo1BuilderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/validation/validators/ValidatingPluginWithGenericSubclassFoo1BuilderTest.java
index bea4e5a..f43ee88 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/validation/validators/ValidatingPluginWithGenericSubclassFoo1BuilderTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/validation/validators/ValidatingPluginWithGenericSubclassFoo1BuilderTest.java
@@ -16,18 +16,16 @@
*/
package org.apache.logging.log4j.core.config.plugins.validation.validators;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
import org.apache.logging.log4j.plugins.Node;
import org.apache.logging.log4j.core.config.NullConfiguration;
import org.apache.logging.log4j.core.config.plugins.util.PluginBuilder;
import org.apache.logging.log4j.plugins.util.PluginManager;
import org.apache.logging.log4j.plugins.util.PluginType;
import org.apache.logging.log4j.plugins.validation.PluginWithGenericSubclassFoo1Builder;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
public class ValidatingPluginWithGenericSubclassFoo1BuilderTest {
@@ -35,12 +33,12 @@ public class ValidatingPluginWithGenericSubclassFoo1BuilderTest {
private Node node;
@SuppressWarnings("unchecked")
- @Before
+ @BeforeEach
public void setUp() throws Exception {
final PluginManager manager = new PluginManager("Test");
manager.collectPlugins();
plugin = (PluginType<PluginWithGenericSubclassFoo1Builder>) manager.getPluginType("PluginWithGenericSubclassFoo1Builder");
- assertNotNull("Rebuild this module to make sure annotation processing kicks in.", plugin);
+ assertNotNull(plugin, "Rebuild this module to make sure annotation processing kicks in.");
node = new Node(null, "Validator", plugin);
}
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/validation/validators/ValidatingPluginWithTypedBuilderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/validation/validators/ValidatingPluginWithTypedBuilderTest.java
index 0f00d46..cafc125 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/validation/validators/ValidatingPluginWithTypedBuilderTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/validation/validators/ValidatingPluginWithTypedBuilderTest.java
@@ -16,18 +16,16 @@
*/
package org.apache.logging.log4j.core.config.plugins.validation.validators;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
import org.apache.logging.log4j.plugins.Node;
import org.apache.logging.log4j.core.config.NullConfiguration;
import org.apache.logging.log4j.core.config.plugins.util.PluginBuilder;
import org.apache.logging.log4j.plugins.util.PluginManager;
import org.apache.logging.log4j.plugins.util.PluginType;
import org.apache.logging.log4j.plugins.validation.ValidatingPluginWithTypedBuilder;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
public class ValidatingPluginWithTypedBuilderTest {
@@ -35,13 +33,13 @@ public class ValidatingPluginWithTypedBuilderTest {
private Node node;
@SuppressWarnings("unchecked")
- @Before
+ @BeforeEach
public void setUp() throws Exception {
final PluginManager manager = new PluginManager("Test");
manager.collectPlugins();
plugin = (PluginType<ValidatingPluginWithTypedBuilder>) manager
.getPluginType("ValidatingPluginWithTypedBuilder");
- assertNotNull("Rebuild this module to make sure annotation processing kicks in.", plugin);
+ assertNotNull(plugin, "Rebuild this module to make sure annotation processing kicks in.");
node = new Node(null, "Validator", plugin);
}
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationRootLoggerOnlyTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationRootLoggerOnlyTest.java
deleted file mode 100644
index acc5220..0000000
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationRootLoggerOnlyTest.java
+++ /dev/null
@@ -1,60 +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.logging.log4j.core.config.properties;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.Appender;
-import org.apache.logging.log4j.core.Filter;
-import org.apache.logging.log4j.core.LifeCycle;
-import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.LoggerConfig;
-import org.apache.logging.log4j.core.filter.ThresholdFilter;
-import org.apache.logging.log4j.junit.LoggerContextRule;
-import org.junit.ClassRule;
-import org.junit.Test;
-
-import java.util.Map;
-
-import static org.junit.Assert.*;
-
-/**
- *
- */
-public class PropertiesConfigurationRootLoggerOnlyTest {
-
- @ClassRule
- public static LoggerContextRule context = new LoggerContextRule("log4j2-properties-root-only.properties");
-
- @Test
- public void testPropertiesConfiguration() {
- final Configuration config = context.getConfiguration();
- assertNotNull("No configuration created", config);
- assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED);
- final Map<String, Appender> appenders = config.getAppenders();
- assertNotNull(appenders);
- assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 1);
- final Map<String, LoggerConfig> loggers = config.getLoggers();
- assertNotNull(loggers);
- assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 1);
- final Filter filter = config.getFilter();
- assertNotNull("No Filter", filter);
- assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter);
- final Logger logger = LogManager.getLogger(getClass());
- logger.info("Welcome to Log4j!");
- }
-}
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationTest.java
index 0e3c2c1..1a75512 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationTest.java
@@ -16,6 +16,7 @@
*/
package org.apache.logging.log4j.core.config.properties;
+import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.Appender;
@@ -24,37 +25,85 @@ import org.apache.logging.log4j.core.LifeCycle;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.LoggerConfig;
import org.apache.logging.log4j.core.filter.ThresholdFilter;
-import org.apache.logging.log4j.junit.LoggerContextRule;
-import org.junit.ClassRule;
-import org.junit.Test;
+import org.apache.logging.log4j.junit.LoggerContextSource;
+import org.junit.jupiter.api.Test;
import java.util.Map;
-import static org.junit.Assert.*;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.junit.jupiter.api.Assertions.*;
-/**
- *
- */
-public class PropertiesConfigurationTest {
+class PropertiesConfigurationTest {
+
+ @Test
+ @LoggerContextSource("log4j2-properties.properties")
+ void testPropertiesConfiguration(final Configuration config) {
+ assertEquals(config.getState(), LifeCycle.State.STARTED, "Incorrect State: " + config.getState());
+ final Map<String, Appender> appenders = config.getAppenders();
+ assertNotNull(appenders);
+ assertEquals(1, appenders.size(), "Incorrect number of Appenders: " + appenders.size());
+ final Map<String, LoggerConfig> loggers = config.getLoggers();
+ assertNotNull(loggers);
+ assertEquals(2, loggers.size(), "Incorrect number of LoggerConfigs: " + loggers.size());
+ final Filter filter = config.getFilter();
+ assertNotNull(filter, "No Filter");
+ assertTrue(filter instanceof ThresholdFilter, "Not a Threshold Filter");
+ final Logger logger = LogManager.getLogger(getClass());
+ logger.info("Welcome to Log4j!");
+ }
- @ClassRule
- public static LoggerContextRule context = new LoggerContextRule("log4j2-properties.properties");
+ @Test
+ @LoggerContextSource("log4j2-properties-root-only.properties")
+ void testRootLoggerOnly(final Configuration config) {
+ assertEquals(config.getState(), LifeCycle.State.STARTED, "Incorrect State: " + config.getState());
+ final Map<String, Appender> appenders = config.getAppenders();
+ assertNotNull(appenders);
+ assertEquals(appenders.size(), 1, "Incorrect number of Appenders: " + appenders.size());
+ final Map<String, LoggerConfig> loggers = config.getLoggers();
+ assertNotNull(loggers);
+ assertEquals(loggers.size(), 1, "Incorrect number of LoggerConfigs: " + loggers.size());
+ final Filter filter = config.getFilter();
+ assertNotNull(filter, "No Filter");
+ assertThat(filter, instanceOf(ThresholdFilter.class));
+ final Logger logger = LogManager.getLogger(getClass());
+ logger.info("Welcome to Log4j!");
+ }
@Test
- public void testPropertiesConfiguration() {
- final Configuration config = context.getConfiguration();
- assertNotNull("No configuration created", config);
- assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED);
+ @LoggerContextSource("log4j-rolling.properties")
+ void testRollingFile(final Configuration config) {
+ assertEquals(config.getState(), LifeCycle.State.STARTED, "Incorrect State: " + config.getState());
final Map<String, Appender> appenders = config.getAppenders();
assertNotNull(appenders);
- assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 1);
+ assertEquals(appenders.size(), 3, "Incorrect number of Appenders: " + appenders.size());
final Map<String, LoggerConfig> loggers = config.getLoggers();
assertNotNull(loggers);
- assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2);
+ assertEquals(loggers.size(), 2, "Incorrect number of LoggerConfigs: " + loggers.size());
final Filter filter = config.getFilter();
- assertNotNull("No Filter", filter);
- assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter);
+ assertNotNull(filter, "No Filter");
+ assertThat(filter, instanceOf(ThresholdFilter.class));
final Logger logger = LogManager.getLogger(getClass());
logger.info("Welcome to Log4j!");
}
+
+ @Test
+ @LoggerContextSource("log4j2-properties-trailing-space-on-level.properties")
+ void testTrailingSpaceOnLevel(final Configuration config) {
+ assertEquals(config.getState(), LifeCycle.State.STARTED, "Incorrect State: " + config.getState());
+ final Map<String, Appender> appenders = config.getAppenders();
+ assertNotNull(appenders);
+ assertEquals(appenders.size(), 1, "Incorrect number of Appenders: " + appenders.size());
+ final Map<String, LoggerConfig> loggers = config.getLoggers();
+ assertNotNull(loggers);
+ assertEquals(loggers.size(), 2, "Incorrect number of LoggerConfigs: " + loggers.size());
+ final Filter filter = config.getFilter();
+ assertNotNull(filter, "No Filter");
+ assertThat(filter, instanceOf(ThresholdFilter.class));
+ final Logger logger = LogManager.getLogger(getClass());
+
+ assertEquals(Level.DEBUG, logger.getLevel(), "Incorrect level " + logger.getLevel());
+
+ logger.debug("Welcome to Log4j!");
+ }
}
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationTrailingSpaceOnLevelTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationTrailingSpaceOnLevelTest.java
deleted file mode 100644
index 743040e..0000000
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationTrailingSpaceOnLevelTest.java
+++ /dev/null
@@ -1,67 +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.logging.log4j.core.config.properties;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Map;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.Appender;
-import org.apache.logging.log4j.core.Filter;
-import org.apache.logging.log4j.core.LifeCycle;
-import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.LoggerConfig;
-import org.apache.logging.log4j.core.filter.ThresholdFilter;
-import org.apache.logging.log4j.junit.LoggerContextRule;
-import org.junit.ClassRule;
-import org.junit.Test;
-
-/**
- *
- */
-public class PropertiesConfigurationTrailingSpaceOnLevelTest {
-
- @ClassRule
- public static LoggerContextRule context = new LoggerContextRule(
- "log4j2-properties-trailing-space-on-level.properties");
-
- @Test
- public void testPropertiesConfiguration() {
- final Configuration config = context.getConfiguration();
- assertNotNull("No configuration created", config);
- assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED);
- final Map<String, Appender> appenders = config.getAppenders();
- assertNotNull(appenders);
- assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 1);
- final Map<String, LoggerConfig> loggers = config.getLoggers();
- assertNotNull(loggers);
- assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2);
- final Filter filter = config.getFilter();
- assertNotNull("No Filter", filter);
- assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter);
- final Logger logger = LogManager.getLogger(getClass());
-
- assertEquals("Incorrect level " + logger.getLevel(), Level.DEBUG, logger.getLevel());
-
- logger.debug("Welcome to Log4j!");
- }
-}
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/properties/RollingFilePropertiesTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/properties/RollingFilePropertiesTest.java
deleted file mode 100644
index 9baf89b..0000000
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/properties/RollingFilePropertiesTest.java
+++ /dev/null
@@ -1,60 +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.logging.log4j.core.config.properties;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.Appender;
-import org.apache.logging.log4j.core.Filter;
-import org.apache.logging.log4j.core.LifeCycle;
-import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.LoggerConfig;
-import org.apache.logging.log4j.core.filter.ThresholdFilter;
-import org.apache.logging.log4j.junit.LoggerContextRule;
-import org.junit.ClassRule;
-import org.junit.Test;
-
-import java.util.Map;
-
-import static org.junit.Assert.*;
-
-/**
- *
- */
-public class RollingFilePropertiesTest {
-
- @ClassRule
- public static LoggerContextRule context = new LoggerContextRule("log4j-rolling.properties");
-
- @Test
- public void testPropertiesConfiguration() {
- final Configuration config = context.getConfiguration();
- assertNotNull("No configuration created", config);
- assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED);
- final Map<String, Appender> appenders = config.getAppenders();
- assertNotNull(appenders);
- assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 3);
- final Map<String, LoggerConfig> loggers = config.getLoggers();
- assertNotNull(loggers);
- assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2);
- final Filter filter = config.getFilter();
- assertNotNull("No Filter", filter);
- assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter);
- final Logger logger = LogManager.getLogger(getClass());
- logger.info("Welcome to Log4j!");
- }
-}
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/xml/XmlConfigurationPropsTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/xml/XmlConfigurationPropsTest.java
index 37781a9..94fa152 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/xml/XmlConfigurationPropsTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/xml/XmlConfigurationPropsTest.java
@@ -21,20 +21,18 @@ import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.apache.logging.log4j.core.util.Constants;
import org.apache.logging.log4j.status.StatusLogger;
-import org.junit.AfterClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.*;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.instanceOf;
-/**
- *
- */
public class XmlConfigurationPropsTest {
private static final String CONFIG = "log4j-props.xml";
private static final String CONFIG1 = "log4j-props1.xml";
- @AfterClass
+ @AfterAll
public static void cleanupClass() {
System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
final LoggerContext ctx = LoggerContext.getContext();
@@ -48,10 +46,9 @@ public class XmlConfigurationPropsTest {
final LoggerContext ctx = LoggerContext.getContext();
ctx.reconfigure();
final Configuration config = ctx.getConfiguration();
- assertTrue("Configuration is not an XmlConfiguration", config instanceof XmlConfiguration);
+ assertThat(config, instanceOf(XmlConfiguration.class));
}
-
@Test
public void testDefaultStatus() {
System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG1);
@@ -60,7 +57,7 @@ public class XmlConfigurationPropsTest {
final LoggerContext ctx = LoggerContext.getContext();
ctx.reconfigure();
final Configuration config = ctx.getConfiguration();
- assertTrue("Configuration is not an XmlConfiguration", config instanceof XmlConfiguration);
+ assertThat(config, instanceOf(XmlConfiguration.class));
} finally {
System.clearProperty(Constants.LOG4J_DEFAULT_STATUS_LEVEL);
}
@@ -74,10 +71,9 @@ public class XmlConfigurationPropsTest {
final LoggerContext ctx = LoggerContext.getContext();
ctx.reconfigure();
final Configuration config = ctx.getConfiguration();
- assertTrue("Configuration is not an XmlConfiguration", config instanceof XmlConfiguration);
+ assertThat(config, instanceOf(XmlConfiguration.class));
} finally {
System.clearProperty("log4j.level");
-
}
}
@@ -90,7 +86,7 @@ public class XmlConfigurationPropsTest {
final LoggerContext ctx = LoggerContext.getContext();
ctx.reconfigure();
final Configuration config = ctx.getConfiguration();
- assertTrue("Configuration is not an XmlConfiguration", config instanceof XmlConfiguration);
+ assertThat(config, instanceOf(XmlConfiguration.class));
} finally {
System.clearProperty("log4j.level");
System.clearProperty("log.level");
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/xml/XmlConigurationSecurity.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/xml/XmlConfigurationSecurity.java
similarity index 82%
rename from log4j-core/src/test/java/org/apache/logging/log4j/core/config/xml/XmlConigurationSecurity.java
rename to log4j-core/src/test/java/org/apache/logging/log4j/core/config/xml/XmlConfigurationSecurity.java
index f7d1425..4cd4c74 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/xml/XmlConigurationSecurity.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/xml/XmlConfigurationSecurity.java
@@ -18,15 +18,20 @@ package org.apache.logging.log4j.core.config.xml;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configurator;
-import org.junit.Test;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
import java.io.IOException;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-public class XmlConigurationSecurity {
+@Tag("functional")
+@Tag("security")
+public class XmlConfigurationSecurity {
- @Test(timeout = 5000L)
+ @Test
+ @Timeout(5)
public void xmlSecurity() throws IOException {
final LoggerContext context = Configurator.initialize("XmlConfigurationSecurity", "XmlConfigurationSecurity.xml");
assertNotNull(context.getConfiguration().getAppender("list"));
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/xml/XmlLoggerPropsTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/xml/XmlLoggerPropsTest.java
index 55a6224..b191524 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/xml/XmlLoggerPropsTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/xml/XmlLoggerPropsTest.java
@@ -16,52 +16,41 @@
*/
package org.apache.logging.log4j.core.config.xml;
-import java.util.List;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.junit.LoggerContextSource;
+import org.apache.logging.log4j.junit.Named;
import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.hamcrest.Matchers.allOf;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.*;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
-/**
- *
- */
-public class XmlLoggerPropsTest {
+import java.util.List;
- private static final String CONFIG = "log4j-loggerprops.xml";
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.*;
- @Rule
- public final LoggerContextRule context = new LoggerContextRule(CONFIG);
+public class XmlLoggerPropsTest {
- @BeforeClass
- public static void setupClass() {
+ @BeforeAll
+ static void setupClass() {
System.setProperty("test", "test");
}
- @Test
- public void testWithProps() {
- final ListAppender listAppender = context.getListAppender("List");
- assertNotNull("No List Appender", listAppender);
+ @AfterAll
+ static void tearDownClass() {
+ System.clearProperty("test");
+ }
- try {
- assertThat(context.getConfiguration(), is(instanceOf(XmlConfiguration.class)));
- Logger logger = LogManager.getLogger(XmlLoggerPropsTest.class);
- logger.debug("Test with props");
- logger = LogManager.getLogger("tiny.bubbles");
- logger.debug("Test on root");
- final List<String> events = listAppender.getMessages();
- assertTrue("No events", events.size() > 0);
- assertTrue("Incorrect number of events", events.size() == 2);
- assertThat(events.get(0), allOf(
+ @Test
+ @LoggerContextSource("log4j-loggerprops.xml")
+ public void testWithProps(final LoggerContext context, @Named("List") final ListAppender listAppender) {
+ assertThat(context.getConfiguration(), is(instanceOf(XmlConfiguration.class)));
+ context.getLogger(getClass()).debug("Test with props");
+ context.getLogger("tiny.bubbles").debug("Test on root");
+ final List<String> events = listAppender.getMessages();
+ listAppender.clear();
+ assertThat(events, hasSize(2));
+ assertThat(events.get(0), allOf(
containsString("user="),
containsString("phrasex=****"),
containsString("test=test"),
@@ -71,8 +60,8 @@ public class XmlLoggerPropsTest {
containsString("test5=test"),
containsString("attribKey=attribValue"),
containsString("duplicateKey=nodeValue")
- ));
- assertThat(events.get(1), allOf(
+ ));
+ assertThat(events.get(1), allOf(
containsString("user="),
containsString("phrasex=****"),
containsString("test=test"),
@@ -82,9 +71,6 @@ public class XmlLoggerPropsTest {
containsString("test5=test"),
containsString("attribKey=attribValue"),
containsString("duplicateKey=nodeValue")
- ));
- } finally {
- System.clearProperty("test");
- }
+ ));
}
}
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/xml/XmlSchemaTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/xml/XmlSchemaTest.java
index 29fe9e6..35f2367 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/xml/XmlSchemaTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/xml/XmlSchemaTest.java
@@ -21,11 +21,13 @@ import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
+import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.stream.Stream;
import javax.xml.XMLConstants;
import javax.xml.transform.sax.SAXSource;
@@ -37,14 +39,15 @@ import javax.xml.validation.Validator;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.mutable.MutableInt;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.XMLFilterImpl;
import org.xml.sax.helpers.XMLReaderFactory;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
public class XmlSchemaTest {
private static final String TARGET_NAMESPACE = "http://logging.apache.org/log4j/2.0/config";
@@ -100,33 +103,35 @@ public class XmlSchemaTest {
final MutableInt configs = new MutableInt();
final MutableInt failures = new MutableInt();
- Files.list(Paths.get("src/test/resources")) //
- .filter(filePath -> {
- final String fileName = filePath.getFileName().toString();
- if (!fileName.endsWith(".xml"))
- return false;
- for (final String ignore : IGNORE_CONFIGS) {
- if (fileName.contains(ignore))
+ try (final Stream<Path> testResources = Files.list(Paths.get("src", "test", "resources"))) {
+ testResources
+ .filter(filePath -> {
+ final String fileName = filePath.getFileName().toString();
+ if (!fileName.endsWith(".xml"))
return false;
- }
- return true;
- }) //
- .forEach(filePath -> {
- System.out.println("Validating " + configs.incrementAndGet() + ". [" + filePath + "]...");
- System.out.flush();
+ for (final String ignore : IGNORE_CONFIGS) {
+ if (fileName.contains(ignore))
+ return false;
+ }
+ return true;
+ }) //
+ .forEach(filePath -> {
+ System.out.println("Validating " + configs.incrementAndGet() + ". [" + filePath + "]...");
+ System.out.flush();
- try {
- final String xml = fixXml(
- FileUtils.readFileToString(filePath.toFile(), Charset.defaultCharset()));
- validator.validate(new SAXSource(namespaceAdder,
- new InputSource(new ByteArrayInputStream(xml.getBytes()))), null);
- } catch (final Exception ex) {
- System.err.println(ex);
- System.err.flush();
- failures.increment();
- }
- });
+ try {
+ final String xml = fixXml(
+ FileUtils.readFileToString(filePath.toFile(), Charset.defaultCharset()));
+ validator.validate(new SAXSource(namespaceAdder,
+ new InputSource(new ByteArrayInputStream(xml.getBytes()))), null);
+ } catch (final Exception ex) {
+ System.err.println(ex);
+ System.err.flush();
+ failures.increment();
+ }
+ });
+ }
- Assert.assertEquals(0, failures.intValue());
+ assertEquals(0, failures.intValue());
}
}