You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mr...@apache.org on 2009/03/01 07:26:58 UTC

svn commit: r748962 - in /xerces/java/trunk/tests/dom/traversal: ./ AbstractTestCase.java AllTests.java BasicTest.java

Author: mrglavas
Date: Sun Mar  1 06:26:58 2009
New Revision: 748962

URL: http://svn.apache.org/viewvc?rev=748962&view=rev
Log:
Adding basic tests for the DOM Element Traversal API.

Added:
    xerces/java/trunk/tests/dom/traversal/
    xerces/java/trunk/tests/dom/traversal/AbstractTestCase.java   (with props)
    xerces/java/trunk/tests/dom/traversal/AllTests.java   (with props)
    xerces/java/trunk/tests/dom/traversal/BasicTest.java   (with props)

Added: xerces/java/trunk/tests/dom/traversal/AbstractTestCase.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/tests/dom/traversal/AbstractTestCase.java?rev=748962&view=auto
==============================================================================
--- xerces/java/trunk/tests/dom/traversal/AbstractTestCase.java (added)
+++ xerces/java/trunk/tests/dom/traversal/AbstractTestCase.java Sun Mar  1 06:26:58 2009
@@ -0,0 +1,79 @@
+/*
+ * 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 dom.traversal;
+
+import java.io.IOException;
+import java.io.StringReader;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.ElementTraversal;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Michael Glavassevich, IBM
+ * @version $Id$
+ */
+public abstract class AbstractTestCase extends TestCase {
+    
+    private DocumentBuilder fDocumentBuilder;
+    
+    protected final void setUp() {
+        try {
+            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+            dbf.setNamespaceAware(true);
+            fDocumentBuilder = dbf.newDocumentBuilder();
+        }
+        catch (ParserConfigurationException pce) {
+            pce.printStackTrace();
+            fail(pce.getMessage());
+        }
+    }
+    
+    protected final void tearDown() {
+        fDocumentBuilder = null;
+    }
+    
+    protected final ElementTraversal parse(String input) {
+        try {
+            Document doc = fDocumentBuilder.parse(new InputSource(new StringReader(input)));
+            return toElementTraversal(doc.getDocumentElement());
+        } 
+        catch (SAXException se) {
+            se.printStackTrace();
+            fail(se.getMessage());
+        } 
+        catch (IOException ioe) {
+            ioe.printStackTrace();
+            fail(ioe.getMessage());
+        }
+        return null;
+    }
+    
+    protected final ElementTraversal toElementTraversal(Element e) {
+        assertTrue("e instanceof ElementTraversal", e == null || e instanceof ElementTraversal);
+        return (ElementTraversal) e;
+    }
+}

Propchange: xerces/java/trunk/tests/dom/traversal/AbstractTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xerces/java/trunk/tests/dom/traversal/AbstractTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: xerces/java/trunk/tests/dom/traversal/AllTests.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/tests/dom/traversal/AllTests.java?rev=748962&view=auto
==============================================================================
--- xerces/java/trunk/tests/dom/traversal/AllTests.java (added)
+++ xerces/java/trunk/tests/dom/traversal/AllTests.java Sun Mar  1 06:26:58 2009
@@ -0,0 +1,42 @@
+/*
+ * 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 dom.traversal;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ * All Element Traversal API Tests
+ * 
+ * @author Michael Glavassevich, IBM
+ * @version $Id$
+ */
+public class AllTests {
+    
+    public static void main(String[] args) {
+        TestRunner.run(AllTests.suite());
+    }
+    
+    public static Test suite() {
+        TestSuite suite = new TestSuite("Tests for the Element Traversal API.");
+        suite.addTestSuite(BasicTest.class);
+        return suite;
+    }
+
+}

