ceki 02/02/18 07:17:24 Added: tests build.properties.sample build.xml tests/input/xml DOMTestCase1.xml tests/src/java/org/apache/log4j Last.java tests/src/java/org/apache/log4j/util Compare.java ControlFilter.java Filter.java ISO8601Filter.java LineNumberFilter.java Transformer.java UnexpectedFormatException.java tests/src/java/org/apache/log4j/xml DOMTestCase.java tests/witness dom.A1.1 dom.A2.1 Log: Moving tests from mixed java/perl structure to pure java. Revision Changes Path 1.1 jakarta-log4j/tests/build.properties.sample Index: build.properties.sample =================================================================== jakarta.oro.jar=../../jakarta-oro-2.0.5/jakarta-oro-2.0.5.jar deprecation=on 1.1 jakarta-log4j/tests/build.xml Index: build.xml =================================================================== <!-- This file is an ANT build script. ANT is a Java based build tool. --> <!-- It is availale from http://jakarta.apache.org/ant/ --> <!-- ================================================================= --> <!-- NOTE: all directories are relative to jakarta-log4j/tests --> <!-- ================================================================= --> <project name="log4j" default="usage" basedir="." > <property file="build.properties"/> <!-- Read the system environment variables and stores them in properties, --> <!-- prefixed with "env". --> <property environment="env"/> <!-- The base directory relative to which most targets are built --> <property name="base" value="."/> <!-- The directory where source files are stored. --> <property name="project.source.home" value="../src/java/"/> <property name="project.classes.home" value="../dist/classes/"/> <property name="tests.source.home" value="./src/java/"/> <path id="tests.classpath"> <pathelement location="${project.source.home}"/> <pathelement location="${project.classes.home}"/> <pathelement location="${tests.source.home}"/> <pathelement location="./classes"/> <pathelement location="${jakarta.oro.jar}"/> </path> <!-- ================================================================= --> <!-- TARGETS --> <!-- ================================================================= --> <!-- ================================================================= --> <!-- Default target --> <!-- ================================================================= --> <target name="usage"> <echo> These are the targets supported by this ANT build scpript: build - compile all project files, if a certain library is missing, then the compilation of its dependents are skipped. run - run the tests </echo> </target> <target name="prepare"> <mkdir dir="./classes" /> <mkdir dir="./output" /> </target> <!-- ================================================================= --> <!-- Compile test cases and related source files. --> <!-- ================================================================= --> <target name="build" depends="prepare"> <javac srcdir="${tests.source.home}" destdir="./classes" deprecation="${deprecation}" debug="on"> <classpath refid="tests.classpath"/> </javac> </target> <!-- ================================================================= --> <!-- Remove all generated (compiled) class files. --> <!-- ================================================================= --> <target name="clean"> <delete dir="${./classes}/" /> </target> <target name="run" depends="DOM"/> <target name="last" depends="build"> <junit printsummary="yes" fork="yes" haltonfailure="yes"> <classpath refid="tests.classpath"/> <formatter type="plain" /> <test name="org.apache.log4j.Last" /> </junit> </target> <target name="DOM" depends="build"> <junit printsummary="yes" fork="yes" haltonfailure="yes"> <classpath refid="tests.classpath"/> <formatter type="plain" /> <test name="org.apache.log4j.xml.DOMTestCase" /> </junit> </target> </project> 1.1 jakarta-log4j/tests/input/xml/DOMTestCase1.xml Index: DOMTestCase1.xml =================================================================== <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <appender name="A1" class="org.apache.log4j.FileAppender"> <param name="File" value="output/temp.A1" /> <param name="Append" value="false" /> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%-5p %c{2} - %m%n"/> </layout> </appender> <appender name="A2" class="org.apache.log4j.FileAppender"> <param name="File" value="output/temp.A2" /> <param name="Append" value="false" /> <layout class="org.apache.log4j.TTCCLayout"> <param name="DateFormat" value="ISO8601" /> </layout> </appender> <logger name="org.apache.log4j.xml"> <level value="debug" /> <appender-ref ref="A1" /> </logger> <root> <priority value ="debug" /> <appender-ref ref="A1" /> <appender-ref ref="A2" /> </root> </log4j:configuration> 1.1 jakarta-log4j/tests/src/java/org/apache/log4j/Last.java Index: Last.java =================================================================== package org.apache.log4j; import junit.framework.TestCase; import junit.framework.TestSuite; import junit.framework.Test; public class Last extends TestCase { public Last(String name) { super(name); } public void test1() { } public static Test suite() { TestSuite suite = new TestSuite(); suite.addTest(new Last("test1")); return suite; } } 1.1 jakarta-log4j/tests/src/java/org/apache/log4j/util/Compare.java Index: Compare.java =================================================================== package org.apache.log4j.util; import java.io.InputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; public class Compare { static public boolean compare(String file1, String file2) throws FileNotFoundException, IOException { InputStream in1 = new FileInputStream(file1); InputStream in2 = new FileInputStream(file2); int b1; while((b1 = in1.read()) != -1) { int b2 = in2.read(); if(b2 != b1) { return false; } } return true; } } 1.1 jakarta-log4j/tests/src/java/org/apache/log4j/util/ControlFilter.java Index: ControlFilter.java =================================================================== package org.apache.log4j.util; import java.io.*; import org.apache.oro.text.perl.Perl5Util; public class ControlFilter implements Filter { Perl5Util util = new Perl5Util(); String[] allowedPatterns; public ControlFilter(String[] allowedPatterns) { this.allowedPatterns = allowedPatterns; } public String filter(String in) throws UnexpectedFormatException{ int len = allowedPatterns.length; for(int i = 0; i < len; i++) { if(util.match("/"+allowedPatterns[i]+"/", in)) { return in; } } throw new UnexpectedFormatException(in); } } 1.1 jakarta-log4j/tests/src/java/org/apache/log4j/util/Filter.java Index: Filter.java =================================================================== package org.apache.log4j.util; public interface Filter { final String BASIC_PAT = "\\[main\\] (FATAL|ERROR|WARN|INFO|DEBUG)"; final String ISO8601_PAT = "^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2},\\d{3} "; String filter(String in) throws UnexpectedFormatException; } 1.1 jakarta-log4j/tests/src/java/org/apache/log4j/util/ISO8601Filter.java Index: ISO8601Filter.java =================================================================== package org.apache.log4j.util; import java.io.*; import org.apache.oro.text.perl.Perl5Util; public class ISO8601Filter implements Filter { Perl5Util util = new Perl5Util(); public String filter(String in) { String pat = "/"+ISO8601_PAT +"/"; if(util.match(pat, in)) { return util.substitute("s/"+ISO8601_PAT+"//", in); } else { return in; } } } 1.1 jakarta-log4j/tests/src/java/org/apache/log4j/util/LineNumberFilter.java Index: LineNumberFilter.java =================================================================== package org.apache.log4j.util; import java.io.*; import org.apache.oro.text.perl.Perl5Util; public class LineNumberFilter implements Filter { Perl5Util util = new Perl5Util(); public String filter(String in) { if(util.match("/\\(.*:\\d{1,4}\\)/", in)) { return util.substitute("s/:\\d{1,4}\\)/:XXX)/", in); } else { return in; } } } 1.1 jakarta-log4j/tests/src/java/org/apache/log4j/util/Transformer.java Index: Transformer.java =================================================================== package org.apache.log4j.util; import java.io.*; import org.apache.oro.text.perl.Perl5Util; public class Transformer { public static void transform(String in, String out, Filter[] filters) throws FileNotFoundException, IOException, UnexpectedFormatException { Perl5Util util = new Perl5Util(); String line; BufferedReader input = new BufferedReader(new FileReader(in)); PrintStream output = new PrintStream(new FileOutputStream(out)); // Initialization of input and output omitted while((line = input.readLine()) != null) { // apply all filters for(int i = 0; i < filters.length; i++) { line = filters[i].filter(line); } output.println(line); } } public static void transform(String in, String out, Filter filter) throws FileNotFoundException, IOException, UnexpectedFormatException { Perl5Util util = new Perl5Util(); String line; BufferedReader input = new BufferedReader(new FileReader(in)); PrintStream output = new PrintStream(new FileOutputStream(out)); // Initialization of input and output omitted while((line = input.readLine()) != null) { // apply all filters line = filter.filter(line); output.println(line); } } } 1.1 jakarta-log4j/tests/src/java/org/apache/log4j/util/UnexpectedFormatException.java Index: UnexpectedFormatException.java =================================================================== package org.apache.log4j.util; public class UnexpectedFormatException extends Exception { public UnexpectedFormatException(String msg) { super(msg); } } 1.1 jakarta-log4j/tests/src/java/org/apache/log4j/xml/DOMTestCase.java Index: DOMTestCase.java =================================================================== package org.apache.log4j.xml; import junit.framework.TestCase; import junit.framework.TestSuite; import junit.framework.Test; import org.apache.log4j.Logger; import org.apache.log4j.Level; import org.apache.log4j.util.Filter; import org.apache.log4j.util.LineNumberFilter; import org.apache.log4j.util.ControlFilter; import org.apache.log4j.util.ISO8601Filter; import org.apache.log4j.util.Transformer; import org.apache.log4j.util.Compare; public class DOMTestCase extends TestCase { static String TEMP_A1 = "output/temp.A1"; static String TEMP_A2 = "output/temp.A2"; static String FILTERED_A1 = "output/filtered.A1"; static String FILTERED_A2 = "output/filtered.A2"; static String EXCEPTION1 = "java.lang.Exception: Just testing"; static String EXCEPTION2 = "\\s*at .*\\(.*:\\d{1,4}\\)"; static String EXCEPTION3 = "\\s*at .*\\(Native Method\\)"; static String TEST1_1A_PAT = "(DEBUG|INFO |WARN |ERROR|FATAL) \\w*\\.\\w* - Message \\d"; static String TEST1_1B_PAT = "(DEBUG|INFO |WARN |ERROR|FATAL) root - Message \\d"; static String TEST1_2_PAT = "^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2},\\d{3} "+ "\\[main]\\ (DEBUG|INFO|WARN|ERROR|FATAL) .* - Message \\d"; Logger root; Logger logger; public DOMTestCase(String name) { super(name); } public void setUp() { System.out.println("===================SETUP======================"); root = Logger.getRootLogger(); logger = Logger.getLogger(DOMTestCase.class); } public void test1() throws Exception { DOMConfigurator.configure("input/xml/DOMTestCase1.xml"); common(); ControlFilter cf1 = new ControlFilter(new String[]{TEST1_1A_PAT, TEST1_1B_PAT, EXCEPTION1, EXCEPTION2, EXCEPTION3}); ControlFilter cf2 = new ControlFilter(new String[]{TEST1_2_PAT, EXCEPTION1, EXCEPTION2, EXCEPTION3}); Transformer.transform(TEMP_A1, FILTERED_A1, new Filter[] {cf1, new LineNumberFilter()}); Transformer.transform(TEMP_A2, FILTERED_A2, new Filter[] {cf2, new LineNumberFilter(), new ISO8601Filter()}); assert(Compare.compare(FILTERED_A1, "witness/dom.A1.1")); assert(Compare.compare(FILTERED_A2, "witness/dom.A2.1")); } void common() { int i = -1; logger.debug("Message " + ++i); root.debug("Message " + i); logger.info ("Message " + ++i); root.info("Message " + i); logger.warn ("Message " + ++i); root.warn("Message " + i); logger.error("Message " + ++i); root.error("Message " + i); logger.log(Level.FATAL, "Message " + ++i); root.log(Level.FATAL, "Message " + i); Exception e = new Exception("Just testing"); logger.debug("Message " + ++i, e); root.debug("Message " + i, e); logger.error("Message " + ++i, e); root.error("Message " + i, e); } public static Test suite() { TestSuite suite = new TestSuite(); suite.addTest(new DOMTestCase("test1")); return suite; } } 1.1 jakarta-log4j/tests/witness/dom.A1.1 Index: dom.A1.1 =================================================================== DEBUG xml.DOMTestCase - Message 0 DEBUG xml.DOMTestCase - Message 0 DEBUG root - Message 0 INFO xml.DOMTestCase - Message 1 INFO xml.DOMTestCase - Message 1 INFO root - Message 1 WARN xml.DOMTestCase - Message 2 WARN xml.DOMTestCase - Message 2 WARN root - Message 2 ERROR xml.DOMTestCase - Message 3 ERROR xml.DOMTestCase - Message 3 ERROR root - Message 3 FATAL xml.DOMTestCase - Message 4 FATAL xml.DOMTestCase - Message 4 FATAL root - Message 4 DEBUG xml.DOMTestCase - Message 5 java.lang.Exception: Just testing at org.apache.log4j.xml.DOMTestCase.common(DOMTestCase.java:XXX) at org.apache.log4j.xml.DOMTestCase.test1(DOMTestCase.java:XXX) at java.lang.reflect.Method.invoke(Native Method) at junit.framework.TestCase.runTest(TestCase.java:XXX) at junit.framework.TestCase.runBare(TestCase.java:XXX) at junit.framework.TestResult$1.protect(TestResult.java:XXX) at junit.framework.TestResult.runProtected(TestResult.java:XXX) at junit.framework.TestResult.run(TestResult.java:XXX) at junit.framework.TestCase.run(TestCase.java:XXX) at junit.framework.TestSuite.run(TestSuite.java:XXX) at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:XXX) at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:XXX) DEBUG xml.DOMTestCase - Message 5 java.lang.Exception: Just testing at org.apache.log4j.xml.DOMTestCase.common(DOMTestCase.java:XXX) at org.apache.log4j.xml.DOMTestCase.test1(DOMTestCase.java:XXX) at java.lang.reflect.Method.invoke(Native Method) at junit.framework.TestCase.runTest(TestCase.java:XXX) at junit.framework.TestCase.runBare(TestCase.java:XXX) at junit.framework.TestResult$1.protect(TestResult.java:XXX) at junit.framework.TestResult.runProtected(TestResult.java:XXX) at junit.framework.TestResult.run(TestResult.java:XXX) at junit.framework.TestCase.run(TestCase.java:XXX) at junit.framework.TestSuite.run(TestSuite.java:XXX) at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:XXX) at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:XXX) DEBUG root - Message 5 java.lang.Exception: Just testing at org.apache.log4j.xml.DOMTestCase.common(DOMTestCase.java:XXX) at org.apache.log4j.xml.DOMTestCase.test1(DOMTestCase.java:XXX) at java.lang.reflect.Method.invoke(Native Method) at junit.framework.TestCase.runTest(TestCase.java:XXX) at junit.framework.TestCase.runBare(TestCase.java:XXX) at junit.framework.TestResult$1.protect(TestResult.java:XXX) at junit.framework.TestResult.runProtected(TestResult.java:XXX) at junit.framework.TestResult.run(TestResult.java:XXX) at junit.framework.TestCase.run(TestCase.java:XXX) at junit.framework.TestSuite.run(TestSuite.java:XXX) at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:XXX) at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:XXX) ERROR xml.DOMTestCase - Message 6 java.lang.Exception: Just testing at org.apache.log4j.xml.DOMTestCase.common(DOMTestCase.java:XXX) at org.apache.log4j.xml.DOMTestCase.test1(DOMTestCase.java:XXX) at java.lang.reflect.Method.invoke(Native Method) at junit.framework.TestCase.runTest(TestCase.java:XXX) at junit.framework.TestCase.runBare(TestCase.java:XXX) at junit.framework.TestResult$1.protect(TestResult.java:XXX) at junit.framework.TestResult.runProtected(TestResult.java:XXX) at junit.framework.TestResult.run(TestResult.java:XXX) at junit.framework.TestCase.run(TestCase.java:XXX) at junit.framework.TestSuite.run(TestSuite.java:XXX) at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:XXX) at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:XXX) ERROR xml.DOMTestCase - Message 6 java.lang.Exception: Just testing at org.apache.log4j.xml.DOMTestCase.common(DOMTestCase.java:XXX) at org.apache.log4j.xml.DOMTestCase.test1(DOMTestCase.java:XXX) at java.lang.reflect.Method.invoke(Native Method) at junit.framework.TestCase.runTest(TestCase.java:XXX) at junit.framework.TestCase.runBare(TestCase.java:XXX) at junit.framework.TestResult$1.protect(TestResult.java:XXX) at junit.framework.TestResult.runProtected(TestResult.java:XXX) at junit.framework.TestResult.run(TestResult.java:XXX) at junit.framework.TestCase.run(TestCase.java:XXX) at junit.framework.TestSuite.run(TestSuite.java:XXX) at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:XXX) at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:XXX) ERROR root - Message 6 java.lang.Exception: Just testing at org.apache.log4j.xml.DOMTestCase.common(DOMTestCase.java:XXX) at org.apache.log4j.xml.DOMTestCase.test1(DOMTestCase.java:XXX) at java.lang.reflect.Method.invoke(Native Method) at junit.framework.TestCase.runTest(TestCase.java:XXX) at junit.framework.TestCase.runBare(TestCase.java:XXX) at junit.framework.TestResult$1.protect(TestResult.java:XXX) at junit.framework.TestResult.runProtected(TestResult.java:XXX) at junit.framework.TestResult.run(TestResult.java:XXX) at junit.framework.TestCase.run(TestCase.java:XXX) at junit.framework.TestSuite.run(TestSuite.java:XXX) at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:XXX) at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:XXX) 1.1 jakarta-log4j/tests/witness/dom.A2.1 Index: dom.A2.1 =================================================================== [main] DEBUG org.apache.log4j.xml.DOMTestCase - Message 0 [main] DEBUG root - Message 0 [main] INFO org.apache.log4j.xml.DOMTestCase - Message 1 [main] INFO root - Message 1 [main] WARN org.apache.log4j.xml.DOMTestCase - Message 2 [main] WARN root - Message 2 [main] ERROR org.apache.log4j.xml.DOMTestCase - Message 3 [main] ERROR root - Message 3 [main] FATAL org.apache.log4j.xml.DOMTestCase - Message 4 [main] FATAL root - Message 4 [main] DEBUG org.apache.log4j.xml.DOMTestCase - Message 5 java.lang.Exception: Just testing at org.apache.log4j.xml.DOMTestCase.common(DOMTestCase.java:XXX) at org.apache.log4j.xml.DOMTestCase.test1(DOMTestCase.java:XXX) at java.lang.reflect.Method.invoke(Native Method) at junit.framework.TestCase.runTest(TestCase.java:XXX) at junit.framework.TestCase.runBare(TestCase.java:XXX) at junit.framework.TestResult$1.protect(TestResult.java:XXX) at junit.framework.TestResult.runProtected(TestResult.java:XXX) at junit.framework.TestResult.run(TestResult.java:XXX) at junit.framework.TestCase.run(TestCase.java:XXX) at junit.framework.TestSuite.run(TestSuite.java:XXX) at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:XXX) at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:XXX) [main] DEBUG root - Message 5 java.lang.Exception: Just testing at org.apache.log4j.xml.DOMTestCase.common(DOMTestCase.java:XXX) at org.apache.log4j.xml.DOMTestCase.test1(DOMTestCase.java:XXX) at java.lang.reflect.Method.invoke(Native Method) at junit.framework.TestCase.runTest(TestCase.java:XXX) at junit.framework.TestCase.runBare(TestCase.java:XXX) at junit.framework.TestResult$1.protect(TestResult.java:XXX) at junit.framework.TestResult.runProtected(TestResult.java:XXX) at junit.framework.TestResult.run(TestResult.java:XXX) at junit.framework.TestCase.run(TestCase.java:XXX) at junit.framework.TestSuite.run(TestSuite.java:XXX) at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:XXX) at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:XXX) [main] ERROR org.apache.log4j.xml.DOMTestCase - Message 6 java.lang.Exception: Just testing at org.apache.log4j.xml.DOMTestCase.common(DOMTestCase.java:XXX) at org.apache.log4j.xml.DOMTestCase.test1(DOMTestCase.java:XXX) at java.lang.reflect.Method.invoke(Native Method) at junit.framework.TestCase.runTest(TestCase.java:XXX) at junit.framework.TestCase.runBare(TestCase.java:XXX) at junit.framework.TestResult$1.protect(TestResult.java:XXX) at junit.framework.TestResult.runProtected(TestResult.java:XXX) at junit.framework.TestResult.run(TestResult.java:XXX) at junit.framework.TestCase.run(TestCase.java:XXX) at junit.framework.TestSuite.run(TestSuite.java:XXX) at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:XXX) at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:XXX) [main] ERROR root - Message 6 java.lang.Exception: Just testing at org.apache.log4j.xml.DOMTestCase.common(DOMTestCase.java:XXX) at org.apache.log4j.xml.DOMTestCase.test1(DOMTestCase.java:XXX) at java.lang.reflect.Method.invoke(Native Method) at junit.framework.TestCase.runTest(TestCase.java:XXX) at junit.framework.TestCase.runBare(TestCase.java:XXX) at junit.framework.TestResult$1.protect(TestResult.java:XXX) at junit.framework.TestResult.runProtected(TestResult.java:XXX) at junit.framework.TestResult.run(TestResult.java:XXX) at junit.framework.TestCase.run(TestCase.java:XXX) at junit.framework.TestSuite.run(TestSuite.java:XXX) at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:XXX) at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:XXX)
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>