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 2010/09/30 09:27:31 UTC
svn commit: r1002955 - in
/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test:
java/org/apache/axiom/om/ java/org/apache/axiom/util/stax/dialect/
resources/org/apache/axiom/util/stax/dialect/
Author: veithen
Date: Thu Sep 30 07:27:31 2010
New Revision: 1002955
URL: http://svn.apache.org/viewvc?rev=1002955&view=rev
Log:
Added some more dialect tests checking the behavior of the NamespaceContext returned by XMLStreamReader#getNamespaceContext(). This in particular provides evidence for an issue in XLXP2.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/GetNamespaceContextTestCase.java (with props)
Removed:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/MaskedNamespaceTestCase.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/org/apache/axiom/util/stax/dialect/masked_namespace.xml
Modified:
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/util/stax/dialect/DialectTest.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTestCase.java
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=1002955&r1=1002954&r2=1002955&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 Thu Sep 30 07:27:31 2010
@@ -21,6 +21,7 @@ package org.apache.axiom.om;
import java.io.BufferedReader;
import java.io.File;
+import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
@@ -102,17 +103,22 @@ public abstract class AbstractTestCase
}
}
- 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);
+ public static String[] getConformanceTestFiles() {
+ try {
+ 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()]);
+ } catch (IOException ex) {
+ fail("Unable to load file list: " + ex.getMessage());
+ return null; // Make compiler happy
}
- in.close();
- return (String[])result.toArray(new String[result.size()]);
}
public File getTempOutputFile(String filename) {
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java?rev=1002955&r1=1002954&r2=1002955&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java Thu Sep 30 07:27:31 2010
@@ -25,6 +25,8 @@ import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamConstants;
+import org.apache.axiom.om.AbstractTestCase;
+
import junit.framework.TestSuite;
public class DialectTest extends TestSuite {
@@ -36,6 +38,7 @@ public class DialectTest extends TestSui
super(name);
this.classLoader = classLoader;
this.props = props;
+ String[] conformanceTestFiles = AbstractTestCase.getConformanceTestFiles();
addDialectTest(new CreateXMLEventWriterWithNullEncodingTestCase());
addDialectTest(new CreateXMLStreamReaderThreadSafetyTestCase());
addDialectTest(new CreateXMLStreamWriterThreadSafetyTestCase());
@@ -85,6 +88,9 @@ public class DialectTest extends TestSui
addDialectTest(new GetNameIllegalStateExceptionTestCase(XMLStreamConstants.DTD, true));
addDialectTest(new GetNameIllegalStateExceptionTestCase(XMLStreamConstants.CDATA, true));
addDialectTest(new GetNamespaceContextImplicitNamespacesTestCase());
+ for (int i=0; i<conformanceTestFiles.length; i++) {
+ addDialectTest(new GetNamespaceContextTestCase(conformanceTestFiles[i]));
+ }
addDialectTest(new GetNamespaceURIIllegalStateExceptionTestCase(XMLStreamConstants.START_ELEMENT, false));
addDialectTest(new GetNamespaceURIIllegalStateExceptionTestCase(XMLStreamConstants.END_ELEMENT, false));
addDialectTest(new GetNamespaceURIIllegalStateExceptionTestCase(XMLStreamConstants.PROCESSING_INSTRUCTION, true));
@@ -149,7 +155,6 @@ public class DialectTest extends TestSui
addDialectTest(new IsCharactersTestCase(XMLStreamConstants.DTD, false));
addDialectTest(new IsCharactersTestCase(XMLStreamConstants.CDATA, false));
addDialectTest(new IsStandaloneTestCase());
- addDialectTest(new MaskedNamespaceTestCase());
addDialectTest(new NextAfterEndDocumentTestCase());
addDialectTest(new SetPrefixScopeTestCase());
addDialectTest(new StandaloneSetTestCase());
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTestCase.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTestCase.java?rev=1002955&r1=1002954&r2=1002955&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTestCase.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTestCase.java Thu Sep 30 07:27:31 2010
@@ -21,9 +21,9 @@ package org.apache.axiom.util.stax.diale
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
-import junit.framework.TestCase;
+import org.apache.axiom.om.AbstractTestCase;
-public abstract class DialectTestCase extends TestCase {
+public abstract class DialectTestCase extends AbstractTestCase {
private DialectTest test;
void init(DialectTest test) {
Added: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/GetNamespaceContextTestCase.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/GetNamespaceContextTestCase.java?rev=1002955&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/GetNamespaceContextTestCase.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/GetNamespaceContextTestCase.java Thu Sep 30 07:27:31 2010
@@ -0,0 +1,118 @@
+/*
+ * 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.InputStream;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.util.namespace.ScopedNamespaceContext;
+
+public class GetNamespaceContextTestCase extends DialectTestCase {
+ private final String testResource;
+
+ public GetNamespaceContextTestCase(String testResource) {
+ this.testResource = testResource;
+ setName(getClass().getName() + " [" + testResource + "]");
+ }
+
+ // Copy & paste from XMLStreamReaderComparator
+ private Set toPrefixSet(Iterator it) {
+ Set set = new HashSet();
+ while (it.hasNext()) {
+ String prefix = (String)it.next();
+ // TODO: Woodstox returns null instead of "" for the default namespace.
+ // This seems incorrect, but the javax.namespace.NamespaceContext specs are
+ // not very clear.
+ set.add(prefix == null ? "" : prefix);
+ }
+ return set;
+ }
+
+ protected void runTest() throws Throwable {
+ XMLInputFactory factory = newNormalizedXMLInputFactory();
+ InputStream in = getTestResource(testResource);
+ Set/*<String>*/ prefixes = new HashSet();
+ Set/*<String>*/ namespaceURIs = new HashSet();
+ prefixes.add("");
+ try {
+ ScopedNamespaceContext refNc = new ScopedNamespaceContext();
+ XMLStreamReader reader = factory.createXMLStreamReader(in);
+ int depth = 0;
+ int eventType;
+ while ((eventType = reader.getEventType()) != XMLStreamReader.END_DOCUMENT) {
+ if (eventType == XMLStreamReader.START_ELEMENT) {
+ refNc.startScope();
+ for (int i=0; i<reader.getNamespaceCount(); i++) {
+ String prefix = reader.getNamespacePrefix(i);
+ String uri = reader.getNamespaceURI(i);
+ refNc.setPrefix(prefix == null ? "" : prefix,
+ uri == null ? "" : uri);
+ if (prefix != null) {
+ prefixes.add(prefix);
+ }
+ if (uri != null && uri.length() > 0) {
+ namespaceURIs.add(uri);
+ }
+ }
+ depth++;
+ }
+ if (depth > 0) {
+ NamespaceContext nc = reader.getNamespaceContext();
+ for (Iterator it = prefixes.iterator(); it.hasNext(); ) {
+ String prefix = (String)it.next();
+ String expectedUri = refNc.getNamespaceURI(prefix);
+ String actualUri = nc.getNamespaceURI(prefix);
+ // TODO: this needs to be clarified
+ if (expectedUri == null) {
+ expectedUri = "";
+ }
+ if (actualUri == null) {
+ actualUri = "";
+ }
+ assertEquals("Namespace URI for prefix '" + prefix + "'", expectedUri, actualUri);
+ }
+ for (Iterator it = namespaceURIs.iterator(); it.hasNext(); ) {
+ String namespaceURI = (String)it.next();
+ assertEquals(
+ "Prefix for namespace URI '" + namespaceURI + "'",
+ refNc.getPrefix(namespaceURI),
+ nc.getPrefix(namespaceURI));
+ assertEquals(
+ "Prefixes for namespace URI '" + namespaceURI + "'",
+ toPrefixSet(refNc.getPrefixes(namespaceURI)),
+ toPrefixSet(nc.getPrefixes(namespaceURI)));
+ }
+ }
+ if (eventType == XMLStreamReader.END_ELEMENT) {
+ refNc.endScope();
+ depth--;
+ }
+ reader.next();
+ }
+ } finally {
+ in.close();
+ }
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/GetNamespaceContextTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native