Propchange: xerces/java/trunk/tests/dom/traversal/AllTests.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xerces/java/trunk/tests/dom/traversal/AllTests.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: xerces/java/trunk/tests/dom/traversal/BasicTest.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/tests/dom/traversal/BasicTest.java?rev=748962&view=auto
==============================================================================
--- xerces/java/trunk/tests/dom/traversal/BasicTest.java (added)
+++ xerces/java/trunk/tests/dom/traversal/BasicTest.java Sun Mar  1 06:26:58 2009
@@ -0,0 +1,131 @@
+/*
+ * 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 dom.traversal;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.ElementTraversal;
+
+/**
+ * @author Michael Glavassevich, IBM
+ * @version $Id$
+ */
+public class BasicTest extends AbstractTestCase {
+    
+    private static final String DOC1 = "<root>1<a/>2<b/>3<c/>4<d/><!-- foo -->5<e/>6<?target data?></root>";
+    private static final String DOC2 = "<root>1<a>2<b/>7<e/>9</a>3<c>5<d/>0<!-- bar -->8<f/>6</c>4</root>";
+    
+    public void testGetFirstChild1() {
+        ElementTraversal et = parse(DOC1);
+        Element e = et.getFirstElementChild();
+        assertEquals("a", e.getNodeName());
+    }
+    
+    public void testGetFirstChild2() {
+        ElementTraversal et = parse(DOC2);
+        Element e = et.getFirstElementChild();
+        assertEquals("a", e.getNodeName());
+        et = toElementTraversal(e);
+        e = et.getFirstElementChild();
+        assertEquals("b", e.getNodeName());
+    }
+    
+    public void testGetLastChild1() {
+        ElementTraversal et = parse(DOC1);
+        Element e = et.getLastElementChild();
+        assertEquals("e", e.getNodeName());
+    }
+    
+    public void testGetLastChild2() {
+        ElementTraversal et = parse(DOC2);
+        Element e = et.getLastElementChild();
+        assertEquals("c", e.getNodeName());
+        et = toElementTraversal(e);
+        e = et.getLastElementChild();
+        assertEquals("f", e.getNodeName());
+    }
+    
+    public void testGetNextElementSibling1() {
+        ElementTraversal et = parse(DOC1);
+        Element e = et.getFirstElementChild();
+        et = toElementTraversal(e);
+        e = et.getNextElementSibling();
+        assertEquals("b", e.getNodeName());
+        et = toElementTraversal(e);
+        e = et.getNextElementSibling();
+        assertEquals("c", e.getNodeName());
+        et = toElementTraversal(e);
+        e = et.getNextElementSibling();
+        assertEquals("d", e.getNodeName());
+    }
+    
+    public void testGetNextElementSibling2() {
+        ElementTraversal et = parse(DOC2);
+        Element e = et.getFirstElementChild();
+        et = toElementTraversal(e);
+        e = et.getNextElementSibling();
+        assertEquals("c", e.getNodeName());
+        et = toElementTraversal(e);
+        e = et.getFirstElementChild();
+        assertEquals("d", e.getNodeName());
+        et = toElementTraversal(e);
+        e = et.getNextElementSibling();
+        assertEquals("f", e.getNodeName());
+    }
+    
+    public void testGetPreviousElementSibling1() {
+        ElementTraversal et = parse(DOC1);
+        Element e = et.getLastElementChild();
+        et = toElementTraversal(e);
+        e = et.getPreviousElementSibling();
+        assertEquals("d", e.getNodeName());
+        et = toElementTraversal(e);
+        e = et.getPreviousElementSibling();
+        assertEquals("c", e.getNodeName());
+        et = toElementTraversal(e);
+        e = et.getPreviousElementSibling();
+        assertEquals("b", e.getNodeName());
+    }
+    
+    public void testGetPreviousElementSibling2() {
+        ElementTraversal et = parse(DOC2);
+        Element e = et.getLastElementChild();
+        et = toElementTraversal(e);
+        e = et.getPreviousElementSibling();
+        assertEquals("a", e.getNodeName());
+        et = toElementTraversal(e);
+        e = et.getLastElementChild();
+        assertEquals("e", e.getNodeName());
+        et = toElementTraversal(e);
+        e = et.getPreviousElementSibling();
+        assertEquals("b", e.getNodeName());
+    }
+    
+    public void testChildElementCount1() {
+        ElementTraversal et = parse(DOC1);
+        assertEquals(5, et.getChildElementCount());
+    }
+    
+    public void testChildElementCount2() {
+        ElementTraversal et = parse(DOC2);
+        assertEquals(2, et.getChildElementCount());
+        ElementTraversal et2 = toElementTraversal(et.getFirstElementChild());
+        assertEquals(2, et2.getChildElementCount());
+        et2 = toElementTraversal(et.getLastElementChild());
+        assertEquals(2, et2.getChildElementCount());
+    }
+}

Propchange: xerces/java/trunk/tests/dom/traversal/BasicTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xerces/java/trunk/tests/dom/traversal/BasicTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org