You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2015/09/22 23:57:38 UTC

svn commit: r1704737 - in /webservices/axiom/trunk: implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/ implementations/fom-impl/src/test/java/org/apache/abdera/test/parser/stax/ testing/fom-testsuite/src/main/java/org/apache/axiom/ts...

Author: veithen
Date: Tue Sep 22 21:57:34 2015
New Revision: 1704737

URL: http://svn.apache.org/viewvc?rev=1704737&view=rev
Log:
Increase test coverage and fix some problems with the _removeChildren method.

Added:
    webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/collection/
    webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/collection/TestSetAccept.java   (with props)
    webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/collection/TestSetAcceptRemove.java   (with props)
    webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/control/
    webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/control/TestIsDraft.java   (with props)
    webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/control/TestSetUnsetDraft.java   (with props)
Modified:
    webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMElement.java
    webservices/axiom/trunk/implementations/fom-impl/src/test/java/org/apache/abdera/test/parser/stax/FOMTest.java
    webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/FOMTestSuiteBuilder.java
    webservices/axiom/trunk/testing/fom-testsuite/src/test/java/org/apache/axiom/ts/fom/AbderaTest.java

Modified: webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMElement.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMElement.java?rev=1704737&r1=1704736&r2=1704737&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMElement.java (original)
+++ webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMElement.java Tue Sep 22 21:57:34 2015
@@ -57,6 +57,8 @@ import org.apache.abdera.util.Constants;
 import org.apache.abdera.util.MimeTypeHelper;
 import org.apache.abdera.writer.Writer;
 import org.apache.abdera.writer.WriterOptions;
+import org.apache.axiom.core.CoreChildNode;
+import org.apache.axiom.core.CoreNSAwareElement;
 import org.apache.axiom.fom.AbderaElement;
 import org.apache.axiom.fom.IRIUtil;
 import org.apache.axiom.fom.Policies;
