test/javax/xml/jaxp/unittest/dom/ElementTraversal.java

Print this page




  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package dom;
  24 
  25 import java.io.IOException;
  26 import java.io.InputStream;
  27 import javax.xml.parsers.DocumentBuilder;
  28 import javax.xml.parsers.DocumentBuilderFactory;
  29 import javax.xml.parsers.ParserConfigurationException;
  30 import org.testng.Assert;
  31 import org.testng.annotations.DataProvider;
  32 import org.testng.annotations.Test;
  33 import org.w3c.dom.Document;

  34 import org.w3c.dom.Element;
  35 import org.xml.sax.SAXException;
  36 
  37 /*
  38  * @bug 8135283
  39  * @summary Tests for the Element Traversal interface.
  40  */
  41 
  42 public class ElementTraversal {


















  43     /*
  44        Verifies the ElementTraversal interface by exercising all of its five
  45        methods while reading through the xml document.
  46      */
  47     @Test(dataProvider = "doc")
  48     public void test(Document doc) {
  49         org.w3c.dom.ElementTraversal et = (org.w3c.dom.ElementTraversal)doc.getDocumentElement();
  50         //4 toys are listed
  51         Assert.assertEquals(et.getChildElementCount(), 4);
  52 
  53         //The 1st is the Martian
  54         Element toy1 = et.getFirstElementChild();
  55         verify(toy1, "1", "The Martian");
  56 
  57         //toy1 has no previous element
  58         Element noE = ((org.w3c.dom.ElementTraversal)toy1).getPreviousElementSibling();
  59         Assert.assertEquals(noE, null);
  60 
  61         //The 1st toy's next element is toy2, the Doll
  62         Element toy2 = ((org.w3c.dom.ElementTraversal)toy1).getNextElementSibling();




  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package dom;
  24 
  25 import java.io.IOException;
  26 import java.io.InputStream;
  27 import javax.xml.parsers.DocumentBuilder;
  28 import javax.xml.parsers.DocumentBuilderFactory;
  29 import javax.xml.parsers.ParserConfigurationException;
  30 import org.testng.Assert;
  31 import org.testng.annotations.DataProvider;
  32 import org.testng.annotations.Test;
  33 import org.w3c.dom.Document;
  34 import org.w3c.dom.DOMImplementation;
  35 import org.w3c.dom.Element;
  36 import org.xml.sax.SAXException;
  37 
  38 /*
  39  * @bug 8135283 8138721
  40  * @summary Tests for the Element Traversal interface.
  41  */
  42 
  43 public class ElementTraversal {
  44     /*
  45        Verifies that ElementTraversal is supported.
  46      */
  47     @Test(dataProvider = "doc")
  48     public void testHasFeature(Document doc) {
  49         DOMImplementation di = doc.getImplementation();
  50 
  51         //return false if feasure == null
  52         Assert.assertFalse(di.hasFeature(null, null));
  53         
  54         //A feature is supported without specifying version
  55         Assert.assertTrue(di.hasFeature("ElementTraversal", null));
  56         Assert.assertTrue(di.hasFeature("ElementTraversal", ""));
  57         
  58         //ElementTraversal Version 1.0 is supported
  59         Assert.assertTrue(di.hasFeature("ElementTraversal", "1.0"));        
  60     }
  61 
  62     /*
  63        Verifies the ElementTraversal interface by exercising all of its five
  64        methods while reading through the xml document.
  65      */
  66     @Test(dataProvider = "doc")
  67     public void test(Document doc) {
  68         org.w3c.dom.ElementTraversal et = (org.w3c.dom.ElementTraversal)doc.getDocumentElement();
  69         //4 toys are listed
  70         Assert.assertEquals(et.getChildElementCount(), 4);
  71 
  72         //The 1st is the Martian
  73         Element toy1 = et.getFirstElementChild();
  74         verify(toy1, "1", "The Martian");
  75 
  76         //toy1 has no previous element
  77         Element noE = ((org.w3c.dom.ElementTraversal)toy1).getPreviousElementSibling();
  78         Assert.assertEquals(noE, null);
  79 
  80         //The 1st toy's next element is toy2, the Doll
  81         Element toy2 = ((org.w3c.dom.ElementTraversal)toy1).getNextElementSibling();