carnold     2005/01/08 12:54:01

  Modified:    tests    build.xml
  Added:       tests/input/schema/valid DOMTestCase1.xml customLogger3.xml
                        filters.LevelMatchFilter.test4.3.xml
                        filters.LevelMatchFilter.test4.4.xml
                        filters.LevelMatchFilter.test4.0.xml
                        customLevel3.xml customLevel4.xml
                        filters.LevelMatchFilter.test4.1.xml
                        customLogger2.xml defaultInit.xml customLevel2.xml
                        customLogger1.xml customLevel1.xml fallback1.xml
                        filters.LevelMatchFilter.test4.2.xml
               tests/src/java/org/apache/log4j/xml SchemaTestCase.java
               src/schema logging.xsd
               tests/input/schema/invalid empty.xml oldns.xml
  Log:
  Bug 33016: Starting XML Schema for http://logging.apache.org/
  
  Revision  Changes    Path
  1.1                  logging-log4j/tests/input/schema/valid/DOMTestCase1.xml
  
  Index: DOMTestCase1.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8" ?>
  <configuration xmlns='http://logging.apache.org/'
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
      xsi:schemaLocation="http://logging.apache.org/ logging.xsd">
  
    <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>
  
    <!-- Prevent internal log4j DEBUG messages from polluting the output. -->
    <logger name="org.apache.log4j.joran"><level value="INFO" /></logger>
    <logger name="org.apache.log4j.joran.action.PriorityAction"><level 
value="ERROR" /></logger>
    <logger name="org.apache.log4j.config"><level value="INFO" /></logger>
    <logger name="org.apache.log4j.FileAppender"><level value="INFO" /></logger>
    
    <logger name="org.apache.log4j.xml">
      <level value="debug" />
      <appender-ref ref="A1" />
    </logger>
    
    <root>
      <level value ="debug" />
      <appender-ref ref="A1" />
      <appender-ref ref="A2" />
    </root>
    
  </configuration>
  
  
  
  1.1                  logging-log4j/tests/input/schema/valid/customLogger3.xml
  
  Index: customLogger3.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8" ?>
  <configuration xmlns='http://logging.apache.org/'
                       debug="true"
                       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
                       xsi:schemaLocation="http://logging.apache.org/ 
logging.xsd">
    
    <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>
    
    <!-- Prevent internal log4j DEBUG messages from polluting the output. -->
    <logger name="org.apache.log4j.joran"><level value="INFO" /></logger>
    <logger name="org.apache.log4j.config"><level value="INFO" /></logger>
    <logger name="org.apache.log4j.FileAppender"><level value="INFO" /></logger>
    <logger name="org.apache.log4j.xml.Log4jEntityResolver"><level 
value="ERROR" /></logger>
  
    <root>
      <level value ="TRACE" class="org.apache.log4j.xml.XLevel"/>
      <appender-ref ref="TEMP" />
    </root>
  </configuration>
  
  
  1.1                  
logging-log4j/tests/input/schema/valid/filters.LevelMatchFilter.test4.3.xml
  
  Index: filters.LevelMatchFilter.test4.3.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8" ?>
  <configuration xmlns="http://logging.apache.org/";
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
      xsi:schemaLocation="http://logging.apache.org/ logging.xsd">
    <appender name="A1" class="org.apache.log4j.FileAppender">
      <param name="File"   value="output/filters.LevelMatchFilter.test4.txt" />
      <param name="Append" value="true" />
          
      <layout class="org.apache.log4j.SimpleLayout"/>
      
      <filter class="org.apache.log4j.filters.LevelMatchFilter">
        <param name="MatchReturnValue" value="accept"/>
        <param name="NoMatchReturnValue" value="deny"/>
        <param name="LevelToMatch" value="error"/>
      </filter>
    </appender>
      
    <root>
      <level value ="debug" />
      <appender-ref ref="A1" />
    </root>
    
  </configuration>
  
  
  
  1.1                  
