Author: veithen
Date: Tue Dec 14 22:22:19 2010
New Revision: 1049310

URL: http://svn.apache.org/viewvc?rev=1049310&view=rev
Log:
AXIOM-311: Refactored SerializationTest, removing duplicate code and also fixed 
one test case (testUParentDChildren was actually not testing what it is 
supposed to test). The test cases are now also applied to DOOM.

Added:
    
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerialization.java
   (with props)
Modified:
    
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/SerializationTest.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestSuiteBuilder.java

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/SerializationTest.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/SerializationTest.java?rev=1049310&r1=1049309&r2=1049310&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/SerializationTest.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/SerializationTest.java
 Tue Dec 14 22:22:19 2010
@@ -26,269 +26,7 @@ import org.apache.axiom.om.impl.builder.
 import javax.xml.stream.XMLStreamException;
 import java.io.ByteArrayInputStream;
 
-/**
- * Each of the following tests have a parent "person" and children "name", 
"age", "weight". The
- * parent is defined as either: a) a qualified name (QParent) b) an 
unqualified name (UParent) c) a
- * qualified name using the default namespace (DParent)
- * <p/>
- * Likewise the children are defined as either: a) qualified names (QChildren) 
b) unqualified
- * children (UChildren) c) qualified using the default namespace (DChildren)
- */
 public class SerializationTest extends TestCase {
-
-    private static final String NS = 
"http://ws.apache.org/axis2/apacheconasia/06";;
-    private static final String PREFIX = "prefix";
-
-    public void testDParentDChildren() {
-        OMFactory fac = OMAbstractFactory.getOMFactory();
-
-        OMNamespace nsParent = fac.createOMNamespace(NS, "");
-        OMNamespace nsChildren = fac.createOMNamespace(NS, "");
-
-        OMElement personElem = fac.createOMElement("person", nsParent);
-        OMElement nameElem = fac.createOMElement("name", nsChildren);
-        nameElem.setText("John");
-
-        OMElement ageElem = fac.createOMElement("age", nsChildren);
-        ageElem.setText("34");
-
-        OMElement weightElem = fac.createOMElement("weight", nsChildren);
-        weightElem.setText("50");
-
-        //Add children to the person element
-        personElem.addChild(nameElem);
-        personElem.addChild(ageElem);
-        personElem.addChild(weightElem);
-
-        String xml = personElem.toString();
-
-        assertEquals("Incorrect namespace serialization", 2,
-                     
xml.split("http://ws.apache.org/axis2/apacheconasia/06";).length);
-    }
-
-    public void testDParentUChildren() {
-        OMFactory fac = OMAbstractFactory.getOMFactory();
-
-        OMNamespace nsParent = fac.createOMNamespace(NS, "");
-        OMNamespace nsChildren = fac.createOMNamespace("", "");
-
-        OMElement personElem = fac.createOMElement("person", nsParent);
-        OMElement nameElem = fac.createOMElement("name", nsChildren);
-        nameElem.setText("John");
-
-        OMElement ageElem = fac.createOMElement("age", nsChildren);
-        ageElem.setText("34");
-
-        OMElement weightElem = fac.createOMElement("weight", nsChildren);
-        weightElem.setText("50");
-
-        //Add children to the person element
-        personElem.addChild(nameElem);
-        personElem.addChild(ageElem);
-        personElem.addChild(weightElem);
-
-        String xml = personElem.toString();
-
-        assertEquals("Incorrect namespace serialization", 2,
-                     
xml.split("http://ws.apache.org/axis2/apacheconasia/06";).length);
-        assertEquals("Incorrect namespace serialization", 4, 
xml.split("\"\"").length);
-    }
-
-    public void testDParentQChildren() {
-        OMFactory fac = OMAbstractFactory.getOMFactory();
-
-        OMNamespace nsParent = fac.createOMNamespace(NS, "");
-        OMNamespace nsChildren = fac.createOMNamespace(NS, PREFIX);
-
-        OMElement personElem = fac.createOMElement("person", nsParent);
-        OMElement nameElem = fac.createOMElement("name", nsChildren);
-        nameElem.setText("John");
-
-        OMElement ageElem = fac.createOMElement("age", nsChildren);
-        ageElem.setText("34");
-
-        OMElement weightElem = fac.createOMElement("weight", nsChildren);
-        weightElem.setText("50");
-
-        //Add children to the person element
-        personElem.addChild(nameElem);
-        personElem.addChild(ageElem);
-        personElem.addChild(weightElem);
-
-        String xml = personElem.toString();
-
-        assertEquals("Incorrect namespace serialization", 5,
-                     
xml.split("http://ws.apache.org/axis2/apacheconasia/06";).length);
-    }
-
-
-    public void testQParentQChildren() {
-        OMFactory fac = OMAbstractFactory.getOMFactory();
-
-        OMNamespace nsParent = fac.createOMNamespace(NS, PREFIX);
-        OMNamespace nsChildren = fac.createOMNamespace(NS, PREFIX);
-
-        OMElement personElem = fac.createOMElement("person", nsParent);
-        OMElement nameElem = fac.createOMElement("name", nsChildren);
-        nameElem.setText("John");
-
-        OMElement ageElem = fac.createOMElement("age", nsChildren);
-        ageElem.setText("34");
-
-        OMElement weightElem = fac.createOMElement("weight", nsChildren);
-        weightElem.setText("50");
-
-        //Add children to the person element
-        personElem.addChild(nameElem);
-        personElem.addChild(ageElem);
-        personElem.addChild(weightElem);
-
-        String xml = personElem.toString();
-
-        assertEquals("Incorrect namespace serialization", 2,
-                     
xml.split("http://ws.apache.org/axis2/apacheconasia/06";).length);
-    }
-
-    public void testQParentUChildren() {
-        OMFactory fac = OMAbstractFactory.getOMFactory();
-
-        OMNamespace nsParent = fac.createOMNamespace(NS, PREFIX);
-        OMNamespace nsChildren = fac.createOMNamespace("", "");
-
-        OMElement personElem = fac.createOMElement("person", nsParent);
-        OMElement nameElem = fac.createOMElement("name", nsChildren);
-        nameElem.setText("John");
-
-        OMElement ageElem = fac.createOMElement("age", nsChildren);
-        ageElem.setText("34");
-
-        OMElement weightElem = fac.createOMElement("weight", nsChildren);
-        weightElem.setText("50");
-
-        //Add children to the person element
-        personElem.addChild(nameElem);
-        personElem.addChild(ageElem);
-        personElem.addChild(weightElem);
-
-        String xml = personElem.toString();
-
-        assertEquals("Incorrect default namespace serialization", 2,
-                     
xml.split("http://ws.apache.org/axis2/apacheconasia/06";).length);
-        assertEquals("Incorrect namespace serialization", 1, 
xml.split("\"\"").length);
-    }
-
-    public void testQParentDChildren() {
-        OMFactory fac = OMAbstractFactory.getOMFactory();
-
-        OMNamespace nsParent = fac.createOMNamespace(NS, PREFIX);
-        OMNamespace nsChildren = fac.createOMNamespace(NS, "");
-
-        OMElement personElem = fac.createOMElement("person", nsParent);
-        OMElement nameElem = fac.createOMElement("name", nsChildren);
-        nameElem.setText("John");
-
-        OMElement ageElem = fac.createOMElement("age", nsChildren);
-        ageElem.setText("34");
-
-        OMElement weightElem = fac.createOMElement("weight", nsChildren);
-        weightElem.setText("50");
-
-        //Add children to the person element
-        personElem.addChild(nameElem);
-        personElem.addChild(ageElem);
-        personElem.addChild(weightElem);
-
-        String xml = personElem.toString();
-
-        assertEquals("Incorrect default namespace serialization", 5,
-                     
xml.split("http://ws.apache.org/axis2/apacheconasia/06";).length);
-    }
-
-    public void testUParentUChildren() {
-        OMFactory fac = OMAbstractFactory.getOMFactory();
-
-        OMNamespace nsParent = fac.createOMNamespace("", "");
-        OMNamespace nsChildren = fac.createOMNamespace("", "");
-
-        OMElement personElem = fac.createOMElement("person", nsParent);
-        OMElement nameElem = fac.createOMElement("name", nsChildren);
-        nameElem.setText("John");
-
-        OMElement ageElem = fac.createOMElement("age", nsChildren);
-        ageElem.setText("34");
-
-        OMElement weightElem = fac.createOMElement("weight", nsChildren);
-        weightElem.setText("50");
-
-        //Add children to the person element
-        personElem.addChild(nameElem);
-        personElem.addChild(ageElem);
-        personElem.addChild(weightElem);
-
-        String xml = personElem.toString();
-
-        assertEquals("Incorrect default namespace serialization", 1,
-                     
xml.split("http://ws.apache.org/axis2/apacheconasia/06";).length);
-        assertEquals("Incorrect namespace serialization", 1, 
xml.split("\"\"").length);
-    }
-
-    public void testUParentQChildren() {
-        OMFactory fac = OMAbstractFactory.getOMFactory();
-
-        OMNamespace nsParent = fac.createOMNamespace("", "");
-        OMNamespace nsChildren = fac.createOMNamespace(NS, PREFIX);
-
-        OMElement personElem = fac.createOMElement("person", nsParent);
-        OMElement nameElem = fac.createOMElement("name", nsChildren);
-        nameElem.setText("John");
-
-        OMElement ageElem = fac.createOMElement("age", nsChildren);
-        ageElem.setText("34");
-
-        OMElement weightElem = fac.createOMElement("weight", nsChildren);
-        weightElem.setText("50");
-
-        //Add children to the person element
-        personElem.addChild(nameElem);
-        personElem.addChild(ageElem);
-        personElem.addChild(weightElem);
-
-        String xml = personElem.toString();
-
-        assertEquals("Incorrect default namespace serialization", 4,
-                     
xml.split("http://ws.apache.org/axis2/apacheconasia/06";).length);
-        assertEquals("Incorrect namespace serialization", 1, 
xml.split("\"\"").length);
-    }
-
-    public void testUParentDChildren() {
-        OMFactory fac = OMAbstractFactory.getOMFactory();
-
-        OMNamespace nsParent = fac.createOMNamespace("", "");
-        OMNamespace nsChildren = fac.createOMNamespace(NS, PREFIX);
-
-        OMElement personElem = fac.createOMElement("person", nsParent);
-        OMElement nameElem = fac.createOMElement("name", nsChildren);
-        nameElem.setText("John");
-
-        OMElement ageElem = fac.createOMElement("age", nsChildren);
-        ageElem.setText("34");
-
-        OMElement weightElem = fac.createOMElement("weight", nsChildren);
-        weightElem.setText("50");
-
-        //Add children to the person element
-        personElem.addChild(nameElem);
-        personElem.addChild(ageElem);
-        personElem.addChild(weightElem);
-
-        String xml = personElem.toString();
-
-        assertEquals("Incorrect namespace serialization", 4,
-                     
xml.split("http://ws.apache.org/axis2/apacheconasia/06";).length);
-        assertEquals("Incorrect namespace serialization", 1, 
xml.split("\"\"").length);
-    }
-
-
     /**
      * Special case when OMElement is created with a null OMNamespace. In this 
case, that element
      * must always belongs to the default, default namespace

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=1049310&r1=1049309&r2=1049310&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
 Tue Dec 14 22:22:19 2010
@@ -51,6 +51,24 @@ public class AxiomTestSuiteBuilder {
         addTest(new 
org.apache.axiom.ts.om.element.TestGetAttributeWithXmlPrefix1(metaFactory));
         addTest(new 
org.apache.axiom.ts.om.element.TestGetAttributeWithXmlPrefix2(metaFactory));
         addTest(new 
org.apache.axiom.ts.om.element.TestGetFirstChildWithName(metaFactory));
+        addTest(new 
org.apache.axiom.ts.om.element.TestSerialization(metaFactory, "D", "D",
+                "<person 
xmlns=\"urn:ns\"><name>John</name><age>34</age><weight>50</weight></person>"));
+        addTest(new 
org.apache.axiom.ts.om.element.TestSerialization(metaFactory, "D", "U",
+                "<person xmlns=\"urn:ns\"><name xmlns=\"\">John</name><age 
xmlns=\"\">34</age><weight xmlns=\"\">50</weight></person>"));
+        addTest(new 
org.apache.axiom.ts.om.element.TestSerialization(metaFactory, "D", "Q",
+                "<person xmlns=\"urn:ns\"><p:name 
xmlns:p=\"urn:ns\">John</p:name><p:age xmlns:p=\"urn:ns\">34</p:age><p:weight 
xmlns:p=\"urn:ns\">50</p:weight></person>"));
+        addTest(new 
org.apache.axiom.ts.om.element.TestSerialization(metaFactory, "Q", "Q",
+                "<p:person 
xmlns:p=\"urn:ns\"><p:name>John</p:name><p:age>34</p:age><p:weight>50</p:weight></p:person>"));
+        addTest(new 
org.apache.axiom.ts.om.element.TestSerialization(metaFactory, "Q", "U",
+                "<p:person 
xmlns:p=\"urn:ns\"><name>John</name><age>34</age><weight>50</weight></p:person>"));
+        addTest(new 
org.apache.axiom.ts.om.element.TestSerialization(metaFactory, "Q", "D",
+                "<p:person xmlns:p=\"urn:ns\"><name 
xmlns=\"urn:ns\">John</name><age xmlns=\"urn:ns\">34</age><weight 
xmlns=\"urn:ns\">50</weight></p:person>"));
+        addTest(new 
org.apache.axiom.ts.om.element.TestSerialization(metaFactory, "U", "U",
+                
"<person><name>John</name><age>34</age><weight>50</weight></person>"));
+        addTest(new 
org.apache.axiom.ts.om.element.TestSerialization(metaFactory, "U", "Q",
+                "<person><p:name xmlns:p=\"urn:ns\">John</p:name><p:age 
xmlns:p=\"urn:ns\">34</p:age><p:weight 
xmlns:p=\"urn:ns\">50</p:weight></person>"));
+        addTest(new 
org.apache.axiom.ts.om.element.TestSerialization(metaFactory, "U", "D",
+                "<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.TestSetTextQName(metaFactory));
         addTest(new org.apache.axiom.ts.om.node.TestDetach(metaFactory, true));
         addTest(new org.apache.axiom.ts.om.node.TestDetach(metaFactory, 
false));

Added: 
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=1049310&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerialization.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerialization.java
 Tue Dec 14 22:22:19 2010
@@ -0,0 +1,95 @@
+/*
+ * 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 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;
+
+/**
+ * Tests proper serialization for different combinations of namespaces on the 
element and its children.
+ * The test creates a parent "person" and children "name", "age", "weight". The
+ * parent is defined as either:
+ * <ul>
+ * <li>a qualified name (<code>parent=Q</code>)
+ * <li>an unqualified name (<code>parent=U</code>)
+ * <li>a qualified name using the default namespace (<code>parent=D</code>)
+ * </ul>
+ * <p>
+ * Likewise the children are defined as either:
+ * <ul>
+ * <li>qualified names (<code>children=Q</code>)
+ * <li>unqualified children (<code>children=U</code>)
+ * <li>qualified using the default namespace (<code>children=D</code>)
+ * </ul>
+ */
+public class TestSerialization extends AxiomTestCase {
+    private static final String NS = "urn:ns";
+    private static final String PREFIX = "p";
+    
+    private final String parent;
+    private final String children;
+    private final String expected;
+    
+    public TestSerialization(OMMetaFactory metaFactory, String parent, String 
children, String expected) {
+        super(metaFactory);
+        this.parent = parent;
+        this.children = children;
+        this.expected = expected;
+        setName(getName() + " [parent=" + parent + ",children=" + children + 
"]");
+    }
+    
+    private static OMNamespace createNamespace(OMFactory factory, String type) 
{
+        if (type.equals("Q")) {
+            return factory.createOMNamespace(NS, PREFIX);
+        } else if (type.equals("U")) {
+            return factory.createOMNamespace("", "");
+        } else if (type.equals("D")) {
+            return factory.createOMNamespace(NS, "");
+        } else {
+            throw new IllegalArgumentException();
+        }
+    }
+    
+    protected void runTest() throws Throwable {
+        OMFactory fac = metaFactory.getOMFactory();
+
+        OMNamespace nsParent = createNamespace(fac, parent);
+        OMNamespace nsChildren = createNamespace(fac, children);
+
+        OMElement personElem = fac.createOMElement("person", nsParent);
+        OMElement nameElem = fac.createOMElement("name", nsChildren);
+        nameElem.setText("John");
+
+        OMElement ageElem = fac.createOMElement("age", nsChildren);
+        ageElem.setText("34");
+
+        OMElement weightElem = fac.createOMElement("weight", nsChildren);
+        weightElem.setText("50");
+
+        //Add children to the person element
+        personElem.addChild(nameElem);
+        personElem.addChild(ageElem);
+        personElem.addChild(weightElem);
+
+        assertEquals(expected, personElem.toString());
+    }
+}

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerialization.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to