@@ -472,15 +474,22 @@ public class FOMElement extends FOMChild
     }
 
     protected void _removeChildren(QName qname, boolean many) {
-        if (many) {
-            for (Iterator i = getChildrenWithName(qname); i.hasNext();) {
-                OMElement element = (OMElement)i.next();
-                element.discard();
+        CoreChildNode child = coreGetFirstChild();
+        while (child != null) {
+            if (child instanceof CoreNSAwareElement) {
+                CoreNSAwareElement element = (CoreNSAwareElement)child;
+                if (element.coreGetLocalName().equals(qname.getLocalPart())
+                        && element.coreGetNamespaceURI().equals(qname.getNamespaceURI())) {
+                    child = child.coreGetNextSibling();
+                    element.coreDetach(Policies.DETACH_POLICY);
+                    if (many) {
+                        continue;
+                    } else {
+                        return;
+                    }
+                }
             }
-        } else {
-            OMElement element = getFirstChildWithName(qname);
-            if (element != null)
-                element.discard();
+            child = child.coreGetNextSibling();
         }
     }
 

Modified: webservices/axiom/trunk/implementations/fom-impl/src/test/java/org/apache/abdera/test/parser/stax/FOMTest.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/fom-impl/src/test/java/org/apache/abdera/test/parser/stax/FOMTest.java?rev=1704737&r1=1704736&r2=1704737&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/fom-impl/src/test/java/org/apache/abdera/test/parser/stax/FOMTest.java (original)
+++ webservices/axiom/trunk/implementations/fom-impl/src/test/java/org/apache/abdera/test/parser/stax/FOMTest.java Tue Sep 22 21:57:34 2015
@@ -341,11 +341,6 @@ public class FOMTest {
         assertEquals("a", contributor.getName());
         assertEquals("b", contributor.getEmail());
         assertEquals("c", contributor.getUri().toString());
-        Control control = factory.newControl();
-        assertNotNull(control);
-        control = factory.newControl();
-        control.setDraft(true);
-        assertTrue(control.isDraft());
         Date now = new Date();
         DateTime dateTime = factory.newDateTime(Constants.UPDATED, null);
         dateTime.setValue(AtomDate.valueOf(now));

Modified: webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/FOMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/FOMTestSuiteBuilder.java?rev=1704737&r1=1704736&r2=1704737&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/FOMTestSuiteBuilder.java (original)
+++ webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/FOMTestSuiteBuilder.java Tue Sep 22 21:57:34 2015
@@ -37,5 +37,9 @@ public class FOMTestSuiteBuilder extends
         addTest(new org.apache.axiom.ts.fom.attribute.TestSetAttributeValueQNameNew(abdera, new QName("urn:test", "attr")));
         addTest(new org.apache.axiom.ts.fom.attribute.TestSetAttributeValueQNameNew(abdera, new QName("urn:test", "attr", "p")));
         addTest(new org.apache.axiom.ts.fom.attribute.TestSetAttributeValueQNameRemove(abdera));
+        addTest(new org.apache.axiom.ts.fom.collection.TestSetAccept(abdera));
+        addTest(new org.apache.axiom.ts.fom.collection.TestSetAcceptRemove(abdera));
+        addTest(new org.apache.axiom.ts.fom.control.TestIsDraft(abdera));
+        addTest(new org.apache.axiom.ts.fom.control.TestSetUnsetDraft(abdera));
     }
 }

Added: webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/collection/TestSetAccept.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/collection/TestSetAccept.java?rev=1704737&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/collection/TestSetAccept.java (added)
+++ webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/collection/TestSetAccept.java Tue Sep 22 21:57:34 2015
@@ -0,0 +1,47 @@
+/*
+ * 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.fom.collection;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import java.util.List;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Collection;
+import org.apache.abdera.model.Element;
+import org.apache.abdera.util.Constants;
+import org.apache.axiom.ts.fom.AbderaTestCase;
+
+public class TestSetAccept extends AbderaTestCase {
+    public TestSetAccept(Abdera abdera) {
+        super(abdera);
+    }
+
+    @Override
+    protected void runTest() throws Throwable {
+        Collection collection = abdera.getFactory().newCollection();
+        collection.setAccept("image/png", "image/jpeg");
+        List<Element> children = collection.getElements();
+        assertThat(children).hasSize(2);
+        assertThat(children.get(0).getQName()).isEqualTo(Constants.ACCEPT);
+        assertThat(children.get(0).getText()).isEqualTo("image/png");
+        assertThat(children.get(1).getQName()).isEqualTo(Constants.ACCEPT);
+        assertThat(children.get(1).getText()).isEqualTo("image/jpeg");
+    }
+}

Propchange: webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/collection/TestSetAccept.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/collection/TestSetAcceptRemove.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/collection/TestSetAcceptRemove.java?rev=1704737&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/collection/TestSetAcceptRemove.java (added)
+++ webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/collection/TestSetAcceptRemove.java Tue Sep 22 21:57:34 2015
@@ -0,0 +1,43 @@
+/*
+ * 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.fom.collection;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Collection;
+import org.apache.axiom.ts.fom.AbderaTestCase;
+
+/**
+ * Tests that {@link Collection#setAccept(String...)} with an empty array removes any existing
+ * <code>accept</code> element.
+ */
+public class TestSetAcceptRemove extends AbderaTestCase {
+    public TestSetAcceptRemove(Abdera abdera) {
+        super(abdera);
+    }
+
+    @Override
+    protected void runTest() throws Throwable {
+        Collection collection = abdera.getFactory().newCollection();
+        collection.setAccept("image/png", "image/jpeg");
+        collection.setAccept();
+        assertThat(collection.getFirstChild()).isNull();
+    }
+}

Propchange: webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/collection/TestSetAcceptRemove.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/control/TestIsDraft.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/control/TestIsDraft.java?rev=1704737&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/control/TestIsDraft.java (added)
+++ webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/control/TestIsDraft.java Tue Sep 22 21:57:34 2015
@@ -0,0 +1,41 @@
+/*
+ * 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.fom.control;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.factory.Factory;
+import org.apache.abdera.model.Control;
+import org.apache.abdera.util.Constants;
+import org.apache.axiom.ts.fom.AbderaTestCase;
+
+public class TestIsDraft extends AbderaTestCase {
+    public TestIsDraft(Abdera abdera) {
+        super(abdera);
+    }
+
+    @Override
+    protected void runTest() throws Throwable {
+        Factory factory = abdera.getFactory();
+        Control control = factory.newControl();
+        factory.newElement(Constants.DRAFT, control).setText("yes");
+        assertThat(control.isDraft()).isTrue();
+    }
+}

Propchange: webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/control/TestIsDraft.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/control/TestSetUnsetDraft.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/control/TestSetUnsetDraft.java?rev=1704737&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/control/TestSetUnsetDraft.java (added)
+++ webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/control/TestSetUnsetDraft.java Tue Sep 22 21:57:34 2015
@@ -0,0 +1,46 @@
+/*
+ * 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.fom.control;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Control;
+import org.apache.abdera.model.Element;
+import org.apache.abdera.util.Constants;
+import org.apache.axiom.ts.fom.AbderaTestCase;
+
+public class TestSetUnsetDraft extends AbderaTestCase {
+    public TestSetUnsetDraft(Abdera abdera) {
+        super(abdera);
+    }
+
+    @Override
+    protected void runTest() throws Throwable {
+        Control control = abdera.getFactory().newControl();
+        assertThat(control).isNotNull();
+        control.setDraft(true);
+        assertThat(control.isDraft()).isTrue();
+        Element element = control.getFirstChild(Constants.DRAFT);
+        assertThat(element).isNotNull();
+        assertThat(element.getText()).isEqualTo("yes");
+        control.unsetDraft();
+        assertThat(control.getFirstChild()).isNull();
+    }
+}

Propchange: webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/control/TestSetUnsetDraft.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/axiom/trunk/testing/fom-testsuite/src/test/java/org/apache/axiom/ts/fom/AbderaTest.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/fom-testsuite/src/test/java/org/apache/axiom/ts/fom/AbderaTest.java?rev=1704737&r1=1704736&r2=1704737&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/fom-testsuite/src/test/java/org/apache/axiom/ts/fom/AbderaTest.java (original)
+++ webservices/axiom/trunk/testing/fom-testsuite/src/test/java/org/apache/axiom/ts/fom/AbderaTest.java Tue Sep 22 21:57:34 2015
@@ -22,9 +22,18 @@ import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
 import org.apache.abdera.Abdera;
+import org.apache.axiom.ts.fom.collection.TestSetAcceptRemove;
+import org.apache.axiom.ts.fom.control.TestSetUnsetDraft;
 
 public class AbderaTest extends TestCase {
     public static TestSuite suite() {
-        return new FOMTestSuiteBuilder(new Abdera()).build();
+        FOMTestSuiteBuilder builder = new FOMTestSuiteBuilder(new Abdera());
+        
+        // Doesn't work because _setElementValue creates an OMElementImpl instead of a FOMElement
+        builder.exclude(TestSetUnsetDraft.class);
+        // Fails with ConcurrentModificationException
+        builder.exclude(TestSetAcceptRemove.class);
+        
+        return builder.build();
     }
 }