logging-log4j/tests/input/schema/valid/filters.LevelMatchFilter.test4.4.xml
  
  Index: filters.LevelMatchFilter.test4.4.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8" ?>
  <configuration xmlns='http://logging.apache.org/'
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
      xsi:schemaLocation="http://logging.apache.org/ logging.xsd">
    <appender name="A1" class="org.apache.log4j.FileAppender">
      <param name="File"   value="output/filters.LevelMatchFilter.test4.txt" />
      <param name="Append" value="true" />
          
      <layout class="org.apache.log4j.SimpleLayout"/>
      
      <filter class="org.apache.log4j.filters.LevelMatchFilter">
        <param name="MatchReturnValue" value="accept"/>
        <param name="NoMatchReturnValue" value="deny"/>
        <param name="LevelToMatch" value="fatal"/>
      </filter>
    </appender>
      
    <root>
      <level value ="debug" />
      <appender-ref ref="A1" />
    </root>
    
  </configuration>
  
  
  
  1.1                  
logging-log4j/tests/input/schema/valid/filters.LevelMatchFilter.test4.0.xml
  
  Index: filters.LevelMatchFilter.test4.0.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8" ?>
  <configuration xmlns="http://logging.apache.org/";
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
      xsi:schemaLocation="http://logging.apache.org/ logging.xsd">
    <appender name="A1" class="org.apache.log4j.FileAppender">
      <param name="File"   value="output/filters.LevelMatchFilter.test4.txt" />
      <param name="Append" value="true" />
          
      <layout class="org.apache.log4j.SimpleLayout"/>
      
      <filter class="org.apache.log4j.filters.LevelMatchFilter">
        <param name="MatchReturnValue" value="accept"/>
        <param name="NoMatchReturnValue" value="deny"/>
        <param name="LevelToMatch" value="debug"/>
      </filter>
    </appender>
      
    <root>
      <level value ="debug" />
      <appender-ref ref="A1" />
    </root>
    
  </configuration>
  
  
  
  1.1                  logging-log4j/tests/input/schema/valid/customLevel3.xml
  
  Index: customLevel3.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8" ?>
  <configuration xmlns='http://logging.apache.org/'
                       debug="false"
                                 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
                       xsi:schemaLocation="http://logging.apache.org/ 
logging.xsd">
  
    <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>
      
      <filter class="org.apache.log4j.filter.LevelMatchFilter">
        <param name="LevelToMatch" value="TRACE#org.apache.log4j.xml.XLevel" />
        <param name="AcceptOnMatch" value="true" />
      </filter>
      
      <filter class="org.apache.log4j.filter.DenyAllFilter"/>
  
    </appender>
  
    <!-- Prevent internal log4j DEBUG messages from polluting the output. -->
    <logger name="org.apache.log4j.joran"><level value="INFO" /></logger>
    <logger name="org.apache.log4j.config"><level value="INFO" /></logger>
    <logger name="org.apache.log4j.FileAppender"><level value="INFO" /></logger>
  
    <root>
      <level value="TRACE" class="org.apache.log4j.xml.XLevel"/>
      <appender-ref ref="TEMP" />
    </root>
  
  </configuration>
  
  
  1.1                  logging-log4j/tests/input/schema/valid/customLevel4.xml
  
  Index: customLevel4.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8" ?>
  <configuration debug="true" 
                       xmlns='http://logging.apache.org/'
                                 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
                       xsi:schemaLocation="http://logging.apache.org/ 
logging.xsd">
  
    <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>
  
      <!-- Prevent internal log4j DEBUG messages from polluting the output. -->
    <logger name="org.apache.log4j.joran"><level value="INFO" /></logger>
    <logger name="org.apache.log4j.config"><level value="INFO" /></logger>
    <logger name="org.apache.log4j.FileAppender"><level value="INFO" /></logger>
    <logger name="org.apache.log4j.xml.Log4jEntityResolver"><level 
value="ERROR" /></logger>
  
    <root>
      <level value="TRACE#org.apache.log4j.xml.XLevel"/>
      <appender-ref ref="TEMP" />
    </root>
  </configuration>
  
  
  1.1                  
