Author: veithen
Date: Sat Apr  4 11:01:55 2009
New Revision: 761900

URL: http://svn.apache.org/viewvc?rev=761900&view=rev
Log:
Refactored the OMStAXWrapper tests.

Added:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/stax/
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/stax/XMLFragmentStreamReader.java
   (with props)
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/stax/package.html
   (with props)
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/OMStAXWrapperConformanceTestCase.java
   (with props)
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/stax/
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/stax/XMLFragmentStreamReaderTest.java
   (with props)
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/stax/XMLStreamReaderComparator.java
      - copied, changed from r758915, 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/XMLStreamReaderComparator.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/conformance/
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/conformance/namespaces.xml
   (with props)
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/conformance/processingInstruction.xml
   (with props)
    
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMStAXWrapperConformanceTest.java
   (with props)
    
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMStAXWrapperConformanceTest.java
   (with props)
Removed:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/XMLStreamReaderComparator.java
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/pom.xml
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/AbstractTestCase.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/OMStAXWrapperTestBase.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/pom.xml
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/pom.xml?rev=761900&r1=761899&r2=761900&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/pom.xml (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/pom.xml Sat Apr  
4 11:01:55 2009
@@ -59,6 +59,11 @@
                         <groupId>xmlunit</groupId>
                         <artifactId>xmlunit</artifactId>
                 </dependency>
+        <dependency>
+            <groupId>${stax.impl.groupid}</groupId>
+            <artifactId>${stax.impl.artifact}</artifactId>
+            <scope>test</scope>
+        </dependency>
        </dependencies>
        <build>
                <resources>
@@ -69,6 +74,14 @@
                                
<directory>${project.build.directory}/legal-files</directory>
                        </resource>
                </resources>
+        <testResources>
+            <testResource>
+                <directory>src/test/resources</directory>
+            </testResource>
+            <testResource>
+                
<directory>${project.build.directory}/generated-test-resources</directory>
+            </testResource>
+        </testResources>
                <plugins>
                        <plugin>
                                <artifactId>maven-antrun-plugin</artifactId>
@@ -92,6 +105,35 @@
                                        </execution>
                                </executions>
                        </plugin>
+            <plugin>
+                <groupId>org.apache.geronimo.genesis.plugins</groupId>
+                <artifactId>script-maven-plugin</artifactId>
+                <version>1.1</version>
+                <executions>
+                    <execution>
+                        <phase>generate-test-resources</phase>
+                        <goals>
+                            <goal>groovy</goal>
+                        </goals>
+                        <configuration>
+                            <source>
+                                <!-- This generates a list of the files in 
src/test/resources/conformance.
+                                     This is useful when loading these files 
from the classpath. -->
+                                <body>
+                                    def filelist = new 
File("${project.build.directory}/generated-test-resources/conformance/filelist");
+                                    filelist.parentFile.mkdirs();
+                                    filelist.delete();
+                                    new 
File("${basedir}/src/test/resources/conformance").eachFile({
+                                        if (it.file) {
+                                            filelist.append("$it.name\n");
+                                        }
+                                    })
+                                </body>
+                            </source>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
                        <plugin>
                                <groupId>org.apache.felix</groupId>
                                <artifactId>maven-bundle-plugin</artifactId>
@@ -130,7 +172,6 @@
                                <configuration>
                                        <includes>
                                                <include>**/*Test.java</include>
-                                               
<include>**/*TestCase.java</include>
                                        </includes>
                                </configuration>
                        </plugin>

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/stax/XMLFragmentStreamReader.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/stax/XMLFragmentStreamReader.java?rev=761900&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/stax/XMLFragmentStreamReader.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/stax/XMLFragmentStreamReader.java
 Sat Apr  4 11:01:55 2009
@@ -0,0 +1,434 @@
+/*
+ * 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.stax;
+
+import java.util.NoSuchElementException;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+/**
+ * Wrapping XML stream reader that reads a single element from the underlying 
stream.
+ * It will generate START_DOCUMENT and END_DOCUMENT events as required to make
+ * the sequence of events appear as a complete document.
+ * <p>
+ * Assume for example that the parent reader is parsing the following document:
+ * <pre>&lt;a>&lt;b>text&lt;/b>&lt;/a></pre>
+ * If the current event is <code>&lt;b></code> when the wrapper is created, it 
will produce
+ * the following sequence of events:
+ * <ul>
+ *   <li>A synthetic START_DOCUMENT event.</li>
+ *   <li>START_ELEMENT, CHARACTERS and END_ELEMENT events for 
<code>&lt;b>text&lt;/b></code>.
+ *       For these events, the wrapper directly delegates to the parent 
reader.</li>
+ *   <li>A synthetic END_DOCUMENT event.</li>
+ * </ul>
+ * After all events have been consumed from the wrapper, the current event on 
the parent reader
+ * will be the event following the last END_ELEMENT of the fragment. In the 
example above this
+ * will be <code>&lt;/a></code>.
+ */
+public class XMLFragmentStreamReader implements XMLStreamReader {
+    // The current event is a synthetic START_DOCUMENT event
+    private static final int STATE_START_DOCUMENT = 0;
+    
+    // The current event is from the fragment and there will be more events 
from the fragment
+    private static final int STATE_IN_FRAGMENT = 1;
+    
+    // The current event is the final END_ELEMENT event from the fragment
+    private static final int STATE_FRAGMENT_END = 2;
+    
+    // The current event is a synthetic END_DOCUMENT event
+    private static final int STATE_END_DOCUMENT = 3;
+    
+    private final XMLStreamReader parent;
+    private int state;
+    private int depth;
+    
+    /**
+     * Constructor.
+     * 
+     * @param parent the parent reader to read the fragment from
+     * @throws IllegalStateException if the current event on the parent is not 
a START_ELEMENT
+     */
+    public XMLFragmentStreamReader(XMLStreamReader parent) {
+        this.parent = parent;
+        if (parent.getEventType() != START_ELEMENT) {
+            throw new IllegalStateException("Expected START_ELEMENT as current 
event");
+        }
+    }
+
+    public int getEventType() {
+        switch (state) {
+            case STATE_START_DOCUMENT:
+                return START_DOCUMENT;
+            case STATE_IN_FRAGMENT:
+                return parent.getEventType();
+            case STATE_FRAGMENT_END:
+                return END_ELEMENT;
+            case STATE_END_DOCUMENT:
+                return END_DOCUMENT;
+            default:
+                // We will never get here; just make the compiler happy.
+                throw new IllegalStateException();
+        }
+    }
+
+    public int next() throws XMLStreamException {
+        switch (state) {
+            case STATE_START_DOCUMENT:
+                state = STATE_IN_FRAGMENT;
+                return START_ELEMENT;
+            case STATE_IN_FRAGMENT:
+                int type = parent.next();
+                switch (type) {
+                    case START_ELEMENT:
+                        depth++;
+                        break;
+                    case END_ELEMENT:
+                        if (depth == 0) {
+                            state = STATE_FRAGMENT_END;
+                        } else {
+                            depth--;
+                        }
+                }
+                return type;
+            case STATE_FRAGMENT_END:
+                // Consume the event from the parent to put the parser in a 
well-defined state
+                parent.next();
+                state = STATE_END_DOCUMENT;
+                return END_DOCUMENT;
+            default:
+                throw new NoSuchElementException("End of document reached");
+        }
+    }
+
+    public int nextTag() throws XMLStreamException {
+        switch (state) {
+            case STATE_START_DOCUMENT:
+                state = STATE_IN_FRAGMENT;
+                return START_ELEMENT;
+            case STATE_END_DOCUMENT:
+            case STATE_FRAGMENT_END:
+                throw new NoSuchElementException();
+            default:
+                int result = parent.nextTag();
+                switch (result) {
+                    case START_ELEMENT:
+                        depth++;
+                        break;
+                    case END_ELEMENT:
+                        if (depth == 0) {
+                            state = STATE_FRAGMENT_END;
+                        } else {
+                            depth--;
+                        }
+                }
+                return result;
+        }
+    }
+
+    public void close() throws XMLStreamException {
+        // TODO: not sure if we should always allow this!
+        parent.close();
+    }
+
+    public Object getProperty(String name) throws IllegalArgumentException {
+        return parent.getProperty(name);
+    }
+
+    public String getCharacterEncodingScheme() {
+        return "UTF-8";
+    }
+
+    public String getEncoding() {
+        return "UTF-8";
+    }
+
+    public String getVersion() {
+        return "1.0";
+    }
+    
+    public boolean isStandalone() {
+        return true;
+    }
+
+    public boolean standaloneSet() {
+        return false;
+    }
+
+    public Location getLocation() {
+        return parent.getLocation();
+    }
+
+    public int getAttributeCount() {
+        if (state == STATE_START_DOCUMENT || state == STATE_END_DOCUMENT) {
+            throw new IllegalStateException();
+        } else {
+            return parent.getAttributeCount();
+        }
+    }
+
+    public String getAttributeLocalName(int index) {
+        if (state == STATE_START_DOCUMENT || state == STATE_END_DOCUMENT) {
+            throw new IllegalStateException();
+        } else {
+            return parent.getAttributeLocalName(index);
+        }
+    }
+
+    public QName getAttributeName(int index) {
+        if (state == STATE_START_DOCUMENT || state == STATE_END_DOCUMENT) {
+            throw new IllegalStateException();
+        } else {
+            return parent.getAttributeName(index);
+        }
+    }
+
+    public String getAttributeNamespace(int index) {
+        if (state == STATE_START_DOCUMENT || state == STATE_END_DOCUMENT) {
+            throw new IllegalStateException();
+        } else {
+            return parent.getAttributeNamespace(index);
+        }
+    }
+
+    public String getAttributePrefix(int index) {
+        if (state == STATE_START_DOCUMENT || state == STATE_END_DOCUMENT) {
+            throw new IllegalStateException();
+        } else {
+            return parent.getAttributePrefix(index);
+        }
+    }
+
+    public String getAttributeType(int index) {
+        if (state == STATE_START_DOCUMENT || state == STATE_END_DOCUMENT) {
+            throw new IllegalStateException();
+        } else {
+            return parent.getAttributeType(index);
+        }
+    }
+
+    public String getAttributeValue(int index) {
+        if (state == STATE_START_DOCUMENT || state == STATE_END_DOCUMENT) {
+            throw new IllegalStateException();
+        } else {
+            return parent.getAttributeValue(index);
+        }
+    }
+
+    public boolean isAttributeSpecified(int index) {
+        if (state == STATE_START_DOCUMENT || state == STATE_END_DOCUMENT) {
+            throw new IllegalStateException();
+        } else {
+            return isAttributeSpecified(index);
+        }
+    }
+
+    public String getAttributeValue(String namespaceURI, String localName) {
+        if (state == STATE_START_DOCUMENT || state == STATE_END_DOCUMENT) {
+            throw new IllegalStateException();
+        } else {
+            return parent.getAttributeValue(namespaceURI, localName);
+        }
+    }
+
+    public String getElementText() throws XMLStreamException {
+        if (state == STATE_START_DOCUMENT || state == STATE_END_DOCUMENT) {
+            throw new IllegalStateException();
+        } else {
+            return parent.getElementText();
+        }
+    }
+
+    public String getLocalName() {
+        if (state == STATE_START_DOCUMENT || state == STATE_END_DOCUMENT) {
+            throw new IllegalStateException();
+        } else {
+            return parent.getLocalName();
+        }
+    }
+
+    public QName getName() {
+        if (state == STATE_START_DOCUMENT || state == STATE_END_DOCUMENT) {
+            throw new IllegalStateException();
+        } else {
+            return parent.getName();
+        }
+    }
+
+    public String getPrefix() {
+        if (state == STATE_START_DOCUMENT || state == STATE_END_DOCUMENT) {
+            throw new IllegalStateException();
+        } else {
+            return parent.getPrefix();
+        }
+    }
+
+    public String getNamespaceURI() {
+        if (state == STATE_START_DOCUMENT || state == STATE_END_DOCUMENT) {
+            throw new IllegalStateException();
+        } else {
+            return parent.getNamespaceURI();
+        }
+    }
+
+    public int getNamespaceCount() {
+        if (state == STATE_START_DOCUMENT || state == STATE_END_DOCUMENT) {
+            throw new IllegalStateException();
+        } else {
+            return parent.getNamespaceCount();
+        }
+    }
+
+    public String getNamespacePrefix(int index) {
+        if (state == STATE_START_DOCUMENT || state == STATE_END_DOCUMENT) {
+            throw new IllegalStateException();
+        } else {
+            return parent.getNamespacePrefix(index);
+        }
+    }
+
+    public String getNamespaceURI(int index) {
+        if (state == STATE_START_DOCUMENT || state == STATE_END_DOCUMENT) {
+            throw new IllegalStateException();
+        } else {
+            return parent.getNamespaceURI(index);
+        }
+    }
+
+    public String getNamespaceURI(String prefix) {
+        // TODO: It is not clear whether this method is allowed in all states.
+        //       The XMLStreamReader Javadoc suggest it is, but Woodstox 
doesn't
+        //       allow it on states other than START_ELEMENT and END_ELEMENT.
+        if (state == STATE_START_DOCUMENT || state == STATE_END_DOCUMENT) {
+            throw new IllegalStateException();
+        } else {
+            return parent.getNamespaceURI(prefix);
+        }
+    }
+
+    public NamespaceContext getNamespaceContext() {
+        return parent.getNamespaceContext();
+    }
+
+    public String getPIData() {
+        if (state == STATE_START_DOCUMENT || state == STATE_END_DOCUMENT) {
+            throw new IllegalStateException();
+        } else {
+            return parent.getPIData();
+        }
+    }
+
+    public String getPITarget() {
+        if (state == STATE_START_DOCUMENT || state == STATE_END_DOCUMENT) {
+            throw new IllegalStateException();
+        } else {
+            return parent.getPITarget();
+        }
+    }
+
+    public String getText() {
+        if (state == STATE_START_DOCUMENT || state == STATE_END_DOCUMENT) {
+            throw new IllegalStateException();
+        } else {
+            return parent.getText();
+        }
+    }
+
+    public char[] getTextCharacters() {
+        if (state == STATE_START_DOCUMENT || state == STATE_END_DOCUMENT) {
+            throw new IllegalStateException();
+        } else {
+            return parent.getTextCharacters();
+        }
+    }
+
+    public int getTextCharacters(int sourceStart, char[] target, int 
targetStart, int length)
+            throws XMLStreamException {
+        if (state == STATE_START_DOCUMENT || state == STATE_END_DOCUMENT) {
+            throw new IllegalStateException();
+        } else {
+            return getTextCharacters(sourceStart, target, targetStart, length);
+        }
+    }
+
+    public int getTextLength() {
+        if (state == STATE_START_DOCUMENT || state == STATE_END_DOCUMENT) {
+            throw new IllegalStateException();
+        } else {
+            return parent.getTextLength();
+        }
+    }
+
+    public int getTextStart() {
+        if (state == STATE_START_DOCUMENT || state == STATE_END_DOCUMENT) {
+            throw new IllegalStateException();
+        } else {
+            return parent.getTextStart();
+        }
+    }
+
+    public boolean hasName() {
+        return state != STATE_START_DOCUMENT && state != STATE_END_DOCUMENT && 
parent.hasName();
+    }
+
+    public boolean hasNext() throws XMLStreamException {
+        return state != STATE_END_DOCUMENT;
+    }
+
+    public boolean hasText() {
+        return state != STATE_START_DOCUMENT && state != STATE_END_DOCUMENT && 
parent.hasText();
+    }
+
+    public boolean isCharacters() {
+        return state != STATE_START_DOCUMENT && state != STATE_END_DOCUMENT && 
parent.isCharacters();
+    }
+
+    public boolean isStartElement() {
+        return state != STATE_START_DOCUMENT && state != STATE_END_DOCUMENT && 
parent.isStartElement();
+    }
+
+    public boolean isEndElement() {
+        return state != STATE_START_DOCUMENT && state != STATE_END_DOCUMENT && 
parent.isEndElement();
+    }
+
+    public boolean isWhiteSpace() {
+        return state != STATE_START_DOCUMENT && state != STATE_END_DOCUMENT && 
parent.isWhiteSpace();
+    }
+
+    public void require(int type, String namespaceURI, String localName) 
throws XMLStreamException {
+        switch (state) {
+            case STATE_START_DOCUMENT:
+                if (type != START_DOCUMENT) {
+                    throw new XMLStreamException("Expected START_DOCUMENT");
+                }
+                break;
+            case STATE_END_DOCUMENT:
+                if (type != END_DOCUMENT) {
+                    throw new XMLStreamException("Expected END_DOCUMENT");
+                }
+                break;
+            default:
+                parent.require(type, namespaceURI, localName);
+        }
+    }
+}

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/stax/XMLFragmentStreamReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/stax/XMLFragmentStreamReader.java
------------------------------------------------------------------------------
    svn:executable = *

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/stax/package.html
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/stax/package.html?rev=761900&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/stax/package.html
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/stax/package.html
 Sat Apr  4 11:01:55 2009
@@ -0,0 +1,5 @@
+<html>
+<body>
+Contains StAX utility classes not depending on the Axiom API. 
+</body>
+</html>
\ No newline at end of file

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/stax/package.html
------------------------------------------------------------------------------
    svn:executable = *

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/AbstractTestCase.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/AbstractTestCase.java?rev=761900&r1=761899&r2=761900&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/AbstractTestCase.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/AbstractTestCase.java
 Sat Apr  4 11:01:55 2009
@@ -19,9 +19,13 @@
 
 package org.apache.axiom.om;
 
+import java.io.BufferedReader;
 import java.io.File;
 import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
 
 import javax.activation.DataSource;
 import javax.activation.URLDataSource;
@@ -81,6 +85,19 @@
         }
         return in;
     }
