Author: veithen
Date: Thu Mar 31 20:51:42 2011
New Revision: 1087432
URL: http://svn.apache.org/viewvc?rev=1087432&view=rev
Log:
AXIOM-311: Refactored a couple of other test cases.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestIOExceptionInGetText.java
(with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestInvalidXML.java
(with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestAddAttributeFromOMAttributeMultiple.java
(with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/resources/invalid_xml.xml
- copied unchanged from r1087408,
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/resources/invalid_xml.xml
Removed:
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/resources/invalid_xml.xml
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/AttrNsTest.java
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/builder/StAXOMBuilderTest.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/AttrNsTest.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/AttrNsTest.java?rev=1087432&r1=1087431&r2=1087432&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/AttrNsTest.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/AttrNsTest.java
Thu Mar 31 20:51:42 2011
@@ -23,36 +23,8 @@ import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.XMLTestCase;
import java.io.StringReader;
-import java.util.Iterator;
public class AttrNsTest extends XMLTestCase {
- public void testAttributesWithProgrammaticalCreation() throws Exception {
- String expectedXML =
- "<AttributeTester xmlns=\"\"
xmlns:myAttr2NS=\"http://test-attributes-2.org\" " +
- "xmlns:myAttr1NS=\"http://test-attributes-1.org\"
myAttr2NS:attrNumber=\"2\" myAttr1NS:attrNumber=\"1\" />";
-
- OMFactory omFactory = OMAbstractFactory.getOMFactory();
-
- OMNamespace attrNS1 =
- omFactory.createOMNamespace("http://test-attributes-1.org",
"myAttr1NS");
- OMNamespace attrNS2 =
- omFactory.createOMNamespace("http://test-attributes-2.org",
"myAttr2NS");
- OMElement omElement = omFactory.createOMElement("AttributeTester",
null);
- omElement.addAttribute(omFactory.createOMAttribute("attrNumber",
attrNS1, "1"));
- omElement.addAttribute(omFactory.createOMAttribute("attrNumber",
attrNS2, "2"));
-
- int nsCount = 0;
- for (Iterator iterator = omElement.getAllDeclaredNamespaces();
iterator.hasNext();) {
- iterator.next();
- nsCount++;
- }
- assertTrue(nsCount == 2);
-
- Diff diff = compareXML(expectedXML, omElement.toString());
- assertXMLEqual(diff, true);
- }
-
-
public void testAttributesWithNamespaceSerialization() throws Exception {
String xmlString =
"<root xmlns='http://custom.com'><node cust:id='123'
xmlns:cust='http://custom.com' /></root>";
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/builder/StAXOMBuilderTest.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/builder/StAXOMBuilderTest.java?rev=1087432&r1=1087431&r2=1087432&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/builder/StAXOMBuilderTest.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/builder/StAXOMBuilderTest.java
Thu Mar 31 20:51:42 2011
@@ -27,15 +27,9 @@ import org.apache.axiom.om.OMText;
import org.apache.axiom.om.OMXMLBuilderFactory;
import org.apache.axiom.om.OMXMLParserWrapper;
import org.apache.axiom.om.util.StAXUtils;
-import org.apache.axiom.testutils.InvocationCounter;
-import org.apache.axiom.testutils.io.ExceptionInputStream;
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
import java.util.Iterator;
-import javax.xml.stream.XMLStreamReader;
-
public class StAXOMBuilderTest extends AbstractTestCase {
OMXMLParserWrapper stAXOMBuilder;
private OMElement rootElement;
@@ -126,95 +120,4 @@ public class StAXOMBuilderTest extends A
assertTrue(childrenCount == 5);
}
-
- public void testInvalidXML() throws Exception {
- XMLStreamReader originalReader =
StAXUtils.createXMLStreamReader(getTestResource("invalid_xml.xml"));
- InvocationCounter invocationCounter = new InvocationCounter();
- XMLStreamReader reader =
(XMLStreamReader)invocationCounter.createProxy(originalReader);
-
- OMXMLParserWrapper stAXOMBuilder =
-
OMXMLBuilderFactory.createStAXOMBuilder(OMAbstractFactory.getSOAP11Factory(),
- reader);
-
- Exception exception = null;
- while (exception == null || stAXOMBuilder.isCompleted()) {
- try {
- stAXOMBuilder.next();
- } catch (Exception e) {
- exception =e;
- }
- }
-
- assertTrue("Expected an exception because invalid_xml.xml is wrong",
exception != null);
-
- assertTrue(invocationCounter.getInvocationCount() > 0);
- invocationCounter.reset();
-
- // Intentionally call builder again to make sure the same error is
returned.
- Exception exception2 = null;
- try {
- stAXOMBuilder.next();
- } catch (Exception e) {
- exception2 = e;
- }
-
- assertEquals(0, invocationCounter.getInvocationCount());
-
- assertTrue("Expected a second exception because invalid_xml.xml is
wrong", exception2 != null);
- assertTrue("Expected the same exception. first=" + exception + "
second=" + exception2,
- exception.getMessage().equals(exception2.getMessage()));
-
- }
-
- /**
- * Test the behavior of the builder when an exception is thrown by
- * {@link XMLStreamReader#getText()}. The test is only effective if the
StAX
- * implementation lazily loads the character data for a
- * {@link javax.xml.stream.XMLStreamConstants#CHARACTERS} event. This is
the
- * case for Woodstox. It checks that after the exception is thrown by the
- * parser, the builder no longer attempts to access the parser.
- *
- * @throws Exception
- */
- public void testIOExceptionInGetText() throws Exception {
- // Construct a stream that will throw an exception in the middle of a
text node.
- // We need to create a very large document, because some parsers (such
as some
- // versions of XLXP) have a large input buffer and would throw an
exception already
- // when the XMLStreamReader is created.
- StringBuffer xml = new StringBuffer("<root>");
- for (int i=0; i<100000; i++) {
- xml.append('x');
- }
- InputStream in = new ExceptionInputStream(new
ByteArrayInputStream(xml.toString().getBytes("ASCII")));
-
- XMLStreamReader originalReader = StAXUtils.createXMLStreamReader(in);
- InvocationCounter invocationCounter = new InvocationCounter();
- XMLStreamReader reader =
(XMLStreamReader)invocationCounter.createProxy(originalReader);
-
- OMXMLParserWrapper builder =
OMXMLBuilderFactory.createStAXOMBuilder(reader);
-
- try {
- while (true) {
- builder.next();
- }
- } catch (Exception ex) {
- // Expected
- }
-
- assertTrue(invocationCounter.getInvocationCount() > 0);
- invocationCounter.reset();
-
- Exception exception;
- try {
- builder.next();
- exception = null;
- } catch (Exception ex) {
- exception = ex;
- }
- if (exception == null) {
- fail("Expected exception");
- }
-
- assertEquals(0, invocationCounter.getInvocationCount());
- }
}
\ No newline at end of file
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=1087432&r1=1087431&r2=1087432&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
Thu Mar 31 20:51:42 2011
@@ -47,6 +47,8 @@ public class OMTestSuiteBuilder extends
addTest(new
org.apache.axiom.ts.om.attribute.TestGetQNameWithoutNamespace(metaFactory));
addTest(new
org.apache.axiom.ts.om.builder.TestGetDocumentElement(metaFactory));
addTest(new
org.apache.axiom.ts.om.builder.TestGetDocumentElementWithDiscardDocument(metaFactory));
+ addTest(new
org.apache.axiom.ts.om.builder.TestInvalidXML(metaFactory));
+ addTest(new
org.apache.axiom.ts.om.builder.TestIOExceptionInGetText(metaFactory));
for (int i=0; i<conformanceFiles.length; i++) {
for (int j=0; j<containerFactories.length; j++) {
addTest(new
org.apache.axiom.ts.om.container.TestGetXMLStreamReader(metaFactory,
conformanceFiles[i], containerFactories[j], true));
@@ -61,6 +63,7 @@ public class OMTestSuiteBuilder extends
addTest(new
org.apache.axiom.ts.om.document.TestSerializeAndConsumeWithIncompleteDescendant(metaFactory));
addTest(new
org.apache.axiom.ts.om.element.TestAddAttributeAlreadyOwnedByElement(metaFactory));
addTest(new
org.apache.axiom.ts.om.element.TestAddAttributeAlreadyOwnedByOtherElement(metaFactory));
+ addTest(new
org.apache.axiom.ts.om.element.TestAddAttributeFromOMAttributeMultiple(metaFactory));
addTest(new
org.apache.axiom.ts.om.element.TestAddAttributeFromOMAttributeWithExistingName(metaFactory));
addTest(new
org.apache.axiom.ts.om.element.TestAddAttributeReplace1(metaFactory));
addTest(new
org.apache.axiom.ts.om.element.TestAddAttributeReplace2(metaFactory));
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestIOExceptionInGetText.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestIOExceptionInGetText.java?rev=1087432&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestIOExceptionInGetText.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestIOExceptionInGetText.java
Thu Mar 31 20:51:42 2011
@@ -0,0 +1,88 @@
+/*
+ * 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.builder;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axiom.testutils.InvocationCounter;
+import org.apache.axiom.testutils.io.ExceptionInputStream;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Test the behavior of the builder when an exception is thrown by
+ * {@link XMLStreamReader#getText()}. The test is only effective if the StAX
+ * implementation lazily loads the character data for a
+ * {@link javax.xml.stream.XMLStreamConstants#CHARACTERS} event. This is the
+ * case for Woodstox. It checks that after the exception is thrown by the
+ * parser, the builder no longer attempts to access the parser.
+ */
+public class TestIOExceptionInGetText extends AxiomTestCase {
+ public TestIOExceptionInGetText(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ // Construct a stream that will throw an exception in the middle of a
text node.
+ // We need to create a very large document, because some parsers (such
as some
+ // versions of XLXP) have a large input buffer and would throw an
exception already
+ // when the XMLStreamReader is created.
+ StringBuffer xml = new StringBuffer("<root>");
+ for (int i=0; i<100000; i++) {
+ xml.append('x');
+ }
+ InputStream in = new ExceptionInputStream(new
ByteArrayInputStream(xml.toString().getBytes("ASCII")));
+
+ XMLStreamReader originalReader = StAXUtils.createXMLStreamReader(in);
+ InvocationCounter invocationCounter = new InvocationCounter();
+ XMLStreamReader reader =
(XMLStreamReader)invocationCounter.createProxy(originalReader);
+
+ OMXMLParserWrapper builder =
OMXMLBuilderFactory.createStAXOMBuilder(metaFactory.getOMFactory(), reader);
+
+ try {
+ while (true) {
+ builder.next();
+ }
+ } catch (Exception ex) {
+ // Expected
+ }
+
+ assertTrue(invocationCounter.getInvocationCount() > 0);
+ invocationCounter.reset();
+
+ Exception exception;
+ try {
+ builder.next();
+ exception = null;
+ } catch (Exception ex) {
+ exception = ex;
+ }
+ if (exception == null) {
+ fail("Expected exception");
+ }
+
+ assertEquals(0, invocationCounter.getInvocationCount());
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestIOExceptionInGetText.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestInvalidXML.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestInvalidXML.java?rev=1087432&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestInvalidXML.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestInvalidXML.java
Thu Mar 31 20:51:42 2011
@@ -0,0 +1,73 @@
+/*
+ * 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.builder;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.om.AbstractTestCase;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axiom.testutils.InvocationCounter;
+import org.apache.axiom.ts.AxiomTestCase;
+
+public class TestInvalidXML extends AxiomTestCase {
+ public TestInvalidXML(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ XMLStreamReader originalReader =
StAXUtils.createXMLStreamReader(AbstractTestCase.getTestResource("invalid_xml.xml"));
+ InvocationCounter invocationCounter = new InvocationCounter();
+ XMLStreamReader reader =
(XMLStreamReader)invocationCounter.createProxy(originalReader);
+
+ OMXMLParserWrapper stAXOMBuilder =
+
OMXMLBuilderFactory.createStAXOMBuilder(metaFactory.getOMFactory(),
+ reader);
+
+ Exception exception = null;
+ while (exception == null || stAXOMBuilder.isCompleted()) {
+ try {
+ stAXOMBuilder.next();
+ } catch (Exception e) {
+ exception =e;
+ }
+ }
+
+ assertTrue("Expected an exception because invalid_xml.xml is wrong",
exception != null);
+
+ assertTrue(invocationCounter.getInvocationCount() > 0);
+ invocationCounter.reset();
+
+ // Intentionally call builder again to make sure the same error is
returned.
+ Exception exception2 = null;
+ try {
+ stAXOMBuilder.next();
+ } catch (Exception e) {
+ exception2 = e;
+ }
+
+ assertEquals(0, invocationCounter.getInvocationCount());
+
+ assertTrue("Expected a second exception because invalid_xml.xml is
wrong", exception2 != null);
+ assertTrue("Expected the same exception. first=" + exception + "
second=" + exception2,
+ exception.getMessage().equals(exception2.getMessage()));
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestInvalidXML.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestAddAttributeFromOMAttributeMultiple.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestAddAttributeFromOMAttributeMultiple.java?rev=1087432&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestAddAttributeFromOMAttributeMultiple.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestAddAttributeFromOMAttributeMultiple.java
Thu Mar 31 20:51:42 2011
@@ -0,0 +1,66 @@
+/*
+ * 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.element;
+
+import java.util.Iterator;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.ts.AxiomTestCase;
+import org.custommonkey.xmlunit.Diff;
+
+/**
+ * Tests that when {@link
OMElement#addAttribute(org.apache.axiom.om.OMAttribute)} is called
+ * multiple times for attributes with different namespaces, each call adds a
corresponding namespace
+ * declaration.
+ */
+public class TestAddAttributeFromOMAttributeMultiple extends AxiomTestCase {
+ public TestAddAttributeFromOMAttributeMultiple(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ String expectedXML =
+ "<AttributeTester xmlns=\"\"
xmlns:myAttr2NS=\"http://test-attributes-2.org\" " +
+ "xmlns:myAttr1NS=\"http://test-attributes-1.org\"
myAttr2NS:attrNumber=\"2\" myAttr1NS:attrNumber=\"1\" />";
+
+ OMFactory omFactory = metaFactory.getOMFactory();
+
+ OMNamespace attrNS1 =
+ omFactory.createOMNamespace("http://test-attributes-1.org",
"myAttr1NS");
+ OMNamespace attrNS2 =
+ omFactory.createOMNamespace("http://test-attributes-2.org",
"myAttr2NS");
+ OMElement omElement = omFactory.createOMElement("AttributeTester",
null);
+ omElement.addAttribute(omFactory.createOMAttribute("attrNumber",
attrNS1, "1"));
+ omElement.addAttribute(omFactory.createOMAttribute("attrNumber",
attrNS2, "2"));
+
+ int nsCount = 0;
+ for (Iterator iterator = omElement.getAllDeclaredNamespaces();
iterator.hasNext();) {
+ iterator.next();
+ nsCount++;
+ }
+ assertTrue(nsCount == 2);
+
+ Diff diff = compareXML(expectedXML, omElement.toString());
+ assertXMLEqual(diff, true);
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestAddAttributeFromOMAttributeMultiple.java
------------------------------------------------------------------------------
svn:eol-style = native