Author: veithen Date: Tue Dec 16 16:46:31 2008 New Revision: 727237 URL: http://svn.apache.org/viewvc?rev=727237&view=rev Log: Reorganized some of the existing OMElement related tests so that the a subset is applied both to LLOM and DOM.
Added: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMElementTestBase.java webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMElementTest.java Removed: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMTextTest.java Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/ElementImplTest.java Added: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMElementTestBase.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMElementTestBase.java?rev=727237&view=auto ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMElementTestBase.java (added) +++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMElementTestBase.java Tue Dec 16 16:46:31 2008 @@ -0,0 +1,83 @@ +/* + * 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; + +import java.util.Iterator; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamConstants; + +public abstract class OMElementTestBase extends AbstractTestCase { + protected abstract OMFactory getOMFactory(); + + public void testSetText() { + OMFactory factory = getOMFactory(); + String localName = "TestLocalName"; + String namespace = "http://ws.apache.org/axis2/ns"; + String prefix = "axis2"; + OMElement elem = factory.createOMElement(localName, namespace, prefix); + + String text = "The quick brown fox jumps over the lazy dog"; + + elem.setText(text); + + assertEquals("Text value mismatch", text, elem.getText()); + } + + public void testCDATA() throws Exception { + OMFactory factory = getOMFactory(); + OMElement omElement = factory.createOMElement("TestElement", null); + final String text = "this is <some> text in a CDATA"; + factory.createOMText(omElement, text, XMLStreamConstants.CDATA); + assertEquals(text, omElement.getText()); + + // OK, CDATA on its own worked - now confirm that a plain text + a CDATA works + omElement = factory.createOMElement("element2", null); + final String normalText = "regular text and "; + factory.createOMText(omElement, normalText); + factory.createOMText(omElement, text, XMLStreamConstants.CDATA); + assertEquals(normalText + text, omElement.getText()); + } + + public void testAddChild() { + OMFactory factory = getOMFactory(); + String localName = "TestLocalName"; + String childLocalName = "TestChildLocalName"; + String namespace = "http://ws.apache.org/axis2/ns"; + String prefix = "axis2"; + + OMElement elem = factory.createOMElement(localName, namespace, prefix); + OMElement childElem = factory.createOMElement(childLocalName, namespace, prefix); + + elem.addChild(childElem); + + Iterator it = elem.getChildrenWithName(new QName(namespace, childLocalName)); + + int count = 0; + while (it.hasNext()) { + OMElement child = (OMElement) it.next(); + assertEquals("Child local name mismatch", childLocalName, child.getLocalName()); + assertEquals("Child namespace mismatch", namespace, + child.getNamespace().getNamespaceURI()); + count ++; + } + assertEquals("In correct number of children", 1, count); + } +} Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/ElementImplTest.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/ElementImplTest.java?rev=727237&r1=727236&r2=727237&view=diff ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/ElementImplTest.java (original) +++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/ElementImplTest.java Tue Dec 16 16:46:31 2008 @@ -19,8 +19,9 @@ package org.apache.axiom.om.impl.dom; -import org.apache.axiom.om.AbstractTestCase; import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMElementTestBase; +import org.apache.axiom.om.OMFactory; import org.apache.axiom.om.OMText; import org.apache.axiom.om.impl.dom.factory.OMDOMFactory; import org.w3c.dom.Document; @@ -28,26 +29,13 @@ import org.w3c.dom.NodeList; import org.w3c.dom.Text; -import javax.xml.namespace.QName; import javax.xml.parsers.DocumentBuilderFactory; import java.io.ByteArrayOutputStream; -import java.util.Iterator; - -public class ElementImplTest extends AbstractTestCase { - public void testSetText() { - OMDOMFactory factory = new OMDOMFactory(); - String localName = "TestLocalName"; - String namespace = "http://ws.apache.org/axis2/ns"; - String prefix = "axis2"; - OMElement elem = factory.createOMElement(localName, namespace, prefix); - - String text = "The quick brown fox jumps over the lazy dog"; - - elem.setText(text); - - assertEquals("Text value mismatch", text, elem.getText()); +public class ElementImplTest extends OMElementTestBase { + protected OMFactory getOMFactory() { + return new OMDOMFactory(); } public void testSerialize() throws Exception { @@ -69,31 +57,6 @@ assertEquals("Incorrect serialized xml", 0, xml.indexOf("<axis2:TestLocalName")); } - public void testAddChild() { - OMDOMFactory factory = new OMDOMFactory(); - String localName = "TestLocalName"; - String childLocalName = "TestChildLocalName"; - String namespace = "http://ws.apache.org/axis2/ns"; - String prefix = "axis2"; - - OMElement elem = factory.createOMElement(localName, namespace, prefix); - OMElement childElem = factory.createOMElement(childLocalName, namespace, prefix); - - elem.addChild(childElem); - - Iterator it = elem.getChildrenWithName(new QName(namespace, childLocalName)); - - int count = 0; - while (it.hasNext()) { - OMElement child = (OMElement) it.next(); - assertEquals("Child local name mismatch", childLocalName, child.getLocalName()); - assertEquals("Child namespace mismatch", namespace, - child.getNamespace().getNamespaceURI()); - count ++; - } - assertEquals("In correct number of children", 1, count); - } - public void testAppendChild() throws Exception { DOMTestUtil.execute(new DOMTestUtil.Test() { public void execute(DocumentBuilderFactory dbf) throws Exception { Added: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMElementTest.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMElementTest.java?rev=727237&view=auto ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMElementTest.java (added) +++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMElementTest.java Tue Dec 16 16:46:31 2008 @@ -0,0 +1,76 @@ +/* + * 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 java.util.Iterator; + +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMElementTestBase; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNamespace; +import org.apache.axiom.om.impl.llom.factory.OMLinkedListImplFactory; + +public class OMElementTest extends OMElementTestBase { + private static final String AXIS2_NS_URI = "http://ws.apache.org/axis2"; + private static final String AXIS2_NS_PREFIX = "axis2"; + private static final String SOME_TEXT = "Some Text"; + + protected OMFactory getOMFactory() { + return new OMLinkedListImplFactory(); + } + + public void testTextQNames() { + OMFactory factory = getOMFactory(); + OMElement omElement = factory.createOMElement("TestElement", null); + omElement.setText(new QName(AXIS2_NS_URI, SOME_TEXT, AXIS2_NS_PREFIX)); + + Iterator allDeclaredNamespaces = omElement.getAllDeclaredNamespaces(); + boolean foundNamespace = false; + while (allDeclaredNamespaces.hasNext()) { + OMNamespace omNamespace = (OMNamespace) allDeclaredNamespaces.next(); + if (AXIS2_NS_URI.equals(omNamespace.getNamespaceURI()) && + AXIS2_NS_PREFIX.equals(omNamespace.getPrefix())) { + foundNamespace = true; + } + } + assertTrue("Namespace of the text is not defined in the parent element", foundNamespace); + + String elementString = omElement.toString(); + assertTrue(elementString.indexOf(AXIS2_NS_PREFIX + ":" + SOME_TEXT) > -1); + assertTrue((AXIS2_NS_PREFIX + ":" + SOME_TEXT).equals(omElement.getText())); + + QName textAsQName = omElement.getTextAsQName(); + assertTrue(textAsQName.equals(new QName(AXIS2_NS_URI, SOME_TEXT, AXIS2_NS_PREFIX))); + } + + public void testTextQNamesWithoutQNames() { + OMFactory factory = getOMFactory(); + OMElement omElement = factory.createOMElement("TestElement", null); + omElement.setText(SOME_TEXT); + + String elementString = omElement.toString(); + assertTrue(elementString.indexOf(":" + SOME_TEXT) == -1); + + QName textAsQName = omElement.getTextAsQName(); + assertTrue(textAsQName.equals(new QName(SOME_TEXT))); + } +}