logging-log4j/tests/input/schema/valid/filters.LevelMatchFilter.test4.1.xml
  
  Index: filters.LevelMatchFilter.test4.1.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8" ?>
  <configuration xmlns="http://logging.apache.org/";
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
      xsi:schemaLocation="http://logging.apache.org/ logging.xsd">
    <appender name="A1" class="org.apache.log4j.FileAppender">
      <param name="File"   value="output/filters.LevelMatchFilter.test4.txt" />
      <param name="Append" value="true" />
          
      <layout class="org.apache.log4j.SimpleLayout"/>
      
      <filter class="org.apache.log4j.filters.LevelMatchFilter">
        <param name="MatchReturnValue" value="accept"/>
        <param name="NoMatchReturnValue" value="deny"/>
        <param name="LevelToMatch" value="info"/>
      </filter>
    </appender>
      
    <root>
      <level value ="debug" />
      <appender-ref ref="A1" />
    </root>
    
  </configuration>
  
  
  
  1.1                  logging-log4j/tests/input/schema/valid/customLogger2.xml
  
  Index: customLogger2.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8" ?>
  <configuration xmlns='http://logging.apache.org/'
                       debug="true"
                       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
                       xsi:schemaLocation="http://logging.apache.org/ 
logging.xsd">
    
    <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>
      
      <filter class="org.apache.log4j.filter.LevelMatchFilter">
        <param name="LevelToMatch"
             value="TRACE#org.apache.log4j.xml.XLevel" />
        <param name="AcceptOnMatch" value="true" />
      </filter>
      
      <filter class="org.apache.log4j.filter.DenyAllFilter"/>
    </appender>
    
    <!-- Prevent internal log4j DEBUG messages from polluting the output. -->
    <logger name="org.apache.log4j.joran"><level value="INFO" /></logger>
    <logger name="org.apache.log4j.config"><level value="INFO" /></logger>
    <logger name="org.apache.log4j.FileAppender"><level value="INFO" /></logger>
    <logger name="org.apache.log4j.xml.Log4jEntityResolver"><level 
value="ERROR" /></logger>
  
    <root>
      <level value ="TRACE" class="org.apache.log4j.xml.XLevel"/>
      <appender-ref ref="TEMP" />
    </root>
  </configuration>
  
  
  1.1                  logging-log4j/tests/input/schema/valid/defaultInit.xml
  
  Index: defaultInit.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8" ?>
  <configuration debug="true" xmlns="http://logging.apache.org/";
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
      xsi:schemaLocation="http://logging.apache.org/ logging.xsd">
  
    <appender name="D1" class="org.apache.log4j.ConsoleAppender">
      <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%-5p %c{2} - %m%n"/>
      </layout>     
    </appender>
    
    <root>
      <level value="OFF" />
      <appender-ref ref="D1" />
    </root>
    
  </configuration>
  
  
  
  1.1                  logging-log4j/tests/input/schema/valid/customLevel2.xml
  
  Index: customLevel2.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8" ?>
  <configuration xmlns='http://logging.apache.org/'
                       debug="false"
                                
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
                                xsi:schemaLocation="http://logging.apache.org/ 
logging.xsd">
  
    <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>
      
      <filter class="org.apache.log4j.filter.LevelMatchFilter">
        <param name="LevelToMatch" value="TRACE#org.apache.log4j.xml.XLevel" />
        <param name="AcceptOnMatch" value="true" />
      </filter>
    </appender>
  
      <!-- Prevent internal log4j DEBUG messages from polluting the output. -->
    <logger name="org.apache.log4j.joran"><level value="INFO" /></logger>
    <logger name="org.apache.log4j.config"><level value="INFO" /></logger>
    <logger name="org.apache.log4j.FileAppender"><level value="INFO" /></logger>
    <logger name="org.apache.log4j.xml.Log4jEntityResolver"><level 
value="ERROR" /></logger>
  
    <root>
      <level value="TRACE" class="org.apache.log4j.xml.XLevel"/>
      <appender-ref ref="TEMP" />
    </root>
  
  </configuration>
  
  
  1.1                  logging-log4j/tests/input/schema/valid/customLogger1.xml
  
  Index: customLogger1.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8" ?>
  <configuration xmlns='http://logging.apache.org/'
                       debug="false"
                                 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
                       xsi:schemaLocation="http://logging.apache.org/ 