+    
+    public static String[] getConformanceTestFiles() throws Exception {
+        BufferedReader in = new BufferedReader(new InputStreamReader(
+                AbstractTestCase.class.getClassLoader().getResourceAsStream(
+                        "conformance/filelist")));
+        String line;
+        List result = new ArrayList(10);
+        while ((line = in.readLine()) != null) {
+            result.add("conformance/" + line);
+        }
+        in.close();
+        return (String[])result.toArray(new String[result.size()]);
+    }
 
     public File getTempOutputFile(String filename) {
         File f = new File(tempDir);

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/OMStAXWrapperConformanceTestCase.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/OMStAXWrapperConformanceTestCase.java?rev=761900&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/OMStAXWrapperConformanceTestCase.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/OMStAXWrapperConformanceTestCase.java
 Sat Apr  4 11:01:55 2009
@@ -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.om.impl;
+
+import java.io.InputStream;
+
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestSuite;
+
+import org.apache.axiom.om.AbstractTestCase;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axiom.stax.XMLFragmentStreamReader;
+import org.apache.axiom.stax.XMLStreamReaderComparator;
+
+/**
+ * Test comparing the output of {...@link OMStAXWrapper} with that of a native 
StAX parser.
+ * {...@link #suite(OMMetaFactory)} can be used to build a complete test suite 
from the
+ * XML files returned by {...@link AbstractTestCase#getConformanceTestFiles()}.
+ */
+public class OMStAXWrapperConformanceTestCase extends AbstractTestCase {
+    private final OMMetaFactory omMetaFactory;
+    private final String file;
+    
+    private OMStAXWrapperConformanceTestCase(OMMetaFactory omMetaFactory, 
String name, String file) {
+        super(name);
+        this.omMetaFactory = omMetaFactory;
+        this.file = file;
+    }
+    
+    public void runTest() throws Throwable {
+        InputStream in1 = getTestResource(file);
+        InputStream in2 = getTestResource(file);
+        try {
+            XMLStreamReader expected = StAXUtils.createXMLStreamReader(in1);
+            expected.nextTag();
+            XMLStreamReader actual = new 
StAXOMBuilder(omMetaFactory.getOMFactory(),
+                    
StAXUtils.createXMLStreamReader(in2)).getDocumentElement().getXMLStreamReader();
+            new XMLStreamReaderComparator(new 
XMLFragmentStreamReader(expected), actual).compare();
+        } finally {
+            in1.close();
+            in2.close();
+        }
+    }
+
+    public static TestSuite suite(OMMetaFactory omMetaFactory) throws 
Exception {
+        TestSuite suite = new TestSuite();
+        String[] files = getConformanceTestFiles();
+        for (int i=0; i<files.length; i++) {
+            String file = files[i];
+            int idx = file.lastIndexOf('/');
+            String name = file.substring(idx+1);
+            suite.addTest(new OMStAXWrapperConformanceTestCase(omMetaFactory, 
name, file));
+        }
+        return suite;
+    }
+}

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/OMStAXWrapperConformanceTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/OMStAXWrapperTestBase.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/OMStAXWrapperTestBase.java?rev=761900&r1=761899&r2=761900&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/OMStAXWrapperTestBase.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/OMStAXWrapperTestBase.java
 Sat Apr  4 11:01:55 2009
@@ -20,7 +20,6 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
-import java.io.StringReader;
 import java.util.Arrays;
 
 import javax.xml.namespace.NamespaceContext;
@@ -37,7 +36,6 @@
 import org.apache.axiom.om.OMText;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axiom.om.util.AXIOMUtil;
-import org.apache.axiom.om.util.StAXUtils;
 
 public class OMStAXWrapperTestBase extends TestCase {
     protected final OMMetaFactory omMetaFactory;
@@ -202,18 +200,4 @@
     public void testGetNamespaceContextWithoutCaching() throws Exception {
         testGetNamespaceContext(false);
     }
-    
-    private void testWithComparator(String xml) throws Exception {
-        XMLStreamReader expected = StAXUtils.createXMLStreamReader(new 
StringReader(xml));
-        XMLStreamReader actual = 
AXIOMUtil.stringToOM(omMetaFactory.getOMFactory(), xml).getXMLStreamReader();
-        new XMLStreamReaderComparator(expected, actual).compare();
-    }
-    
-    public void testProcessingInstruction() throws Exception {
-        testWithComparator("<root><?pi data?></root>");
-    }
-    
-    public void testNamespaces() throws Exception {
-        testWithComparator("<a xmlns='urn:ns1' xmlns:ns2='urn:ns2' 
ns2:att='test'><ns2:b att='test'/></a>");
-    }
 }

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/stax/XMLFragmentStreamReaderTest.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/stax/XMLFragmentStreamReaderTest.java?rev=761900&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/stax/XMLFragmentStreamReaderTest.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/stax/XMLFragmentStreamReaderTest.java
 Sat Apr  4 11:01:55 2009
@@ -0,0 +1,46 @@
+/*
+ * 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.stax;
+
+import java.io.StringReader;
+
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.axiom.om.util.StAXUtils;
+
+public class XMLFragmentStreamReaderTest extends TestCase {
+    /**
+     * Test comparing the output of {...@link XMLFragmentStreamReader} with 
that
+     * of a native StAX parser. In particular this tests the behavior for 
START_DOCUMENT
+     * and END_DOCUMENT events.
+     * 
+     * @throws Exception
+     */
+    public void test() throws Exception {
+        String xml = "<ns:a xmlns:ns='urn:ns'>test</ns:a>";
+        XMLStreamReader expected = StAXUtils.createXMLStreamReader(new 
StringReader(xml));
+        XMLStreamReader reader = StAXUtils.createXMLStreamReader(new 
StringReader(xml));
+        reader.nextTag();
+        XMLStreamReader actual = new XMLFragmentStreamReader(reader);
+        new XMLStreamReaderComparator(expected, actual).compare();
+        assertEquals(XMLStreamReader.END_DOCUMENT, reader.getEventType());
+    }
+}

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/stax/XMLFragmentStreamReaderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/stax/XMLStreamReaderComparator.java
 (from r758915, 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/XMLStreamReaderComparator.java)
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/stax/XMLStreamReaderComparator.java?p2=webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/stax/XMLStreamReaderComparator.java&p1=webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/XMLStreamReaderComparator.java&r1=758915&r2=761900&rev=761900&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/XMLStreamReaderComparator.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/stax/XMLStreamReaderComparator.java
 Sat Apr  4 11:01:55 2009
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.axiom.om.impl;
+package org.apache.axiom.stax;
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
@@ -111,8 +111,8 @@
     public void compare() throws Exception {
         // Collect all prefixes seen in the document to be able to test 
getNamespaceURI(String)
         Set prefixes = new HashSet();
-        while (expected.next() != XMLStreamReader.END_DOCUMENT) {
-            actual.next();
+        do {
+            int eventType = 
((Integer)assertSameResult("getEventType")).intValue();
             Integer attributeCount = 
(Integer)assertSameResult("getAttributeCount");
             if (attributeCount != null) {
                 for (int i=0; i<attributeCount.intValue(); i++) {
@@ -164,13 +164,20 @@
             assertSameResult("isEndElement");
             assertSameResult("isStartElement");
             assertSameResult("isWhiteSpace");
-            for (Iterator it = prefixes.iterator(); it.hasNext(); ) {
-                String prefix = (String)it.next();
-                if (prefix != null) {
-                    assertSameResult("getNamespaceURI",
-                            new Class[] { String.class }, new Object[] { 
prefix });
+            
+            // Only check getNamespaceURI(String) for START_ELEMENT and 
END_ELEMENT. The Javadoc
+            // of XMLStreamReader suggests that this method is valid for all 
states, but Woodstox
+            // only allows it for some states.
+            if (eventType == XMLStreamReader.START_ELEMENT ||
+                    eventType == XMLStreamReader.END_ELEMENT) {
+                for (Iterator it = prefixes.iterator(); it.hasNext(); ) {
+                    String prefix = (String)it.next();
+                    if (prefix != null) {
+                        assertSameResult("getNamespaceURI",
+                                new Class[] { String.class }, new Object[] { 
prefix });
+                    }
                 }
             }
-        }
+        } while (assertSameResult("next") != null);
     }
 }

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/conformance/namespaces.xml
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/conformance/namespaces.xml?rev=761900&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/conformance/namespaces.xml
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/conformance/namespaces.xml
 Sat Apr  4 11:01:55 2009
@@ -0,0 +1,2 @@
+<?xml version="1.0"?>
+<a xmlns='urn:ns1' xmlns:ns2='urn:ns2' ns2:att='test'><ns2:b att='test'/></a>
\ No newline at end of file

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/conformance/namespaces.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/conformance/processingInstruction.xml
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/conformance/processingInstruction.xml?rev=761900&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/conformance/processingInstruction.xml
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/conformance/processingInstruction.xml
 Sat Apr  4 11:01:55 2009
@@ -0,0 +1,2 @@
+<?xml version="1.0"?>
+<root><?pi data?></root>

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/conformance/processingInstruction.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMStAXWrapperConformanceTest.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMStAXWrapperConformanceTest.java?rev=761900&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMStAXWrapperConformanceTest.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMStAXWrapperConformanceTest.java
 Sat Apr  4 11:01:55 2009
@@ -0,0 +1,31 @@
+/*
+ * 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.om.impl.dom;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.axiom.om.impl.OMStAXWrapperConformanceTestCase;
+import org.apache.axiom.om.impl.dom.factory.OMDOMMetaFactory;
+
+public class DOMStAXWrapperConformanceTest extends TestCase {
+    public static TestSuite suite() throws Exception {
+        return OMStAXWrapperConformanceTestCase.suite(new OMDOMMetaFactory());
+    }
+}

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMStAXWrapperConformanceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMStAXWrapperConformanceTest.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMStAXWrapperConformanceTest.java?rev=761900&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMStAXWrapperConformanceTest.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMStAXWrapperConformanceTest.java
 Sat Apr  4 11:01:55 2009
@@ -0,0 +1,31 @@
+/*
+ * 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.om.impl.llom;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.axiom.om.impl.OMStAXWrapperConformanceTestCase;
+import org.apache.axiom.om.impl.llom.factory.OMLinkedListMetaFactory;
+
+public class OMStAXWrapperConformanceTest extends TestCase {
+    public static TestSuite suite() throws Exception {
+        return OMStAXWrapperConformanceTestCase.suite(new 
OMLinkedListMetaFactory());
+    }
+}

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMStAXWrapperConformanceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to