Author: veithen
Date: Sun Aug 29 18:57:10 2010
New Revision: 990625

URL: http://svn.apache.org/viewvc?rev=990625&view=rev
Log:
Created a new module for test cases for StAXDialect. This will eventually 
replace the brute force axiom-parser-tests.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/
    
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/pom.xml 
  (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/
    
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/
    
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/
    
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/
    
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/
    
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/
    
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/
    
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/
    
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/
    
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java
   (with props)
    
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/DialectTestCase.java
   (with props)
    
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/DialectTestSuite.java
   (with props)
    
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/IsCharactersOnCDATASectionTestCase.java
   (with props)
    
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/resources/
    
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/resources/stax.properties
Modified:
    webservices/commons/trunk/modules/axiom/pom.xml

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/pom.xml
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/pom.xml?rev=990625&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/pom.xml 
(added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/pom.xml 
Sun Aug 29 18:57:10 2010
@@ -0,0 +1,106 @@
+<?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 xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.ws.commons.axiom</groupId>
+        <artifactId>axiom-parent</artifactId>
+        <version>1.2.10-SNAPSHOT</version>
+        <relativePath>../axiom-parent/pom.xml</relativePath>
+    </parent>
+    <artifactId>axiom-staxdialect-tests</artifactId>
+    <name>Axiom StAXDialect Test Suite</name>
+    <description>
+        This module tests the StAXDialect feature with various StAX 
implementations.
+    </description>
+    <scm>
+        
<connection>scm:svn:http://svn.apache.org/repos/asf/webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests</connection>
+        
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests</developerConnection>
+        
<url>http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests</url>
+    </scm>
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>axiom-api</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+        </dependency>
+    </dependencies>
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>maven-dependency-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>copy-parsers</id>
+                        <phase>generate-test-resources</phase>
+                        <goals>
+                            <goal>copy</goal>
+                        </goals>
+                        <configuration>
+                            <artifactItems>
+                                <artifactItem>
+                                    <groupId>org.codehaus.woodstox</groupId>
+                                    <artifactId>wstx-asl</artifactId>
+                                    <version>3.2.7</version>
+                                </artifactItem>
+                                <artifactItem>
+                                    <groupId>org.codehaus.woodstox</groupId>
+                                    <artifactId>wstx-asl</artifactId>
+                                    <version>3.2.8</version>
+                                </artifactItem>
+                                <artifactItem>
+                                    <groupId>org.codehaus.woodstox</groupId>
+                                    <artifactId>wstx-asl</artifactId>
+                                    <version>3.2.9</version>
+                                </artifactItem>
+                                <artifactItem>
+                                    <groupId>com.sun.xml.stream</groupId>
+                                    <artifactId>sjsxp</artifactId>
+                                    <version>1.0.1</version>
+                                </artifactItem>
+                                <artifactItem>
+                                    <groupId>stax</groupId>
+                                    <artifactId>stax</artifactId>
+                                    <version>1.2.0</version>
+                                </artifactItem>
+                            </artifactItems>
+                            
<outputDirectory>${project.build.directory}/parsers</outputDirectory>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <configuration>
+                    <includes>
+                        <include>**/DialectTestSuite.java</include>
+                    </includes>
+                    <excludes>
+                        <exclude>**/*Test.java</exclude>
+                    </excludes>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java?rev=990625&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java
 Sun Aug 29 18:57:10 2010
@@ -0,0 +1,75 @@
+/*
+ * 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.
+ */
+package org.apache.axiom.util.stax.dialect;
+
+import java.util.Properties;
+
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLInputFactory;
+
+import junit.framework.TestSuite;
+
+public class DialectTest extends TestSuite {
+    private final ClassLoader classLoader;
+    private final Properties props;
+    private StAXDialect dialect;
+    
+    public DialectTest(ClassLoader classLoader, String name, Properties props) 
{
+        super(name);
+        this.classLoader = classLoader;
+        this.props = props;
+        addDialectTest(new IsCharactersOnCDATASectionTestCase());
+    }
+    
+    private void addDialectTest(DialectTestCase testCase) {
+        testCase.init(this);
+        addTest(testCase);
+    }
+    
+    XMLInputFactory newXMLInputFactory() {
+        String className = props == null ? null : 
props.getProperty(XMLInputFactory.class.getName());
+        if (className == null) {
+            ClassLoader savedClassLoader = 
Thread.currentThread().getContextClassLoader();
+            Thread.currentThread().setContextClassLoader(classLoader);
+            try {
+                XMLInputFactory factory = XMLInputFactory.newInstance();
+                if (factory.getClass().getClassLoader() != classLoader) {
+                    throw new FactoryConfigurationError("Wrong factory!");
+                }
+                return factory;
+            } finally {
+                Thread.currentThread().setContextClassLoader(savedClassLoader);
+            }
+        } else {
+            try {
+                return 
(XMLInputFactory)classLoader.loadClass(className).newInstance();
+            } catch (Exception ex) {
+                throw new FactoryConfigurationError(ex);
+            }
+        }
+    }
+    
+    XMLInputFactory newNormalizedXMLInputFactory() {
+        XMLInputFactory factory = newXMLInputFactory();
+        if (dialect == null) {
+            dialect = StAXDialectDetector.getDialect(factory.getClass());
+        }
+        return dialect.normalize(factory);
+    }
+}

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/DialectTestCase.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/DialectTestCase.java?rev=990625&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/DialectTestCase.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/DialectTestCase.java
 Sun Aug 29 18:57:10 2010
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+package org.apache.axiom.util.stax.dialect;
+
+import javax.xml.stream.XMLInputFactory;
+
+import junit.framework.TestCase;
+
+public abstract class DialectTestCase extends TestCase {
+    private DialectTest test;
+    
+    void init(DialectTest test) {
+        this.test = test;
+        setName(getClass().getName());
+    }
+    
+    protected XMLInputFactory newNormalizedXMLInputFactory() {
+        return test.newNormalizedXMLInputFactory();
+    }
+}

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/DialectTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/DialectTestSuite.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/DialectTestSuite.java?rev=990625&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/DialectTestSuite.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/DialectTestSuite.java
 Sun Aug 29 18:57:10 2010
@@ -0,0 +1,94 @@
+/*
+ * 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.
+ */
+package org.apache.axiom.util.stax.dialect;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Properties;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class DialectTestSuite extends TestSuite {
+    private static final FilenameFilter jarFilter = new FilenameFilter() {
+        public boolean accept(File dir, String name) {
+            return name.endsWith(".jar");
+        }
+    };
+    
+    public static Test suite() throws Exception {
+        DialectTestSuite suite = new DialectTestSuite();
+        
+        File targetDir = new File("target");
+        
+        // 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")) {
+            suite.addTest(new DialectTest(ClassLoader.getSystemClassLoader(), 
"JRE", null));
+        }
+        
+        suite.addParsersFromDirectory(new File("parsers"));
+        suite.addParsersFromDirectory(new File(targetDir, "parsers"));
+        
+        return suite;
+    }
+
+    private void addParsersFromDirectory(File dir) throws Exception {
+        if (dir.exists()) {
+            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;
+        
+        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 = DialectTestSuite.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() }, DialectTestSuite.class.getClassLoader());
+        addTest(new DialectTest(parserClassLoader, parserJar.getName(), 
props));
+    }
+}

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/DialectTestSuite.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/IsCharactersOnCDATASectionTestCase.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/IsCharactersOnCDATASectionTestCase.java?rev=990625&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/IsCharactersOnCDATASectionTestCase.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/IsCharactersOnCDATASectionTestCase.java
 Sun Aug 29 18:57:10 2010
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+package org.apache.axiom.util.stax.dialect;
+
+import java.io.StringReader;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+public class IsCharactersOnCDATASectionTestCase extends DialectTestCase {
+    protected void runTest() throws Throwable {
+        XMLInputFactory factory = newNormalizedXMLInputFactory();
+        factory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
+        XMLStreamReader reader = factory.createXMLStreamReader(new 
StringReader("<root><![CDATA[X]]></root>"));
+        reader.nextTag();
+        reader.next();
+        assertTrue(reader.isCharacters());
+    }
+}

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/IsCharactersOnCDATASectionTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/resources/stax.properties
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/resources/stax.properties?rev=990625&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/resources/stax.properties
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/resources/stax.properties
 Sun Aug 29 18:57:10 2010
@@ -0,0 +1,3 @@
+javax.xml.stream.XMLInputFactory=com.bea.xml.stream.MXParserFactory
+javax.xml.stream.XMLOutputFactory=com.bea.xml.stream.XMLOutputFactoryBase
+javax.xml.stream.XMLEventFactory=com.bea.xml.stream.EventFactory
\ No newline at end of file

Modified: webservices/commons/trunk/modules/axiom/pom.xml
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/pom.xml?rev=990625&r1=990624&r2=990625&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/pom.xml (original)
+++ webservices/commons/trunk/modules/axiom/pom.xml Sun Aug 29 18:57:10 2010
@@ -520,6 +520,7 @@
         <module>modules/axiom-testutils</module>
         <module>modules/axiom-jaxen-testsuite</module>
         <module>modules/axiom-api</module>
+        <module>modules/axiom-staxdialect-tests</module>
         <module>modules/axiom-impl</module>
         <module>modules/axiom-dom</module>
         <module>modules/axiom-c14n</module>


Reply via email to