logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mattsic...@apache.org
Subject svn commit: r1582184 - /logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/
Date Thu, 27 Mar 2014 04:59:04 GMT
Author: mattsicker
Date: Thu Mar 27 04:59:04 2014
New Revision: 1582184

URL: http://svn.apache.org/r1582184
Log:
Combine random access appender tests.

  - Gotta love it when you can do that!

Added:
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppenderTests.java
  (with props)
Removed:
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppenderLocationTest.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppenderTest.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RollingRandomAccessFileAppenderLocationTest.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RollingRandomAccessFileAppenderTest.java

Added: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppenderTests.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppenderTests.java?rev=1582184&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppenderTests.java
(added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppenderTests.java
Thu Mar 27 04:59:04 2014
@@ -0,0 +1,78 @@
+package org.apache.logging.log4j.core.appender;
+
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.junit.CleanFiles;
+import org.apache.logging.log4j.junit.InitialLoggerContext;
+import org.hamcrest.Matcher;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.util.Arrays;
+import java.util.Collection;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.not;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Simple tests for both the RandomAccessFileAppender and RollingRandomAccessFileAppender.
+ */
+@RunWith(Parameterized.class)
+public class RandomAccessFileAppenderTests {
+
+    @Parameterized.Parameters
+    public static Collection<Object[]> data() {
+        return Arrays.asList(
+                new Object[][]{
+                        { "RandomAccessFileAppenderTest", false },
+                        { "RandomAccessFileAppenderLocationTest", true },
+                        { "RollingRandomAccessFileAppenderTest", false },
+                        { "RollingRandomAccessFileAppenderLocationTest", true }
+                }
+        );
+    }
+
+    @Rule
+    public InitialLoggerContext init;
+
+    @Rule
+    public CleanFiles files;
+
+    private final File logFile;
+    private final boolean locationEnabled;
+
+    public RandomAccessFileAppenderTests(final String testName, final boolean locationEnabled)
{
+        this.init = new InitialLoggerContext(testName + ".xml");
+        this.logFile = new File("target", testName + ".log");
+        this.files = new CleanFiles(this.logFile);
+        this.locationEnabled = locationEnabled;
+    }
+
+    @Test
+    public void testRandomAccessConfiguration() throws Exception {
+        final Logger logger = this.init.getLogger("com.foo.Bar");
+        final String message = "This is a test log message brought to you by Slurm.";
+        logger.info(message);
+        this.init.getContext().stop(); // stop async thread
+
+        String line;
+        final BufferedReader reader = new BufferedReader(new FileReader(this.logFile));
+        try {
+            line = reader.readLine();
+        } finally {
+            reader.close();
+        }
+        assertNotNull(line);
+        assertThat(line, containsString(message));
+        final Matcher<String> containsLocationInformation = containsString("testRandomAccessConfiguration");
+        final Matcher<String> usesLocationInformationAsConfigured = this.locationEnabled
?
+                containsLocationInformation : not(containsLocationInformation);
+        assertThat(line, usesLocationInformationAsConfigured);
+    }
+}

Propchange: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppenderTests.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message