Author: veithen
Date: Thu Dec 30 13:46:48 2010
New Revision: 1053889

URL: http://svn.apache.org/viewvc?rev=1053889&view=rev
Log:
Added two new test cases for OMContainer#serializeAndConsume. They will be 
necessary to ensure non regression when implementing AXIOM-24. In addition, 
they reveal problems in DOOM which may be related to AXIOM-315.

Added:
    
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/
    
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/TestSerializeAndConsumeWithIncompleteDescendant.java
   (with props)
    
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerializeAndConsumeWithIncompleteDescendant.java
   (with props)
Modified:
    
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/ImplementationTest.java
    
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

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/ImplementationTest.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/ImplementationTest.java?rev=1053889&r1=1053888&r2=1053889&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/ImplementationTest.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/ImplementationTest.java
 Thu Dec 30 13:46:48 2010
@@ -30,6 +30,11 @@ public class ImplementationTest extends 
         AxiomTestSuiteBuilder builder = new AxiomTestSuiteBuilder(new 
OMDOMMetaFactory());
         // OMElement#setText(QName) is unsupported
         builder.exclude(TestSetTextQName.class);
+        
+        // TODO: these need to be investigated; may be related to AXIOM-315
+        
builder.exclude(org.apache.axiom.ts.om.document.TestSerializeAndConsumeWithIncompleteDescendant.class);
+        
builder.exclude(org.apache.axiom.ts.om.element.TestSerializeAndConsumeWithIncompleteDescendant.class);
+        
         return builder.build();
     }
 }

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=1053889&r1=1053888&r2=1053889&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
 Thu Dec 30 13:46:48 2010
@@ -18,7 +18,9 @@
  */
 package org.apache.axiom.ts;
 
+import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.om.OMMetaFactory;
+import org.apache.commons.io.output.NullOutputStream;
 import org.custommonkey.xmlunit.XMLTestCase;
 
 public abstract class AxiomTestCase extends XMLTestCase {
@@ -28,4 +30,16 @@ public abstract class AxiomTestCase exte
         this.metaFactory = metaFactory;
         setName(getClass().getName());
     }
+    
+    protected void assertConsumed(OMContainer container) {
+        assertFalse(container.isComplete());
+        boolean isConsumed;
+        try {
+            container.serialize(new NullOutputStream());
+            isConsumed = false;
+        } catch (Exception ex) {
+            isConsumed = true;
+        }
+        assertTrue(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=1053889&r1=1053888&r2=1053889&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
 Thu Dec 30 13:46:48 2010
@@ -40,9 +40,10 @@ public class AxiomTestSuiteBuilder {
     
     public TestSuite build() {
         suite = new TestSuite();
+        addTest(new 
org.apache.axiom.ts.om.attribute.TestGetQName(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.attribute.TestGetQName(metaFactory));
+        addTest(new 
org.apache.axiom.ts.om.document.TestSerializeAndConsumeWithIncompleteDescendant(metaFactory));
         addTest(new 
org.apache.axiom.ts.om.element.TestAddAttributeWithExistingNamespaceDeclarationInScope(metaFactory));
         addTest(new 
org.apache.axiom.ts.om.element.TestAddAttributeWithExistingNamespaceDeclarationOnSameElement(metaFactory));
         addTest(new 
org.apache.axiom.ts.om.element.TestAddAttributeWithMaskedNamespaceDeclaration(metaFactory));
@@ -72,6 +73,7 @@ public class AxiomTestSuiteBuilder {
         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.TestSerializationWithTwoNonBuiltOMElements(metaFactory));
+        addTest(new 
org.apache.axiom.ts.om.element.TestSerializeAndConsumeWithIncompleteDescendant(metaFactory));
         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/document/TestSerializeAndConsumeWithIncompleteDescendant.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/TestSerializeAndConsumeWithIncompleteDescendant.java?rev=1053889&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/TestSerializeAndConsumeWithIncompleteDescendant.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/TestSerializeAndConsumeWithIncompleteDescendant.java
 Thu Dec 30 13:46:48 2010
@@ -0,0 +1,55 @@
+/*
+ * 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.document;
+
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import org.apache.axiom.om.OMDocument;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests that {...@link OMDocument#serializeAndConsume(java.io.Writer)} 
consumes incomplete descendants,
+ * even if the document itself is complete (more precisely, created 
programmatically). This situation
+ * may occur when an element obtained from
+ * {...@link 
org.apache.axiom.om.OMXMLParserWrapper#getDocumentElement(boolean)} (with
+ * <code>discardDocument</code> set to true) is added to an existing document.
+ */
+public class TestSerializeAndConsumeWithIncompleteDescendant extends 
AxiomTestCase {
+    public TestSerializeAndConsumeWithIncompleteDescendant(OMMetaFactory 
metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMFactory factory = metaFactory.getOMFactory();
+        OMElement incompleteElement = 
OMXMLBuilderFactory.createOMBuilder(factory,
+                new 
StringReader("<elem>text</elem>")).getDocumentElement(true);
+        OMDocument document = factory.createOMDocument();
+        OMElement root = factory.createOMElement("root", null, document);
+        root.addChild(incompleteElement);
+        StringWriter out = new StringWriter();
+        document.serializeAndConsume(out);
+        assertXMLEqual("<root><elem>text</elem></root>", out.toString());
+        assertConsumed(incompleteElement);
+    }
+}

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

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerializeAndConsumeWithIncompleteDescendant.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerializeAndConsumeWithIncompleteDescendant.java?rev=1053889&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerializeAndConsumeWithIncompleteDescendant.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerializeAndConsumeWithIncompleteDescendant.java
 Thu Dec 30 13:46:48 2010
@@ -0,0 +1,54 @@
+/*
+ * 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.io.StringReader;
+import java.io.StringWriter;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests that {...@link OMElement#serializeAndConsume(java.io.Writer)} 
consumes incomplete descendants,
+ * even if the element itself is complete (more precisely, created 
programmatically). This situation
+ * may occur when an element obtained from
+ * {...@link 
org.apache.axiom.om.OMXMLParserWrapper#getDocumentElement(boolean)} (with
+ * <code>discardDocument</code> set to true) is added to an existing tree.
+ */
+public class TestSerializeAndConsumeWithIncompleteDescendant extends 
AxiomTestCase {
+    public TestSerializeAndConsumeWithIncompleteDescendant(OMMetaFactory 
metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMFactory factory = metaFactory.getOMFactory();
+        OMElement incompleteElement = 
OMXMLBuilderFactory.createOMBuilder(factory,
+                new 
StringReader("<elem>text</elem>")).getDocumentElement(true);
+        OMElement root = factory.createOMElement("root", null);
+        OMElement child = factory.createOMElement("child", null, root);
+        child.addChild(incompleteElement);
+        StringWriter out = new StringWriter();
+        root.serializeAndConsume(out);
+        assertEquals("<root><child><elem>text</elem></child></root>", 
out.toString());
+        assertConsumed(incompleteElement);
+    }
+}

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


Reply via email to