You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ve...@apache.org on 2009/08/02 09:55:09 UTC

svn commit: r800004 - in /webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests: ./ parsers/ src/test/java/ src/test/resources/

Author: veithen
Date: Sun Aug  2 07:55:09 2009
New Revision: 800004

URL: http://svn.apache.org/viewvc?rev=800004&view=rev
Log:
Parser test suite:
* Added a feature to run the tests with StAX implementations that are not available from public Maven repositories.
* Support implementations that require system properties (because they don't have META-INF/services).

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/parsers/
    webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/parsers/build.xml   (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/parsers/readme.txt   (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/src/test/java/ParserTestSetup.java
      - copied, changed from r799402, webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/src/test/java/SetContextClassLoaderTestWrapper.java
    webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/src/test/resources/
    webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/src/test/resources/com.ibm.ws.runtime.properties
Removed:
    webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/src/test/java/SetContextClassLoaderTestWrapper.java
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/pom.xml
    webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/src/test/java/ParserTest.java

Added: webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/parsers/build.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/parsers/build.xml?rev=800004&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/parsers/build.xml (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/parsers/build.xml Sun Aug  2 07:55:09 2009
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements. See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership. The ASF licenses this file
+  ~ to you 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.
+  -->
+<project>
+    <!-- Use this to extract the XLXP parser from the Feature Pack for Web Services for
+         WebSphere Application Server V6.1.
+         
+         Usage: ant extract-xlxp -Dfile=/path/to/6.1.0-WS-WAS-WSFEP-WinX32.zip -->
+    <target name="extract-xlxp">
+        <property name="file" value=""/>
+        <mkdir dir=".tmp"/>
+        <unzip src="${file}" dest=".tmp">
+            <patternset>
+                <include name="EBIFMaintenance/6.1.0.9-WS-WASFeature-IFII000002.pak"/>
+            </patternset>
+        </unzip>
+        <unzip src=".tmp/EBIFMaintenance/6.1.0.9-WS-WASFeature-IFII000002.pak" dest=".tmp">
+            <patternset>
+            	<include name="repository/was.rt.bundle/plugins/com.ibm.ws.runtime_6.1.0.jar/**/*"/>
+            </patternset>
+        </unzip>
+        <zip destfile="com.ibm.ws.runtime_6.1.0.jar" >
+            <fileset dir=".tmp/repository/was.rt.bundle/plugins/com.ibm.ws.runtime_6.1.0.jar"/>
+        </zip>
+        <delete dir=".tmp"/>
+    </target>
+</project>

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/parsers/build.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/parsers/readme.txt
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/parsers/readme.txt?rev=800004&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/parsers/readme.txt (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/parsers/readme.txt Sun Aug  2 07:55:09 2009
@@ -0,0 +1 @@
+Use this folder to drop other parsers that are not available from public Maven repositories.
\ No newline at end of file

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/parsers/readme.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/pom.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/pom.xml?rev=800004&r1=800003&r2=800004&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/pom.xml (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/pom.xml Sun Aug  2 07:55:09 2009
@@ -92,11 +92,6 @@
         </dependency>
     </dependencies>
     <build>
-        <testResources>
-            <testResource>
-                <directory>test-resources</directory>
-            </testResource>
-        </testResources>
         <plugins>
             <plugin>
                 <artifactId>maven-dependency-plugin</artifactId>

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/src/test/java/ParserTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/src/test/java/ParserTest.java?rev=800004&r1=800003&r2=800004&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/src/test/java/ParserTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/src/test/java/ParserTest.java Sun Aug  2 07:55:09 2009
@@ -20,10 +20,12 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FilenameFilter;
+import java.io.InputStream;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.net.URL;
 import java.net.URLClassLoader;
+import java.util.Properties;
 import java.util.jar.JarEntry;
 import java.util.jar.JarInputStream;
 
@@ -31,17 +33,21 @@
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
-public class ParserTest extends TestCase {
-    public static Test suite() throws Exception {
-        ClassLoader parentClassLoader = ParserTest.class.getClassLoader();
-        File targetDir = new File("target");
-        FilenameFilter jarFilter = new FilenameFilter() {
-            public boolean accept(File dir, String name) {
-                return name.endsWith(".jar");
-            }
-        };
-        File[] testJars = new File(targetDir, "test-jars").listFiles(jarFilter);
-        
+public class ParserTest extends TestSuite {
+    private static final FilenameFilter jarFilter = new FilenameFilter() {
+        public boolean accept(File dir, String name) {
+            return name.endsWith(".jar");
+        }
+    };
+    
+    private final ClassLoader parentClassLoader;
+    private TestSuite suite;
+
+    public ParserTest() {
+        parentClassLoader = ParserTest.class.getClassLoader();
+    }
+    
+    private void loadTestJars(File[] testJars) throws Exception {
         // Build the class loader. We use a single class loader for all test JARs because there
         // are dependencies between them.
         URL[] testJarUrls = new URL[testJars.length];
@@ -51,7 +57,7 @@
         ClassLoader testClassLoader = new URLClassLoader(testJarUrls, parentClassLoader);
         
         // Scan the test JARs for test cases/suites and build a test suite from them
-        TestSuite suite = new TestSuite();
+        suite = new TestSuite();
         for (int i=0; i<testJars.length; i++) {
             JarInputStream jar = new JarInputStream(new FileInputStream(testJars[i]));
             try {
@@ -78,21 +84,66 @@
                 jar.close();
             }
         }
+    }
+    
+    private void addParserFromJRE() {
+        addTest(new ParserTestSetup(suite, ClassLoader.getSystemClassLoader(), null));
+    }
+    
+    private void addParsersFromDirectory(File dir) throws Exception {
+        // Build decorators that execute the test suite using different StAX implementations
+        File[] parserJars = dir.listFiles(jarFilter);
+        for (int i=0; i<parserJars.length; i++) {
+            addParserJar(parserJars[i]);
+        }
+    }
+    
+    private void addParserJar(File parserJar) throws Exception {
+        Properties props = null;
         
-        TestSuite superSuite = new TestSuite();
+        String name = parserJar.getName();
+        int delimiterIndex = name.length();
+        outer: while (true) {
+            while (true) {
+                if (delimiterIndex-- == 0) {
+                    break outer;
+                }
+                char c = name.charAt(delimiterIndex);
+                if (c == '.' || c == '_' || c == '-') {
+                    break;
+                }
+            }
+            InputStream in = ParserTest.class.getResourceAsStream("/" + name.substring(0, delimiterIndex) + ".properties");
+            if (in != null) {
+                try {
+                    props = new Properties();
+                    props.load(in);
+                } finally {
+                    in.close();
+                }
+                break;
+            }
+        }
+        
+        ClassLoader parserClassLoader = new URLClassLoader(new URL[] { parserJar.toURL() }, parentClassLoader);
+        addTest(new ParserTestSetup(suite, parserClassLoader, props));
+    }
+
+    public static Test suite() throws Exception {
+        ParserTest suite = new ParserTest();
+        
+        File targetDir = new File("target");
+        suite.loadTestJars(new File(targetDir, "test-jars").listFiles(jarFilter));
         
         // On Java 1.6, also add the StAX implementation from the JRE
         // The check is not very clean but it should be enough for a unit test...
         if (System.getProperty("java.version").startsWith("1.6")) {
-            superSuite.addTest(new SetContextClassLoaderTestWrapper(suite, ClassLoader.getSystemClassLoader()));
+            suite.addParserFromJRE();
         }
         
-        // Build decorators that execute the test suite using different StAX implementations
-        File[] parserJars = new File(targetDir, "parsers").listFiles(jarFilter);
-        for (int i=0; i<parserJars.length; i++) {
-            ClassLoader parserClassLoader = new URLClassLoader(new URL[] { parserJars[i].toURL() }, parentClassLoader);
-            superSuite.addTest(new SetContextClassLoaderTestWrapper(suite, parserClassLoader));
-        }
-        return superSuite;
+        suite.addParsersFromDirectory(new File("parsers"));
+        suite.addParsersFromDirectory(new File(targetDir, "parsers"));
+        
+        return suite;
     }
 }

Copied: webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/src/test/java/ParserTestSetup.java (from r799402, webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/src/test/java/SetContextClassLoaderTestWrapper.java)
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/src/test/java/ParserTestSetup.java?p2=webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/src/test/java/ParserTestSetup.java&p1=webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/src/test/java/SetContextClassLoaderTestWrapper.java&r1=799402&r2=800004&rev=800004&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/src/test/java/SetContextClassLoaderTestWrapper.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/src/test/java/ParserTestSetup.java Sun Aug  2 07:55:09 2009
@@ -17,26 +17,61 @@
  * under the License.
  */
 
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+
 import junit.extensions.TestDecorator;
 import junit.framework.Test;
 import junit.framework.TestResult;
 
-public class SetContextClassLoaderTestWrapper extends TestDecorator {
+public class ParserTestSetup extends TestDecorator {
     private final ClassLoader classLoader;
+    private final Properties props;
     
-    public SetContextClassLoaderTestWrapper(Test test, ClassLoader classLoader) {
+    public ParserTestSetup(Test test, ClassLoader classLoader, Properties props) {
         super(test);
         this.classLoader = classLoader;
+        this.props = props;
     }
 
     public void run(TestResult result) {
         Thread currentThread = Thread.currentThread();
         ClassLoader savedClassLoader = currentThread.getContextClassLoader();
         currentThread.setContextClassLoader(classLoader);
+
+        Map savedProps;
+        if (props == null) {
+            savedProps = null;
+        } else {
+            // Need a HashMap (instead of Properties) since we store null values
+            savedProps = new HashMap();
+            for (Iterator it = props.entrySet().iterator(); it.hasNext(); ) {
+                Map.Entry entry = (Map.Entry)it.next();
+                String key = (String)entry.getKey();
+                savedProps.put(key, System.getProperty(key));
+                System.setProperty(key, (String)entry.getValue());
+            }
+        }
+        
         try {
             super.run(result);
         } finally {
             currentThread.setContextClassLoader(savedClassLoader);
+            
+            if (savedProps != null) {
+                for (Iterator it = savedProps.entrySet().iterator(); it.hasNext(); ) {
+                    Map.Entry entry = (Map.Entry)it.next();
+                    String key = (String)entry.getKey();
+                    String value = (String)entry.getValue();
+                    if (value == null) {
+                        System.getProperties().remove(key);
+                    } else {
+                        System.setProperty(key, value);
+                    }
+                }
+            }
         }
     }
 }

Added: webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/src/test/resources/com.ibm.ws.runtime.properties
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/src/test/resources/com.ibm.ws.runtime.properties?rev=800004&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/src/test/resources/com.ibm.ws.runtime.properties (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/src/test/resources/com.ibm.ws.runtime.properties Sun Aug  2 07:55:09 2009
@@ -0,0 +1,2 @@
+javax.xml.stream.XMLInputFactory=com.ibm.xml.xlxp.api.stax.XMLInputFactoryImpl
+javax.xml.stream.XMLOutputFactory=com.ibm.xml.xlxp.api.stax.XMLOutputFactoryImpl