You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2022/01/16 15:05:00 UTC
[logging-log4j2] 01/02: Make the test use a system property in addition to a local property.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit 766d8b19153c5d1ef23f371d46b6d7f971bcee74
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jan 15 18:51:32 2022 -0500
Make the test use a system property in addition to a local property.
---
.../PropertiesRollingWithPropertiesTest.java | 22 ++++++++++++++++------
.../resources/log4j1-rolling-properties.properties | 4 ++--
2 files changed, 18 insertions(+), 8 deletions(-)
diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/config/PropertiesRollingWithPropertiesTest.java b/log4j-1.2-api/src/test/java/org/apache/log4j/config/PropertiesRollingWithPropertiesTest.java
index 87326cf..c149ab9 100644
--- a/log4j-1.2-api/src/test/java/org/apache/log4j/config/PropertiesRollingWithPropertiesTest.java
+++ b/log4j-1.2-api/src/test/java/org/apache/log4j/config/PropertiesRollingWithPropertiesTest.java
@@ -18,13 +18,16 @@ package org.apache.log4j.config;
import static org.junit.Assert.assertTrue;
-import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.logging.log4j.core.test.SystemPropertyTestRule;
import org.junit.ClassRule;
import org.junit.Test;
+import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
/**
@@ -32,16 +35,23 @@ import org.junit.rules.TestRule;
*/
public class PropertiesRollingWithPropertiesTest {
+ private static final String TEST_DIR = "target/" + PropertiesRollingWithPropertiesTest.class.getSimpleName();
+
@ClassRule
- public static TestRule SP_RULE = SystemPropertyTestRule.create("log4j.configuration", "target/test-classes/log4j1-rolling-properties.properties");
+ public static TestRule SP_RULE = RuleChain.emptyRuleChain()
+ //@formatter:off
+ .around(SystemPropertyTestRule.create("test.directory", TEST_DIR))
+ .around(SystemPropertyTestRule.create("log4j.configuration", "target/test-classes/log4j1-rolling-properties.properties"));
+ //@formatter:on
@Test
public void testProperties() throws Exception {
- Logger logger = LogManager.getLogger("test");
+ final Logger logger = LogManager.getLogger("test");
logger.debug("This is a test of the root logger");
- File file = new File("target/rolling/somefile.log");
- assertTrue("Log file was not created", file.exists());
- assertTrue("Log file is empty", file.length() > 0);
+ final Path path = Paths.get(TEST_DIR, "somefile.log");
+ assertTrue("Log file was not created", Files.exists(path));
+ assertTrue("Log file is empty", Files.size(path) > 0);
+
}
}
diff --git a/log4j-1.2-api/src/test/resources/log4j1-rolling-properties.properties b/log4j-1.2-api/src/test/resources/log4j1-rolling-properties.properties
index 4ce0e43..41d8453 100644
--- a/log4j-1.2-api/src/test/resources/log4j1-rolling-properties.properties
+++ b/log4j-1.2-api/src/test/resources/log4j1-rolling-properties.properties
@@ -16,7 +16,7 @@
log4j.debug=true
# Properties for substitution
-somelogfile=target/rolling/somefile.log
+somelogfile=somefile.log
maxfilesize=256MB
maxbackupindex=20
@@ -24,7 +24,7 @@ log4j.rootLogger=TRACE, RFA
# Appender configuration with variables
log4j.appender.RFA=org.apache.log4j.RollingFileAppender
-log4j.appender.RFA.File=${somelogfile}
+log4j.appender.RFA.File=${test.directory}/${somelogfile}
log4j.appender.RFA.MaxFileSize=${maxfilesize}
log4j.appender.RFA.MaxBackupIndex=${maxbackupindex}
log4j.appender.RFA.layout=org.apache.log4j.PatternLayout