"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "log4j-core/src/test/java/org/apache/logging/log4j/core/appender/XmlCompleteFileAppenderTest.java" between
apache-log4j-2.11.1-src.tar.gz and apache-log4j-2.11.2-src.tar.gz

About: Apache Log4j 2 is a logging library for Java. Source distribution (Java).

XmlCompleteFileAppenderTest.java  (apache-log4j-2.11.1-src):XmlCompleteFileAppenderTest.java  (apache-log4j-2.11.2-src)
skipping to change at line 24 skipping to change at line 24
* See the license for the specific language governing permissions and * See the license for the specific language governing permissions and
* limitations under the license. * limitations under the license.
*/ */
package org.apache.logging.log4j.core.appender; package org.apache.logging.log4j.core.appender;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List; import java.util.List;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.categories.Layouts; import org.apache.logging.log4j.categories.Layouts;
import org.apache.logging.log4j.core.CoreLoggerContexts; import org.apache.logging.log4j.core.CoreLoggerContexts;
import org.apache.logging.log4j.core.selector.ContextSelector; import org.apache.logging.log4j.core.selector.ContextSelector;
import org.apache.logging.log4j.core.selector.CoreContextSelectors; import org.apache.logging.log4j.core.selector.CoreContextSelectors;
import org.apache.logging.log4j.junit.CleanFiles; import org.apache.logging.log4j.junit.CleanFiles;
import org.apache.logging.log4j.junit.LoggerContextRule; import org.apache.logging.log4j.junit.LoggerContextRule;
import org.junit.Rule; import org.junit.Rule;
skipping to change at line 144 skipping to change at line 143
*/ */
@Test @Test
public void testChildElementsAreCorrectlyIndented() throws Exception { public void testChildElementsAreCorrectlyIndented() throws Exception {
final Logger logger = this.loggerContextRule.getLogger("com.foo.Bar"); final Logger logger = this.loggerContextRule.getLogger("com.foo.Bar");
final String firstLogMsg = "First Msg tag must be in level 2 after corre ct indentation"; final String firstLogMsg = "First Msg tag must be in level 2 after corre ct indentation";
logger.info(firstLogMsg); logger.info(firstLogMsg);
final String secondLogMsg = "Second Msg tag must also be in level 2 afte r correct indentation"; final String secondLogMsg = "Second Msg tag must also be in level 2 afte r correct indentation";
logger.info(secondLogMsg); logger.info(secondLogMsg);
CoreLoggerContexts.stopLoggerContext(false, logFile); // stop async thre ad CoreLoggerContexts.stopLoggerContext(false, logFile); // stop async thre ad
int[] indentations = { final int[] indentations = {
0, //"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" 0, //"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
0, //"<Events xmlns=\"http://logging.apache.org/log4j/2.0/events \">\n" 0, //"<Events xmlns=\"http://logging.apache.org/log4j/2.0/events \">\n"
-1, // empty -1, // empty
2, //" <Event xmlns=\"http://logging.apache.org/log4j/2.0/event s\" thread=\"main\" level=\"INFO\" loggerName=\"com.foo.Bar\" endOfBatch=\"true\ " loggerFqcn=\"org.apache.logging.log4j.spi.AbstractLogger\" threadId=\"12\" thr eadPriority=\"5\">\n" 2, //" <Event xmlns=\"http://logging.apache.org/log4j/2.0/event s\" thread=\"main\" level=\"INFO\" loggerName=\"com.foo.Bar\" endOfBatch=\"true\ " loggerFqcn=\"org.apache.logging.log4j.spi.AbstractLogger\" threadId=\"12\" thr eadPriority=\"5\">\n"
4, //" <Instant epochSecond=\"1515889414\" nanoOfSecond=\"144 000000\" epochMillisecond=\"1515889414144\" nanoOfMillisecond=\"0\"/>\n" 4, //" <Instant epochSecond=\"1515889414\" nanoOfSecond=\"144 000000\" epochMillisecond=\"1515889414144\" nanoOfMillisecond=\"0\"/>\n"
4, //" <Message>First Msg tag must be in level 2 after correc t indentation</Message>\n" + 4, //" <Message>First Msg tag must be in level 2 after correc t indentation</Message>\n" +
2, //" </Event>\n" 2, //" </Event>\n"
-1, // empty -1, // empty
2, //" <Event xmlns=\"http://logging.apache.org/log4j/2.0/event s\" thread=\"main\" level=\"INFO\" loggerName=\"com.foo.Bar\" endOfBatch=\"true\ " loggerFqcn=\"org.apache.logging.log4j.spi.AbstractLogger\" threadId=\"12\" thr eadPriority=\"5\">\n" + 2, //" <Event xmlns=\"http://logging.apache.org/log4j/2.0/event s\" thread=\"main\" level=\"INFO\" loggerName=\"com.foo.Bar\" endOfBatch=\"true\ " loggerFqcn=\"org.apache.logging.log4j.spi.AbstractLogger\" threadId=\"12\" thr eadPriority=\"5\">\n" +
4, //" <Instant epochSecond=\"1515889414\" nanoOfSecond=\"144 000000\" epochMillisecond=\"1515889414144\" nanoOfMillisecond=\"0\"/>\n" + 4, //" <Instant epochSecond=\"1515889414\" nanoOfSecond=\"144 000000\" epochMillisecond=\"1515889414144\" nanoOfMillisecond=\"0\"/>\n" +
4, //" <Message>Second Msg tag must also be in level 2 after correct indentation</Message>\n" + 4, //" <Message>Second Msg tag must also be in level 2 after correct indentation</Message>\n" +
2, //" </Event>\n" + 2, //" </Event>\n" +
0, //"</Events>\n"; 0, //"</Events>\n";
}; };
List<String> lines1 = Files.readAllLines(logFile.toPath(), Charset.forNa me("UTF-8")); final List<String> lines1 = Files.readAllLines(logFile.toPath(), Charset .forName("UTF-8"));
assertEquals("number of lines", indentations.length, lines1.size()); assertEquals("number of lines", indentations.length, lines1.size());
for (int i = 0; i < indentations.length; i++) { for (int i = 0; i < indentations.length; i++) {
String line = lines1.get(i); final String line = lines1.get(i);
if (line.trim().isEmpty()) { if (line.trim().isEmpty()) {
assertEquals(-1, indentations[i]); assertEquals(-1, indentations[i]);
} else { } else {
String padding = " ".substring(0, indentations[i]); final String padding = " ".substring(0, indentations[i]);
assertTrue("Expected " + indentations[i] + " leading spaces but got: " + line, line.startsWith(padding)); assertTrue("Expected " + indentations[i] + " leading spaces but got: " + line, line.startsWith(padding));
} }
} }
} }
} }
 End of changes. 5 change blocks. 
5 lines changed or deleted 4 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)