Author: chinthaka Date: Sat Nov 17 20:38:09 2007 New Revision: 596052 URL: http://svn.apache.org/viewvc?rev=596052&view=rev Log: Adding the problem mentioned in Axis2-3155 as a test case
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/NamespaceTest.java Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/NamespaceTest.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/NamespaceTest.java?rev=596052&r1=596051&r2=596052&view=diff ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/NamespaceTest.java (original) +++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/NamespaceTest.java Sat Nov 17 20:38:09 2007 @@ -21,15 +21,16 @@ import org.apache.axiom.om.impl.builder.StAXOMBuilder; import org.apache.axiom.om.impl.llom.factory.OMXMLBuilderFactory; +import org.apache.axiom.om.impl.llom.util.AXIOMUtil; import org.custommonkey.xmlunit.XMLTestCase; import org.xml.sax.SAXException; import javax.xml.namespace.QName; import javax.xml.parsers.ParserConfigurationException; import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamWriter; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -143,7 +144,7 @@ assertEquals(2, getNumberOfOccurrences(documentElement.toStringWithConsume(), - "xmlns=\"http://one.org\"")); + "xmlns=\"http://one.org\"")); } public void testNamespaceProblem3() throws XMLStreamException { @@ -168,7 +169,7 @@ OMElement childTwo = omFac.createOMElement("ChildElementTwo", ns1, childOne); assertEquals(1, getNumberOfOccurrences(documentElement.toStringWithConsume(), - "xmlns:ns2=\"http://one.org\"")); + "xmlns:ns2=\"http://one.org\"")); } @@ -203,7 +204,7 @@ int index = -1; int count = 0; while ((index = xml.indexOf(pattern, index + 1)) != -1) { - count ++; + count++; } return count; @@ -236,7 +237,9 @@ } - /** This is re-producing and testing the bug mentioned in http://issues.apache.org/jira/browse/WSCOMMONS-74 */ + /** + * This is re-producing and testing the bug mentioned in http://issues.apache.org/jira/browse/WSCOMMONS-74 + */ public void testNamespaceProblem7() { String expectedString = "<person xmlns=\"http://ws.apache.org/axis2/apacheconasia/06\">" + @@ -273,7 +276,9 @@ } } - /** This is re-producing and testing the bug mentioned in http://issues.apache.org/jira/browse/WSCOMMONS-74 */ + /** + * This is re-producing and testing the bug mentioned in http://issues.apache.org/jira/browse/WSCOMMONS-74 + */ public void testNamespaceProblem8() { String expectedXML = @@ -306,27 +311,27 @@ public void testOMElementSerialize() throws Exception { String content = - "<?xml version='1.0' encoding='UTF-8'?> \n" + - "<foo:foo xmlns:foo=\"urn:foo\"> \n" + - " <bar:bar xmlns:bar=\"urn:bar\"> baz </bar:bar> \n" + - " <bar:bar xmlns:bar=\"urn:bar\"> baz </bar:bar> \n" + - " <bar:bar xmlns:bar=\"urn:bar\"> baz </bar:bar> \n" + - "</foo:foo>"; + "<?xml version='1.0' encoding='UTF-8'?> \n" + + "<foo:foo xmlns:foo=\"urn:foo\"> \n" + + " <bar:bar xmlns:bar=\"urn:bar\"> baz </bar:bar> \n" + + " <bar:bar xmlns:bar=\"urn:bar\"> baz </bar:bar> \n" + + " <bar:bar xmlns:bar=\"urn:bar\"> baz </bar:bar> \n" + + "</foo:foo>"; // read and build XML content Reader reader = new StringReader(content); XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(reader); StAXOMBuilder builder = new StAXOMBuilder(parser); - OMElement element = builder.getDocumentElement(); + OMElement element = builder.getDocumentElement(); int count = 0; Iterator iter = element.getChildElements(); while (iter.hasNext()) { OMElement child = (OMElement) iter.next(); - assertTrue( child.getNamespace().getNamespaceURI().equals("urn:bar")); + assertTrue(child.getNamespace().getNamespaceURI().equals("urn:bar")); count++; } - assertEquals( 3, count); + assertEquals(3, count); // serialize it back to a String StringWriter stringWriter = new StringWriter(); @@ -342,17 +347,47 @@ reader = new StringReader(output); parser = XMLInputFactory.newInstance().createXMLStreamReader(reader); builder = new StAXOMBuilder(parser); - element = builder.getDocumentElement(); + element = builder.getDocumentElement(); count = 0; iter = element.getChildElements(); while (iter.hasNext()) { OMElement child = (OMElement) iter.next(); - assertTrue( child.getNamespace().getNamespaceURI().equals("urn:bar")); + assertTrue(child.getNamespace().getNamespaceURI().equals("urn:bar")); count++; } - assertEquals( 3, count); + assertEquals(3, count); } + public void testAxis2_3155() { + try { + String xmlString = + "<outerTag xmlns=\"http://someNamespace\">" + + "<innerTag>" + + "<node1>Hello</node1>" + + "<node2>Hello</node2>" + + "</innerTag>" + + "</outerTag>"; + + OMElement elem = AXIOMUtil.stringToOM(xmlString); + System.out.println("--- Calling toStringWithConsume() ---\n"); + System.out.println(elem.toStringWithConsume()); + + xmlString = + "<outerTag xmlns=\"http://someNamespace\">" + + "<innerTag>" + + "<node1>Hello</node1>" + + "<node2>Hello</node2>" + + "</innerTag>" + + "</outerTag>"; + + elem = AXIOMUtil.stringToOM(xmlString); + System.out.println("\n--- Calling toString() ---\n"); + System.out.println(elem.toString()); + } + catch (Exception e) { + e.printStackTrace(); + } + } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]