You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-cvs@jakarta.apache.org by ce...@apache.org on 2002/02/18 18:36:37 UTC

cvs commit: jakarta-log4j/tests/witness customLevel.1

ceki        02/02/18 09:36:37

  Modified:    .        build.xml
               examples/subclass MyLogger.java MyLoggerTest.java
               src/java/org/apache/log4j/helpers OptionConverter.java
               src/java/org/apache/log4j/test unitTest
               src/java/org/apache/log4j/varia LevelMatchFilter.java
               tests    build.xml
  Added:       tests/input/xml customLevel1.xml
               tests/src/java/org/apache/log4j/helpers
                        OptionConverterTestCase.java
               tests/witness customLevel.1
  Removed:     src/java/org/apache/log4j/test SocketAppenderTest.java
               src/java/org/apache/log4j/varia PriorityMatchFilter.java
                        PriorityRangeFilter.java
  Log:
  Moving tests around.
  
  Revision  Changes    Path
  1.19      +8 -3      jakarta-log4j/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/build.xml,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- build.xml	11 Feb 2002 22:20:30 -0000	1.18
  +++ build.xml	18 Feb 2002 17:36:36 -0000	1.19
  @@ -59,6 +59,11 @@
     <!-- Directory for temporary files. -->
     <property name="dist.tmp" value="dist/tmp"/>
   
  +
  +
  +  <!-- ================================================================= -->
  +  <!-- Default target                                                    -->
  +  <!-- ================================================================= -->
     
     <target name="usage">
       <echo>
  @@ -130,13 +135,13 @@
     <!-- ================================================================= -->
     <target name="init">
       <tstamp />
  +    <mkdir dir="${javac.dest}" />
     </target>
   
  -  <target name="build" depends="init, build.core, build.examples, build.xml, build.unitTests, 
  -                                build.javamail, build.jms, build.jmx"/>
  +  <target name="build" depends="init, build.core, build.examples, build.xml, 
  +                                build.unitTests, build.javamail, build.jms, build.jmx"/>
   
     <target name="build.core" depends="init">
  -    <mkdir dir="${javac.dest}" />
       <javac srcdir="${java.source.dir}"
   	   destdir="${javac.dest}"
   	   includes="${stem}/**/*.java, ${stem}/xml/XMLLayout.java,"
  
  
  
  1.3       +1 -1      jakarta-log4j/examples/subclass/MyLogger.java
  
  Index: MyLogger.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/examples/subclass/MyLogger.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MyLogger.java	11 Feb 2002 16:14:33 -0000	1.2
  +++ MyLogger.java	18 Feb 2002 17:36:36 -0000	1.3
  @@ -10,7 +10,7 @@
   import org.apache.log4j.*;
   import org.apache.log4j.spi.LoggerFactory;
   import org.apache.log4j.xml.DOMConfigurator;
  -import org.apache.log4j.xml.examples.XLevel;
  +import examples.customLevel.XLevel;
   import org.apache.log4j.PropertyConfigurator;
   import org.apache.log4j.helpers.LogLog;
   
  
  
  
  1.3       +1 -1      jakarta-log4j/examples/subclass/MyLoggerTest.java
  
  Index: MyLoggerTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/examples/subclass/MyLoggerTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MyLoggerTest.java	11 Feb 2002 16:14:33 -0000	1.2
  +++ MyLoggerTest.java	18 Feb 2002 17:36:36 -0000	1.3
  @@ -10,7 +10,7 @@
   import org.apache.log4j.*;
   import org.apache.log4j.spi.LoggerFactory;
   import org.apache.log4j.xml.DOMConfigurator;
  -import org.apache.log4j.xml.examples.XLevel;
  +import examples.customLevel.XLevel;
   import org.apache.log4j.PropertyConfigurator;
   import org.apache.log4j.helpers.LogLog;
   
  
  
  
  1.32      +1 -1      jakarta-log4j/src/java/org/apache/log4j/helpers/OptionConverter.java
  
  Index: OptionConverter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/helpers/OptionConverter.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- OptionConverter.java	11 Feb 2002 16:14:33 -0000	1.31
  +++ OptionConverter.java	18 Feb 2002 17:36:36 -0000	1.32
  @@ -208,7 +208,7 @@
         // get a ref to the specified class' static method
         // toLevel(String, org.apache.log4j.Level)
         Class[] paramTypes = new Class[] { String.class,
  -					 org.apache.log4j.Priority.class
  +					 org.apache.log4j.Level.class
                                          };
         java.lang.reflect.Method toLevelMethod =
                         customLevel.getMethod("toLevel", paramTypes);
  
  
  
  1.7       +0 -8      jakarta-log4j/src/java/org/apache/log4j/test/unitTest
  
  Index: unitTest
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/test/unitTest,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- unitTest	17 Apr 2001 19:59:34 -0000	1.6
  +++ unitTest	18 Feb 2002 17:36:36 -0000	1.7
  @@ -7,14 +7,6 @@
     exit 1   
   fi
   
  -java junit.textui.TestRunner org.apache.log4j.test.UnitTestOptionConverter
  -  
  -if [ $? != 0 ]; then
  -  echo "UnitTestOptionConverter failed."
  -  exit 1   
  -fi
  -
  -
   java junit.textui.TestRunner org.apache.log4j.test.UnitTestCyclicBuffer  
   if [ $? != 0 ]; then
     echo "UnitTestCyclicBuffer failed."
  
  
  
  1.2       +18 -54    jakarta-log4j/src/java/org/apache/log4j/varia/LevelMatchFilter.java
  
  Index: LevelMatchFilter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/varia/LevelMatchFilter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LevelMatchFilter.java	3 Sep 2001 22:37:30 -0000	1.1
  +++ LevelMatchFilter.java	18 Feb 2002 17:36:36 -0000	1.2
  @@ -26,14 +26,10 @@
      Filter#DENY} is returned. If there is no match, {@link
      Filter#NEUTRAL} is returned.
   
  -   <p>See configuration files <a
  -   href="../xml/doc-files/test11.xml">test11.xml</a> and <a
  -   href="../xml/doc-files/test12.xml">test12.xml</a> for an example of
  -   seeting up a <code>LevelMatchFilter</code>.
  -
      @author Ceki G&uuml;lc&uuml;
   
  -   @since 0.9.1 */
  +   @since 1.2
  +*/
   public class LevelMatchFilter extends Filter {
     
     /**
  @@ -59,31 +55,7 @@
      */
     Level levelToMatch;
   
  -  /**
  -     @deprecated We now use JavaBeans introspection to configure
  -     components.
  -  */
  -  public
  -  String[] getOptionStrings() {
  -    return new String[] {LEVEL_TO_MATCH_OPTION, ACCEPT_ON_MATCH_OPTION};
  -  }
  -
  -  /**
  -     @deprecated Use the setter method for the option directly instead
  -     of the generic <code>setOption</code> method. 
  -
  -     @deprecated We now use JavaBeans introspection to configure
  -     components. 
  -  */
  -  public
  -  void setOption(String key, String value) {    
  -    if(key.equalsIgnoreCase(LEVEL_TO_MATCH_OPTION)) {
  -      levelToMatch = OptionConverter.toLevel(value, null);
  -    } else if (key.equalsIgnoreCase(ACCEPT_ON_MATCH_OPTION)) {
  -      acceptOnMatch = OptionConverter.toBoolean(value, acceptOnMatch);
  -    }
  -  }
  -  
  + 
     public
     void setLevelToMatch(String level) {
       levelToMatch = OptionConverter.toLevel(level, null);
  @@ -108,25 +80,14 @@
     /**
        Return the decision of this filter.
   
  -     Returns {@link Filter#NEUTRAL} if the <b>LevelToMatch</b>
  -     option is not set.  Otherwise, the returned decision is defined
  -     according to the following table:
  -
  -     <p><table border=1>
  -     <tr><th rowspan="2" BGCOLOR="#AAAAFF">Did a level match occur?</th>
  -     	 <th colspan="2" BGCOLOR="#CCCCCC">AcceptOnMatch setting</th>
  -     
  -     <tr><td BGCOLOR="#CCCCCC" align="center">TRUE</td>
  -     	 <td BGCOLOR="#CCCCCC" align="center">FALSE</td>
  -     
  -     <tr><td BGCOLOR="#AAAAFF" align="center">TRUE</td>
  -     	 <td>{@link Filter#ACCEPT}</td><td>{@link Filter#DENY}</td>
  -     <tr><td BGCOLOR="#AAAAFF" align="center">FALSE</td>
  -     	 <td>{@link Filter#DENY}</td><td>{@link Filter#ACCEPT}</td>
  -     
  -     	 <caption align="bottom">Filter decision in function of whether a match
  -     	 occured and the AcceptOnMatch settings</caption> 
  -    </table> */
  +     Returns {@link Filter#NEUTRAL} if the <b>LevelToMatch</b> option
  +     is not set or if there is not match.  Otherwise, if there is a
  +     match, then the returned decision is {@link Filter#ACCEPT} if the
  +     <b>AcceptOnMatch</b> property is set to <code>true</code>. The
  +     returned decision is {@link Filter#DENY} if the
  +     <b>AcceptOnMatch</b> property is set to false.
  +
  +  */
     public
     int decide(LoggingEvent event) {
       if(this.levelToMatch == null) {
  @@ -136,12 +97,15 @@
       boolean matchOccured = false;
       if(this.levelToMatch == event.level) {
         matchOccured = true;
  -    }
  +    } 
   
  -    if(this.acceptOnMatch ^ matchOccured) {
  -      return Filter.DENY;
  +    if(matchOccured) {
  +      if(this.acceptOnMatch)
  +	  return Filter.ACCEPT;
  +      else
  +	  return Filter.DENY;
       } else {
  -      return Filter.ACCEPT;
  +      return Filter.NEUTRAL;
       }
     }
   }
  
  
  
  1.2       +26 -1     jakarta-log4j/tests/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/tests/build.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- build.xml	18 Feb 2002 15:17:23 -0000	1.1
  +++ build.xml	18 Feb 2002 17:36:36 -0000	1.2
  @@ -82,7 +82,7 @@
     </target>
   
     
  -  <target name="run" depends="DOM"/>
  +  <target name="run" depends="OptionConverter, BoundedFIFO, DOM, CustomLevel"/>
     
     <target name="last" depends="build">
       <junit printsummary="yes" fork="yes" haltonfailure="yes">
  @@ -92,11 +92,36 @@
       </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>
  +
  +  <target name="CustomLevel" depends="build">
  +    <junit printsummary="yes" fork="yes" haltonfailure="yes">
  +      <classpath refid="tests.classpath"/>
  +      <formatter type="plain" />
  +      <test name="org.apache.log4j.xml.CustomLevelTestCase" />
  +    </junit>
  +  </target>
  +
  +  <target name="OptionConverter" depends="build">
  +    <junit printsummary="yes" fork="yes" haltonfailure="yes">
  +      <classpath refid="tests.classpath"/>
  +      <formatter type="plain" />
  +      <test name="org.apache.log4j.helpers.OptionConverterTestCase" />
  +    </junit>
  +  </target>
  +
  +  <target name="BoundedFIFO" depends="build">
  +    <junit printsummary="yes" fork="yes" haltonfailure="yes">
  +      <classpath refid="tests.classpath"/>
  +      <formatter type="plain" />
  +      <test name="org.apache.log4j.helpers.BoundedFIFOTestCase" />
       </junit>
     </target>
   
  
  
  
  1.1                  jakarta-log4j/tests/input/xml/customLevel1.xml
  
  Index: customLevel1.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8" ?>
  <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
  
  <log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'
                       debug="true">
  
    <appender name="TEMP" class="org.apache.log4j.FileAppender">
      <param name="Append" value="false" />
      <param name="File"   value="output/temp" />
      <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern"
  	value="%-5p %c{2} - %m\n"/>
      </layout>
    </appender>
  
    <root>
      <level value="TRACE" class="org.apache.log4j.xml.XLevel"/>
      <appender-ref ref="TEMP" />
    </root>
  </log4j:configuration>
  
  
  1.1                  jakarta-log4j/tests/src/java/org/apache/log4j/helpers/OptionConverterTestCase.java
  
  Index: OptionConverterTestCase.java
  ===================================================================
  
  // Log4j uses the JUnit framework for internal unit testing. JUnit
  // is available from "http://www.junit.org".
  
  package org.apache.log4j.helpers;
  
  import org.apache.log4j.helpers.OptionConverter;
  import org.apache.log4j.Level;
  import org.apache.log4j.xml.XLevel;
  
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import junit.framework.Test;
  import java.util.Properties;
  
  /**
     Test variable substitution code.   
     @author Ceki G&uuml;lc&uuml;
     
     @since 1.0
  */
  public class OptionConverterTestCase extends TestCase {
  
    Properties props;
    
    public OptionConverterTestCase(String name) {
      super(name);
    }
  
    public
    void setUp() {
      props = new Properties();
      props.put("TOTO", "wonderful");
      props.put("key1", "value1");
      props.put("key2", "value2");
      System.setProperties(props);
  
  
    }  
    
    public
    void tearDown() {
      props = null;
    }
  
    public
    void varSubstTest1() {
      String r;
  
      r = OptionConverter.substVars("hello world.", null);
      assertEquals("hello world.", r);
      
      r = OptionConverter.substVars("hello ${TOTO} world.", null);
      
      assertEquals("hello wonderful world.", r);
    }
  
  
    public
    void varSubstTest2() {
      String r;
  
      r = OptionConverter.substVars("Test2 ${key1} mid ${key2} end.", null);
      assertEquals("Test2 value1 mid value2 end.", r);
    }
  
    public
    void varSubstTest3() {
      String r;
  
      r = OptionConverter.substVars(
  				     "Test3 ${unset} mid ${key1} end.", null);
      assertEquals("Test3  mid value1 end.", r);
    }
  
    public
    void varSubstTest4() {
      String res;
      String val = "Test4 ${incomplete ";
      try {
        res = OptionConverter.substVars(val, null);
      }
      catch(IllegalArgumentException e) {
        String errorMsg = e.getMessage();
        //System.out.println('['+errorMsg+']');
        assertEquals('"'+val+ "\" has no closing brace. Opening brace at position 6.", errorMsg);
      }
    }
  
  
    public
    void toLevelTest1() {
      String val = "INFO";
      Level p = OptionConverter.toLevel(val, null);
      assertEquals(p, Level.INFO);
    }
  
    public
    void toLevelTest2() {
      String val = "INFO#org.apache.log4j.xml.XLevel";
      Level p = OptionConverter.toLevel(val, null);
      assertEquals(p, Level.INFO);
    }
  
    public
    void toLevelTest3() {
      String val = "TRACE#org.apache.log4j.xml.XLevel";
      Level p = OptionConverter.toLevel(val, null);    
      assertEquals(p, XLevel.TRACE);
    }
  
    public
    void toLevelTest4() {
      String val = "TR#org.apache.log4j.xml.XLevel";
      Level p = OptionConverter.toLevel(val, null);    
      assertEquals(p, null);
    }
  
    public
    void toLevelTest5() {
      String val = "INFO#org.apache.log4j.xml.TOTO";
      Level p = OptionConverter.toLevel(val, null);    
      assertEquals(p, null);
    }
  
  
    public
    static
    Test suite() {
      TestSuite suite = new TestSuite();
      suite.addTest(new OptionConverterTestCase("varSubstTest1"));
      suite.addTest(new OptionConverterTestCase("varSubstTest2"));
      suite.addTest(new OptionConverterTestCase("varSubstTest3"));
      suite.addTest(new OptionConverterTestCase("varSubstTest4"));
  
      suite.addTest(new OptionConverterTestCase("toLevelTest1"));
      suite.addTest(new OptionConverterTestCase("toLevelTest2"));
      suite.addTest(new OptionConverterTestCase("toLevelTest3"));
      suite.addTest(new OptionConverterTestCase("toLevelTest4"));
      suite.addTest(new OptionConverterTestCase("toLevelTest5"));
      return suite;
    }
  
  }
  
  
  
  1.1                  jakarta-log4j/tests/witness/customLevel.1
  
  Index: customLevel.1
  ===================================================================
  DEBUG xml.CustomLevelTestCase - Message 1
  INFO  xml.CustomLevelTestCase - Message 2
  WARN  xml.CustomLevelTestCase - Message 3
  ERROR xml.CustomLevelTestCase - Message 4
  TRACE xml.CustomLevelTestCase - Message 5
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>