logging.xsd">
    
    <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>
  
     <!-- Prevent internal log4j DEBUG messages from polluting the output. -->
    <logger name="org.apache.log4j.joran"><level value="INFO" /></logger>
    <logger name="org.apache.log4j.config"><level value="INFO" /></logger>
    <logger name="org.apache.log4j.FileAppender"><level value="INFO" /></logger>
    <logger name="org.apache.log4j.xml.Log4jEntityResolver"><level 
value="ERROR" /></logger>
  
    <root>
      <level value ="TRACE" class="org.apache.log4j.xml.XLevel"/>
      <appender-ref ref="TEMP" />
    </root>
  </configuration>
  
  
  1.1                  logging-log4j/tests/input/schema/valid/customLevel1.xml
  
  Index: customLevel1.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8" ?>
  <configuration xmlns='http://logging.apache.org/'
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
      xsi:schemaLocation="http://logging.apache.org/ logging.xsd">
  
    <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>
  
    <!-- Prevent internal log4j DEBUG messages from polluting the output. -->
    <logger name="org.apache.log4j.joran"><level value="INFO" /></logger>
    <logger name="org.apache.log4j.config"><level value="INFO" /></logger>
    <logger name="org.apache.log4j.FileAppender"><level value="INFO" /></logger>
  
    <root>
      <level value="TRACE" class="org.apache.log4j.xml.XLevel"/>
      <appender-ref ref="TEMP" />
    </root>
  </configuration>
  
  
  1.1                  logging-log4j/tests/input/schema/valid/fallback1.xml
  
  Index: fallback1.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8" ?>
  <configuration debug="true" xmlns="http://logging.apache.org/";
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
      xsi:schemaLocation="http://logging.apache.org/ logging.xsd">
  
  
    <appender name="PRIMARY" class="org.apache.log4j.FileAppender">
      <errorHandler class="org.apache.log4j.varia.FallbackErrorHandler">
        <root-ref/>
        <appender-ref ref="FALLBACK" />
      </errorHandler>
  
      <param name="File" value="/xyz/x.log" />
      <param name="Append" value="false" />         
      
      <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%-5p %c{2} - %m%n"/>
      </layout>     
    </appender>
    
    <appender name="FALLBACK" class="org.apache.log4j.FileAppender">
      <param name="File" value="output/temp" />
      <param name="Append" value="false" />
      <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="FALLBACK - %c - %m%n"/>
      </layout>     
    </appender>
        
    
    <root>
      <level value ="debug" />
      <appender-ref ref="PRIMARY" />
    </root>
        
  </configuration>
  
  
  
  1.1                  
logging-log4j/tests/input/schema/valid/filters.LevelMatchFilter.test4.2.xml
  
  Index: filters.LevelMatchFilter.test4.2.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8" ?>
  <configuration xmlns="http://logging.apache.org/";
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
      xsi:schemaLocation="http://logging.apache.org/ logging.xsd">
    <appender name="A1" class="org.apache.log4j.FileAppender">
      <param name="File"   value="output/filters.LevelMatchFilter.test4.txt" />
      <param name="Append" value="true" />
          
      <layout class="org.apache.log4j.SimpleLayout"/>
      
      <filter class="org.apache.log4j.filters.LevelMatchFilter">
        <param name="MatchReturnValue" value="accept"/>
        <param name="NoMatchReturnValue" value="deny"/>
        <param name="LevelToMatch" value="warn"/>
      </filter>
    </appender>
      
    <root>
      <level value ="debug" />
      <appender-ref ref="A1" />
    </root>
    
  </configuration>
  
  
  
  1.1                  
