Author: veithen
Date: Wed Mar 30 21:56:33 2011
New Revision: 1087099
URL: http://svn.apache.org/viewvc?rev=1087099&view=rev
Log:
Started to rationalize/generalize the test cases that validate the various
serialization methods. This also reveals two new issues with the
serialize(OutputStream) method when called on an OMDocument.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/OMContainerFactory.java
(with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/OMElementFactory.java
(with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/SerializationMethod.java
(with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/SerializeToOutputStream.java
(with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestGetXMLStreamReader.java
- copied, changed from r1087047,
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/GetXMLStreamReaderTestCase.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestSerialize.java
- copied, changed from r1087047,
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerializeToOutputStream.java
Removed:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/GetXMLStreamReaderTestCase.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/TestGetXMLStreamReader.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReader.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerializeToOutputStream.java
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestCase.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestSuiteBuilder.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/ConformanceTestCase.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderGetNamespaceContext.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderOnNonRootElement.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerialization.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/factory/TestCreateOMElement.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/node/TestDetach.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestCase.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/headerblock/TestSetMustUnderstandBoolean.java
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestCase.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestCase.java?rev=1087099&r1=1087098&r2=1087099&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestCase.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestCase.java
Wed Mar 30 21:56:33 2011
@@ -18,6 +18,10 @@
*/
package org.apache.axiom.ts;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
import org.apache.axiom.om.OMContainer;
import org.apache.axiom.om.OMMetaFactory;
import org.apache.commons.io.output.NullOutputStream;
@@ -25,12 +29,22 @@ import org.custommonkey.xmlunit.XMLTestC
public abstract class AxiomTestCase extends XMLTestCase {
protected final OMMetaFactory metaFactory;
+ private final Map/*<String,String>*/ properties = new HashMap();
public AxiomTestCase(OMMetaFactory metaFactory) {
this.metaFactory = metaFactory;
setName(getClass().getName());
}
+ public void addTestProperty(String name, String value) {
+ setName(getName() + " [" + name + "=" + value + "]");
+ properties.put(name, value);
+ }
+
+ public Map getTestProperties() {
+ return Collections.unmodifiableMap(properties);
+ }
+
protected void assertConsumed(OMContainer container) {
assertFalse("Expected the node to be incomplete",
container.isComplete());
boolean isConsumed;
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestSuiteBuilder.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestSuiteBuilder.java?rev=1087099&r1=1087098&r2=1087099&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestSuiteBuilder.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestSuiteBuilder.java
Wed Mar 30 21:56:33 2011
@@ -19,11 +19,13 @@
package org.apache.axiom.ts;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
import junit.framework.TestSuite;
import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.ts.om.container.TestSerialize;
public abstract class AxiomTestSuiteBuilder {
protected final OMMetaFactory metaFactory;
@@ -48,6 +50,19 @@ public abstract class AxiomTestSuiteBuil
protected final void addTest(AxiomTestCase test) {
if (!excludedTests.contains(test.getClass())) {
+ // TODO: quick & dirty hack; need to implement a generic way to
exclude tests based on properties
+ if (test instanceof TestSerialize) {
+ Map props = test.getTestProperties();
+ if (props.get("file").equals("iso-8859-1.xml") &&
props.get("container").equals("document")) {
+ // TODO: this case is not working because Axiom generates
an XML declaration
+ // but uses another charset encoding to serialize
the document
+ return;
+ }
+ if (props.get("file").equals("spaces.xml") &&
props.get("container").equals("document")) {
+ // TODO: this case is not working because Axiom doesn't
serialize the DTD
+ return;
+ }
+ }
suite.addTest(test);
}
}
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/ConformanceTestCase.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/ConformanceTestCase.java?rev=1087099&r1=1087098&r2=1087099&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/ConformanceTestCase.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/ConformanceTestCase.java
Wed Mar 30 21:56:33 2011
@@ -35,7 +35,7 @@ public abstract class ConformanceTestCas
super(metaFactory);
this.file = file;
int idx = file.lastIndexOf('/');
- setName(getName() + " [file=" + file.substring(idx+1) + "]");
+ addTestProperty("file", file.substring(idx+1));
}
protected InputStream getFileAsStream() {
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java?rev=1087099&r1=1087098&r2=1087099&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java
Wed Mar 30 21:56:33 2011
@@ -20,9 +20,22 @@ package org.apache.axiom.ts;
import org.apache.axiom.om.AbstractTestCase;
import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.ts.om.container.OMContainerFactory;
+import org.apache.axiom.ts.om.container.OMElementFactory;
+import org.apache.axiom.ts.om.container.SerializationMethod;
+import org.apache.axiom.ts.om.container.SerializeToOutputStream;
import org.apache.axiom.ts.om.factory.OMElementCreator;
public class OMTestSuiteBuilder extends AxiomTestSuiteBuilder {
+ private static final OMContainerFactory[] containerFactories = {
+ OMContainerFactory.DOCUMENT,
+ new OMElementFactory(false),
+ new OMElementFactory(true) };
+
+ private static final SerializationMethod[] serializationMethods = {
+ new SerializeToOutputStream(true),
+ new SerializeToOutputStream(false) };
+
public OMTestSuiteBuilder(OMMetaFactory metaFactory) {
super(metaFactory);
}
@@ -35,8 +48,13 @@ public class OMTestSuiteBuilder extends
addTest(new
org.apache.axiom.ts.om.builder.TestGetDocumentElement(metaFactory));
addTest(new
org.apache.axiom.ts.om.builder.TestGetDocumentElementWithDiscardDocument(metaFactory));
for (int i=0; i<conformanceFiles.length; i++) {
- addTest(new
org.apache.axiom.ts.om.document.TestGetXMLStreamReader(metaFactory,
conformanceFiles[i], true));
- addTest(new
org.apache.axiom.ts.om.document.TestGetXMLStreamReader(metaFactory,
conformanceFiles[i], false));
+ for (int j=0; j<containerFactories.length; j++) {
+ addTest(new
org.apache.axiom.ts.om.container.TestGetXMLStreamReader(metaFactory,
conformanceFiles[i], containerFactories[j], true));
+ addTest(new
org.apache.axiom.ts.om.container.TestGetXMLStreamReader(metaFactory,
conformanceFiles[i], containerFactories[j], false));
+ for (int k=0; k<serializationMethods.length; k++) {
+ addTest(new
org.apache.axiom.ts.om.container.TestSerialize(metaFactory,
conformanceFiles[i], containerFactories[j], serializationMethods[k]));
+ }
+ }
}
addTest(new
org.apache.axiom.ts.om.document.TestIsCompleteAfterAddingIncompleteChild(metaFactory));
addTest(new
org.apache.axiom.ts.om.document.TestSerializeAndConsume(metaFactory));
@@ -72,12 +90,6 @@ public class OMTestSuiteBuilder extends
addTest(new
org.apache.axiom.ts.om.element.TestGetFirstChildWithName(metaFactory));
addTest(new
org.apache.axiom.ts.om.element.TestGetFirstChildWithNameOnIncompleteElement(metaFactory));
addTest(new
org.apache.axiom.ts.om.element.TestGetQNameWithoutNamespace(metaFactory));
- for (int i=0; i<conformanceFiles.length; i++) {
- addTest(new
org.apache.axiom.ts.om.element.TestGetXMLStreamReader(metaFactory,
conformanceFiles[i], true, false));
- addTest(new
org.apache.axiom.ts.om.element.TestGetXMLStreamReader(metaFactory,
conformanceFiles[i], false, false));
- addTest(new
org.apache.axiom.ts.om.element.TestGetXMLStreamReader(metaFactory,
conformanceFiles[i], true, true));
- addTest(new
org.apache.axiom.ts.om.element.TestGetXMLStreamReader(metaFactory,
conformanceFiles[i], false, true));
- }
addTest(new
org.apache.axiom.ts.om.element.TestGetXMLStreamReaderCDATAEventFromElement(metaFactory));
addTest(new
org.apache.axiom.ts.om.element.TestGetXMLStreamReaderCDATAEventFromParser(metaFactory));
addTest(new
org.apache.axiom.ts.om.element.TestGetXMLStreamReaderCommentEvent(metaFactory));
@@ -112,10 +124,6 @@ public class OMTestSuiteBuilder extends
"<person><name xmlns=\"urn:ns\">John</name><age
xmlns=\"urn:ns\">34</age><weight xmlns=\"urn:ns\">50</weight></person>"));
addTest(new
org.apache.axiom.ts.om.element.TestSerializationWithTwoNonBuiltOMElements(metaFactory));
addTest(new
org.apache.axiom.ts.om.element.TestSerializeAndConsumeWithIncompleteDescendant(metaFactory));
- for (int i=0; i<conformanceFiles.length; i++) {
- addTest(new
org.apache.axiom.ts.om.element.TestSerializeToOutputStream(metaFactory,
conformanceFiles[i], true));
- addTest(new
org.apache.axiom.ts.om.element.TestSerializeToOutputStream(metaFactory,
conformanceFiles[i], false));
- }
addTest(new org.apache.axiom.ts.om.element.TestSetText(metaFactory));
addTest(new
org.apache.axiom.ts.om.element.TestSetTextQName(metaFactory));
for (int i=0; i<OMElementCreator.INSTANCES.length; i++) {
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/OMContainerFactory.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/OMContainerFactory.java?rev=1087099&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/OMContainerFactory.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/OMContainerFactory.java
Wed Mar 30 21:56:33 2011
@@ -0,0 +1,57 @@
+/*
+ * 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.ts.om.container;
+
+import java.io.InputStream;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.impl.RootWhitespaceFilter;
+import org.apache.axiom.ts.AxiomTestCase;
+import org.xml.sax.InputSource;
+
+/**
+ * Prepares {@link OMContainer} instances from a test file.
+ */
+public interface OMContainerFactory {
+ OMContainerFactory DOCUMENT = new OMContainerFactory() {
+ public void addTestProperties(AxiomTestCase testCase) {
+ testCase.addTestProperty("container", "document");
+ }
+
+ public InputSource getControl(InputStream testFileContent) {
+ return new InputSource(testFileContent);
+ }
+
+ public OMContainer getContainer(OMXMLParserWrapper builder) {
+ return builder.getDocument();
+ }
+
+ public XMLStreamReader filter(XMLStreamReader reader) {
+ return new RootWhitespaceFilter(reader);
+ }
+ };
+
+ void addTestProperties(AxiomTestCase testCase);
+ InputSource getControl(InputStream testFileContent) throws Exception;
+ OMContainer getContainer(OMXMLParserWrapper builder);
+ XMLStreamReader filter(XMLStreamReader reader);
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/OMContainerFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/OMElementFactory.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/OMElementFactory.java?rev=1087099&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/OMElementFactory.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/OMElementFactory.java
Wed Mar 30 21:56:33 2011
@@ -0,0 +1,71 @@
+/*
+ * 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.ts.om.container;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.impl.DocumentElementExtractor;
+import org.apache.axiom.ts.AxiomTestCase;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+
+public class OMElementFactory implements OMContainerFactory {
+ private final boolean detached;
+
+ public OMElementFactory(boolean detached) {
+ this.detached = detached;
+ }
+
+ public void addTestProperties(AxiomTestCase testCase) {
+ testCase.addTestProperty("container", "element");
+ testCase.addTestProperty("detached", Boolean.toString(detached));
+ }
+
+ public InputSource getControl(InputStream testFileContent) throws
Exception {
+ try {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ Document doc = dbf.newDocumentBuilder().parse(testFileContent);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ TransformerFactory.newInstance().newTransformer().transform(
+ new DOMSource(doc.getDocumentElement()), new
StreamResult(baos));
+ return new InputSource(new
ByteArrayInputStream(baos.toByteArray()));
+ } finally {
+ testFileContent.close();
+ }
+ }
+
+ public OMContainer getContainer(OMXMLParserWrapper builder) {
+ return builder.getDocumentElement(detached);
+ }
+
+ public XMLStreamReader filter(XMLStreamReader reader) {
+ return new DocumentElementExtractor(reader);
+ }
+};
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/OMElementFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/SerializationMethod.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/SerializationMethod.java?rev=1087099&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/SerializationMethod.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/SerializationMethod.java
Wed Mar 30 21:56:33 2011
@@ -0,0 +1,29 @@
+/*
+ * 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.ts.om.container;
+
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.ts.AxiomTestCase;
+import org.xml.sax.InputSource;
+
+public interface SerializationMethod {
+ void addTestProperties(AxiomTestCase testCase);
+ InputSource serialize(OMContainer container) throws Exception;
+ boolean isCaching();
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/SerializationMethod.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/SerializeToOutputStream.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/SerializeToOutputStream.java?rev=1087099&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/SerializeToOutputStream.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/SerializeToOutputStream.java
Wed Mar 30 21:56:33 2011
@@ -0,0 +1,52 @@
+/*
+ * 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.ts.om.container;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.ts.AxiomTestCase;
+import org.xml.sax.InputSource;
+
+public class SerializeToOutputStream implements SerializationMethod {
+ private final boolean cache;
+
+ public SerializeToOutputStream(boolean cache) {
+ this.cache = cache;
+ }
+
+ public void addTestProperties(AxiomTestCase testCase) {
+ testCase.addTestProperty("method", cache ? "serialize" :
"serializeAndConsume");
+ }
+
+ public InputSource serialize(OMContainer container) throws Exception {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ if (cache) {
+ container.serialize(baos);
+ } else {
+ container.serializeAndConsume(baos);
+ }
+ return new InputSource(new ByteArrayInputStream(baos.toByteArray()));
+ }
+
+ public boolean isCaching() {
+ return cache;
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/SerializeToOutputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestGetXMLStreamReader.java
(from r1087047,
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/GetXMLStreamReaderTestCase.java)
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestGetXMLStreamReader.java?p2=webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestGetXMLStreamReader.java&p1=webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/GetXMLStreamReaderTestCase.java&r1=1087047&r2=1087099&rev=1087099&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/GetXMLStreamReaderTestCase.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestGetXMLStreamReader.java
Wed Mar 30 21:56:33 2011
@@ -34,13 +34,16 @@ import org.apache.axiom.ts.ConformanceTe
* Test comparing the output of {@link
OMContainer#getXMLStreamReader(boolean)} with that of a
* native StAX parser.
*/
-public abstract class GetXMLStreamReaderTestCase extends ConformanceTestCase {
+public class TestGetXMLStreamReader extends ConformanceTestCase {
+ private final OMContainerFactory containerFactory;
private final boolean cache;
- public GetXMLStreamReaderTestCase(OMMetaFactory metaFactory, String file,
boolean cache) {
+ public TestGetXMLStreamReader(OMMetaFactory metaFactory, String file,
OMContainerFactory containerFactory, boolean cache) {
super(metaFactory, file);
+ this.containerFactory = containerFactory;
this.cache = cache;
- setName(getName() + " [cache=" + cache + "]");
+ containerFactory.addTestProperties(this);
+ addTestProperty("cache", Boolean.toString(cache));
}
protected final void runTest() throws Throwable {
@@ -51,8 +54,8 @@ public abstract class GetXMLStreamReader
try {
OMXMLParserWrapper builder =
OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), in2);
try {
- XMLStreamReader actual =
getContainer(builder).getXMLStreamReader(cache);
- new XMLStreamReaderComparator(filter(expected),
filter(actual)).compare();
+ XMLStreamReader actual =
containerFactory.getContainer(builder).getXMLStreamReader(cache);
+ new
XMLStreamReaderComparator(containerFactory.filter(expected),
containerFactory.filter(actual)).compare();
} finally {
builder.close();
}
@@ -64,7 +67,4 @@ public abstract class GetXMLStreamReader
in2.close();
}
}
-
- protected abstract OMContainer getContainer(OMXMLParserWrapper builder);
- protected abstract XMLStreamReader filter(XMLStreamReader reader);
}
Copied:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestSerialize.java
(from r1087047,
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerializeToOutputStream.java)
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestSerialize.java?p2=webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestSerialize.java&p1=webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerializeToOutputStream.java&r1=1087047&r2=1087099&rev=1087099&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerializeToOutputStream.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestSerialize.java
Wed Mar 30 21:56:33 2011
@@ -16,81 +16,62 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.axiom.ts.om.element;
+package org.apache.axiom.ts.om.container;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.io.InputStream;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-
import junit.framework.AssertionFailedError;
-import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMContainer;
import org.apache.axiom.om.OMMetaFactory;
import org.apache.axiom.om.OMXMLBuilderFactory;
import org.apache.axiom.om.OMXMLParserWrapper;
import org.apache.axiom.om.util.StAXParserConfiguration;
import org.apache.axiom.ts.ConformanceTestCase;
-import org.w3c.dom.Document;
+import org.apache.commons.io.IOUtils;
import org.xml.sax.InputSource;
-public class TestSerializeToOutputStream extends ConformanceTestCase {
- private final boolean cache;
+public class TestSerialize extends ConformanceTestCase {
+ private final OMContainerFactory containerFactory;
+ private final SerializationMethod serializationMethod;
- public TestSerializeToOutputStream(OMMetaFactory metaFactory, String file,
boolean cache) {
+ public TestSerialize(OMMetaFactory metaFactory, String file,
+ OMContainerFactory containerFactory, SerializationMethod
serializationMethod) {
super(metaFactory, file);
- this.cache = cache;
- setName(getName() + " [cache=" + cache + "]");
+ this.containerFactory = containerFactory;
+ this.serializationMethod = serializationMethod;
+ containerFactory.addTestProperties(this);
+ serializationMethod.addTestProperties(this);
}
protected void runTest() throws Throwable {
InputStream in = getFileAsStream();
- byte[] control;
- try {
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- dbf.setNamespaceAware(true);
- Document doc = dbf.newDocumentBuilder().parse(in);
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- TransformerFactory.newInstance().newTransformer().transform(
- new DOMSource(doc.getDocumentElement()), new
StreamResult(baos));
- control = baos.toByteArray();
- } finally {
- in.close();
- }
- in = getFileAsStream();
try {
OMXMLParserWrapper builder =
OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(),
StAXParserConfiguration.PRESERVE_CDATA_SECTIONS, in);
try {
- OMElement element = builder.getDocumentElement();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- if (cache) {
- element.serialize(baos);
- } else {
- element.serializeAndConsume(baos);
- }
- byte[] actual = baos.toByteArray();
+ OMContainer container = containerFactory.getContainer(builder);
+ // We need to clone the InputSource objects so that we can
dump their contents
+ // if the test fails
+ InputSource control[] =
duplicateInputSource(containerFactory.getControl(getFileAsStream()));
+ InputSource actual[] =
duplicateInputSource(serializationMethod.serialize(container));
try {
- assertXMLIdentical(compareXML(new InputSource(new
ByteArrayInputStream(control)),
- new InputSource(new
ByteArrayInputStream(actual))), true);
+ assertXMLIdentical(compareXML(control[0], actual[0]),
true);
} catch (AssertionFailedError ex) {
System.out.println("Control:");
- System.out.write(control);
- System.out.println();
+ dumpInputSource(control[1]);
System.out.println("Actual:");
- System.out.write(actual);
- System.out.println();
+ dumpInputSource(actual[1]);
throw ex;
}
- if (cache) {
- assertTrue(element.isComplete());
+ if (serializationMethod.isCaching()) {
+ assertTrue(container.isComplete());
} else {
// TODO: need to investigate why assertConsumed is not
working here
- assertFalse(element.isComplete());
+ assertFalse(container.isComplete());
// assertConsumed(element);
}
} finally {
@@ -100,4 +81,19 @@ public class TestSerializeToOutputStream
in.close();
}
}
+
+ private InputSource[] duplicateInputSource(InputSource is) throws
IOException {
+ // TODO: also handle character streams
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ IOUtils.copy(is.getByteStream(), baos);
+ byte[] content = baos.toByteArray();
+ return new InputSource[] { new InputSource(new
ByteArrayInputStream(content)),
+ new InputSource(new ByteArrayInputStream(content)) };
+ }
+
+ private void dumpInputSource(InputSource is) throws IOException {
+ // TODO: also handle character streams
+ IOUtils.copy(is.getByteStream(), System.out);
+ System.out.println();
+ }
}
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderGetNamespaceContext.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderGetNamespaceContext.java?rev=1087099&r1=1087098&r2=1087099&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderGetNamespaceContext.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderGetNamespaceContext.java
Wed Mar 30 21:56:33 2011
@@ -32,7 +32,7 @@ public class TestGetXMLStreamReaderGetNa
public TestGetXMLStreamReaderGetNamespaceContext(OMMetaFactory
metaFactory, boolean cache) {
super(metaFactory);
this.cache = cache;
- setName(getName() + " [cache=" + cache + "]");
+ addTestProperty("cache", Boolean.toString(cache));
}
protected void runTest() throws Throwable {
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderOnNonRootElement.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderOnNonRootElement.java?rev=1087099&r1=1087098&r2=1087099&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderOnNonRootElement.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderOnNonRootElement.java
Wed Mar 30 21:56:33 2011
@@ -31,7 +31,7 @@ public class TestGetXMLStreamReaderOnNon
public TestGetXMLStreamReaderOnNonRootElement(OMMetaFactory metaFactory,
boolean cache) {
super(metaFactory);
this.cache = cache;
- setName(getName() + " [cache=" + cache + "]");
+ addTestProperty("cache", Boolean.toString(cache));
}
protected void runTest() throws Throwable {
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerialization.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerialization.java?rev=1087099&r1=1087098&r2=1087099&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerialization.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerialization.java
Wed Mar 30 21:56:33 2011
@@ -54,7 +54,8 @@ public class TestSerialization extends A
this.parent = parent;
this.children = children;
this.expected = expected;
- setName(getName() + " [parent=" + parent + ",children=" + children +
"]");
+ addTestProperty("parent", parent);
+ addTestProperty("children", children);
}
private static OMNamespace createNamespace(OMFactory factory, String type)
{
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/factory/TestCreateOMElement.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/factory/TestCreateOMElement.java?rev=1087099&r1=1087098&r2=1087099&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/factory/TestCreateOMElement.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/factory/TestCreateOMElement.java
Wed Mar 30 21:56:33 2011
@@ -34,7 +34,7 @@ public class TestCreateOMElement extends
public TestCreateOMElement(OMMetaFactory metaFactory, OMElementCreator
variant) {
super(metaFactory);
this.variant = variant;
- setName(getName() + " [variant=" + variant.getName() + "]");
+ addTestProperty("variant", variant.getName());
}
protected void runTest() throws Throwable {
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/node/TestDetach.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/node/TestDetach.java?rev=1087099&r1=1087098&r2=1087099&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/node/TestDetach.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/node/TestDetach.java
Wed Mar 30 21:56:33 2011
@@ -33,7 +33,7 @@ public class TestDetach extends AxiomTes
public TestDetach(OMMetaFactory metaFactory, boolean build) {
super(metaFactory);
this.build = build;
- setName(getName() + " [build=" + build + "]");
+ addTestProperty("build", Boolean.toString(build));
}
protected void runTest() throws Throwable {
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestCase.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestCase.java?rev=1087099&r1=1087098&r2=1087099&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestCase.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestCase.java
Wed Mar 30 21:56:33 2011
@@ -42,7 +42,7 @@ public class SOAPTestCase extends AxiomT
public SOAPTestCase(OMMetaFactory metaFactory, SOAPSpec spec) {
super(metaFactory);
this.spec = spec;
- setName(getName() + " [" + spec.getName() + "]");
+ addTestProperty("spec", spec.getName());
}
protected void setUp() throws Exception {
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/headerblock/TestSetMustUnderstandBoolean.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/headerblock/TestSetMustUnderstandBoolean.java?rev=1087099&r1=1087098&r2=1087099&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/headerblock/TestSetMustUnderstandBoolean.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/headerblock/TestSetMustUnderstandBoolean.java
Wed Mar 30 21:56:33 2011
@@ -34,7 +34,7 @@ public class TestSetMustUnderstandBoolea
public TestSetMustUnderstandBoolean(OMMetaFactory metaFactory, SOAPSpec
spec, boolean value, String stringValue) {
super(metaFactory, spec);
- setName(getName() + " [value=" + value + "]");
+ addTestProperty("value", Boolean.toString(value));
this.value = value;
this.stringValue = stringValue;
}