logging-log4j/tests/src/java/org/apache/log4j/xml/SchemaTestCase.java
  
  Index: SchemaTestCase.java
  ===================================================================
  /*
   * Copyright 2005 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.log4j.xml;
  
  import java.io.ByteArrayInputStream;
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.IOException;
  
  import javax.xml.parsers.SAXParser;
  import javax.xml.parsers.SAXParserFactory;
  
  import junit.framework.TestCase;
  
  import org.xml.sax.InputSource;
  import org.xml.sax.SAXException;
  import org.xml.sax.SAXParseException;
  import org.xml.sax.helpers.DefaultHandler;
  
  /**
   * Tests the src/schema/logging-strict.xsd and src/schema/logging.xsd
   * by checking the validation results of configuration files in 
   * subdirectories of tests/input/schema.
   * 
   * @author Curt Arnold
   *
   */
  public class SchemaTestCase extends TestCase {
  
        /**
         * Constructs a SchemaTestCase
         * @param test name
         */
        public SchemaTestCase(final String testName) {
                super(testName);
        }
        
        private static final String loggingXSD = "../src/schema/logging.xsd"; 
  
        /**
         * Validate input/schema/strict/*.xml against
         * both logging-strict.xsd and logging.xsd
         * expecting everything to be valid.
         * 
         * @throws Exception
         */
        public void testValid() throws Exception {
                validateFiles("input/schema/valid", 
                                loggingXSD,
                                true);
        }
  
        
        /**
         * Validate input/schema/strict/*.xml against
         * both logging-strict.xsd and logging.xsd
         * expecting everything to be invalid.
         * 
         * @throws Exception
         */
        public void testInvalid() throws Exception {
                validateFiles("input/schema/invalid", 
                                loggingXSD,
                                false);
        }
        
        private static class SchemaEntityResolver extends DefaultHandler {
          private final byte[] schemaBytes = new byte[20000];
          private final int schemaLength;
          
                public SchemaEntityResolver(final String schemaLocation) 
                    throws IOException {
                        FileInputStream fs = new 
FileInputStream(schemaLocation);
                        schemaLength = fs.read(schemaBytes);
                        if (schemaLength == schemaBytes.length) {
                                throw new IOException("Buffer too small for 
schema.");                          
                        }
                        fs.close();
                }
                
                public InputSource resolveEntity(final String publicID, 
                                final String systemID) {
                        return new InputSource(new 
ByteArrayInputStream(schemaBytes, 0, schemaLength));
                }
                
                public void error(SAXParseException ex) throws 
SAXParseException {
                        throw ex;
                }
        }
  
        /**
         * Loads the specified schema and validates
         * files matching the pattern.
         * 
         * @param testPath Directory containing test files
         * @param schemaLocation schema location
         * @param expected expected validation result
         */
        private void validateFiles(final String testPath,
                        final String schemaLocation,
                        final boolean expected) throws Exception {
                
                File testDir = new File(testPath);
                assertTrue(testDir.exists());
                assertTrue(testDir.isDirectory());
                
                String[] files = testDir.list();
                
                SAXParserFactory factory = SAXParserFactory.newInstance();
                factory.setNamespaceAware(true);
                factory.setValidating(true);
                
factory.setFeature("http://apache.org/xml/features/validation/schema";, true);
                SAXParser parser = factory.newSAXParser();
  
                DefaultHandler handler = new 
SchemaEntityResolver(schemaLocation);
                
                if (expected) {
                        for(int i = 0; i < files.length; i++) {
                                if (files[i].endsWith(".xml")) {
                                        File testFile = new File(testDir, 
files[i]);
                                        try {
                                                parser.parse(testFile, handler);
                                        } catch(SAXException ex) {
                                                fail("Exception while parsing 
expected valid configuration " + testFile.toString() + ".  " +  ex.toString());
                                        }
                                }
                        }
                } else {
                        for(int i = 0; i < files.length; i++) {
                                if (files[i].endsWith(".xml")) {
                                        try {
                                                File testFile = new 
File(testDir, files[i]);
                                                parser.parse(testFile, handler);
                                                fail("No exception thrown on 
expected invalid configuration " + testFile.toString());
                                        } catch(SAXException ex) {
                                        }
                                }
                        }
                }
                
        }
  }
  
  
  
  1.1                  logging-log4j/src/schema/logging.xsd
  
  Index: logging.xsd
  ===================================================================
  <?xml version="1.0" encoding="utf-8" ?> 

  <!--

    Copyright 2005 The Apache Software Foundation.

    

    Licensed under the Apache License, Version 2.0 (the "License");

    you may not use this file except in compliance with the License.

    You may obtain a copy of the License at

    

         http://www.apache.org/licenses/LICENSE-2.0

    

    Unless required by applicable law or agreed to in writing, software

    distributed under the License is distributed on an "AS IS" BASIS,

    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

    See the License for the specific language governing permissions and

    limitations under the License.

    

  -->

  <xs:schema targetNamespace="http://logging.apache.org/";

                    elementFormDefault="qualified"

                    xmlns="http://logging.apache.org/";

                    xmlns:xs="http://www.w3.org/2001/XMLSchema";>

                   

  <xs:simpleType name="objectName">

     <xs:restriction base="xs:string">

           <xs:minLength value="1"/>

     </xs:restriction>

  </xs:simpleType>                  

  

  <xs:simpleType name="className">

     <xs:restriction base="xs:string">

                <!-- xs:pattern value=""/ -->

     </xs:restriction>

  </xs:simpleType>

  

  <xs:attributeGroup name="object">

        <xs:attribute name="class" type="className" use="optional"/>

  </xs:attributeGroup>

  

  <xs:element name="configuration">

        <xs:complexType>

                <xs:sequence>

                        <xs:element ref="appender" minOccurs="1" 
maxOccurs="unbounded"/>

                        <xs:element ref="logger" minOccurs="0" 
maxOccurs="unbounded"/>

                        <xs:element ref="root" minOccurs="1" maxOccurs="1"/>

                </xs:sequence>

                <xs:attribute name="debug" type="xs:boolean"/>

        </xs:complexType>

  </xs:element>

  

  <xs:element name="appender">

        <xs:complexType>

                <xs:sequence>

                        <xs:element ref="errorHandler" minOccurs="0" 
maxOccurs="1"/>

                        <xs:element ref="param" minOccurs="0" 
maxOccurs="unbounded"/>

                        <xs:element ref="layout" minOccurs="0" maxOccurs="1"/>

                        <xs:element ref="filter" minOccurs="0" 
maxOccurs="unbounded"/>

                </xs:sequence>

                <xs:attribute name="name" type="objectName" use="required"/>

                <xs:attribute name="class" type="className" use="required"/>

        </xs:complexType>

  </xs:element>

  

  <xs:element name="logger">

        <xs:complexType>

                <xs:sequence>

                        <xs:element ref="level" minOccurs="0"/>

                        <xs:element ref="appender-ref" minOccurs="0" 
maxOccurs="unbounded"/>

                </xs:sequence>

                <xs:attribute name="name" type="objectName" use="required"/>

        </xs:complexType>

  </xs:element>

  

  <xs:element name="root">

        <xs:complexType>

                <xs:sequence>

                        <xs:element ref="level" minOccurs="0"/>

                        <xs:element ref="appender-ref" minOccurs="0" 
maxOccurs="unbounded"/>

                </xs:sequence>

        </xs:complexType>

  </xs:element>

  

  <xs:simpleType name="levelValue">

        <xs:restriction base="xs:string">

                <xs:minLength value="1"/>

        </xs:restriction>

  </xs:simpleType>

  

  <xs:element name="level">

        <xs:complexType>

                <xs:attribute name="value" type="levelValue" use="required"/>

                <xs:attribute name="class" type="className" use="optional"/>

        </xs:complexType>

  </xs:element>

  

  <xs:simpleType name="paramName">

        <xs:restriction base="xs:string">

                <xs:minLength value="1"/>

        </xs:restriction>

  </xs:simpleType>

  

  <xs:element name="param">

        <xs:complexType>

                <xs:attribute name="name" type="paramName" use="required"/>

                <xs:attribute name="value" type="xs:string" use="required"/>

        </xs:complexType>

  </xs:element>

  

  <xs:element name="layout">

        <xs:complexType>

                <xs:sequence>

                        <xs:element ref="param" minOccurs="0" 
maxOccurs="unbounded"/>

                </xs:sequence>

                <xs:attribute name="class" type="className" use="required"/>

        </xs:complexType>

  </xs:element>

  

  <xs:element name="root-ref">

        <xs:complexType>

        </xs:complexType>

  </xs:element>

  

  <xs:element name="appender-ref">

        <xs:complexType>

                <xs:attribute name="ref" type="objectName" use="required"/>

        </xs:complexType>

  </xs:element>

  

  <xs:group name="appender-ref">

        <xs:choice>

                <xs:element ref="root-ref"/>

                <xs:element ref="appender-ref"/>

        </xs:choice>

  </xs:group>

  

  

  <xs:element name="filter">

      <xs:complexType>

        <xs:sequence>

                <xs:element ref="param" minOccurs="0" maxOccurs="unbounded"/>

        </xs:sequence>

        <xs:attribute name="class" type="className" use="required"/>

      </xs:complexType>

  </xs:element>

  

  <xs:element name="errorHandler">

     <xs:complexType>

          <xs:sequence>

                <xs:group ref="appender-ref" minOccurs="0" 
maxOccurs="unbounded"/>

          </xs:sequence>

          <xs:attribute name="class" type="className" use="required"/>          
  

        </xs:complexType>

  </xs:element>

  

  </xs:schema>

  
  
  
  1.1                  logging-log4j/tests/input/schema/invalid/empty.xml
  
  Index: empty.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8" ?>
  <configuration xmlns='http://logging.apache.org/'
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
      xsi:schemaLocation="http://logging.apache.org/ logging.xsd">
  </configuration>
  
  
  1.1                  logging-log4j/tests/input/schema/invalid/oldns.xml
  
  Index: oldns.xml
  ===================================================================
  <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"/>
  
  
  1.91      +20 -5     logging-log4j/tests/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/logging-log4j/tests/build.xml,v
  retrieving revision 1.90
  retrieving revision 1.91
  diff -u -r1.90 -r1.91
  --- build.xml 8 Jan 2005 15:47:44 -0000       1.90
  +++ build.xml 8 Jan 2005 20:54:01 -0000       1.91
  @@ -176,23 +176,24 @@
                                        XMLLayout, 
                                         AsyncAppender, 
                                        OptionSubstitutionTest,
  -                                  LevelOptionConverterTest,
  -                                  BoundedFIFO, 
  +                                      LevelOptionConverterTest,
  +                                                  BoundedFIFO, 
                                        Joran,
                                        SimpleFilter,
  -                                  Scheduler, 
  +                                      Scheduler, 
                                        ThrowableInformation,
                                        LocationInfo,
                                        CyclicBuffer, 
                                        OR, 
  -                                  VariaLevelMatchFilter, 
  +                                      VariaLevelMatchFilter, 
                                        VariaLevelRangeFilter, PatternParser,
                                        LevelMatchFilter, DRFA, 
                                        Rolling, 
                                        NDC,
                                        Plugins,
                                        CachedDateFormat,
  -                                     ReaderWriterLock
  +                                     ReaderWriterLock,
  +                                      Schema
                                        "/>
   
   
  @@ -620,6 +621,20 @@
          <classpath refid="tests.classpath"/>
          <formatter type="plain" usefile="false"/>
          <test name="org.apache.log4j.pattern.CachedDateFormatTest" />
  +    </junit>
  +  </target>
  +
  +  <target name="Schema" depends="check, build">
  +     <available classname="org.apache.xerces.jaxp.SAXParserFactoryImpl" 
property="xerces-available"/>
  +     <fail unless="xerces-available" message="Schema tests require Xerces-J 
2.x on class path."/>
  +     <junit printsummary="yes" fork="yes" haltonfailure="yes">
  +       <classpath>
  +         <pathelement path="${javac.dest}"/>
  +             <pathelement path="${java.class.path}"/>
  +       </classpath>
  +       <jvmarg 
value="-Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl"/>
            
  +       <formatter type="plain" usefile="false"/>
  +       <test name="org.apache.log4j.xml.SchemaTestCase" />
       </junit>
     </target>
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to