/* * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. */ /* * 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.qetest.dtm; import com.sun.org.apache.xml.internal.dtm.Axis; import com.sun.org.apache.xml.internal.dtm.DTM; import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator; import java.io.FilePermission; import java.util.ArrayList; import java.util.List; import jaxp.library.JAXPBaseTest; import static org.apache.qetest.dtm.QeDtmConst.XML_DIR; import static org.apache.qetest.dtm.QeDtmConst.createDTM; import static org.testng.Assert.assertEquals; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; /** * Basic API test for DTMAxisIterator. Iterator on different Axis type. * */ public class TestDTMIterDeep extends JAXPBaseTest { /** * Iterator on different Axis type. * * @param axisType axis type. * @param expectedLastNode expected last node we will validate. * @param expectedTotal expected total node number we will validate. */ @Test(dataProvider = "axisProvider") public void test(int axisType, int expectedLastNode, int expectedTotal) { setPermissions(new RuntimePermission("accessClassInPackage.com.sun.org.apache.xml.internal.utils"), new RuntimePermission("accessClassInPackage.com.sun.org.apache.xpath.internal.objects"), new FilePermission(System.getProperty("test.src") + "/-", "read")); String deepFile = XML_DIR + "xtestdata/elem10kdeep.xml"; List lines = new ArrayList<>(); lines.add("Axis is " + Axis.getNames(axisType).toUpperCase()); DTM dtm = createDTM(0, deepFile, lines); // Get various nodes to use as context nodes. int DNode = dtm.getFirstChild(dtm.getDocument()); assertEquals(dtm.getNodeName(dtm.getFirstChild(DNode)), "e1"); // Get an iterator for Descendant:: axis. DTMAxisIterator iter = dtm.getAxisIterator(axisType); iter.setStartNode(DNode); int lastNode = 0; int numOfNodes = 0; for (int atNode = iter.next(); DTM.NULL != atNode; atNode = iter.next()) { lastNode = atNode; numOfNodes = numOfNodes + 1; // Need to know that we Iterated the whole tree } assertEquals(lastNode, expectedLastNode); assertEquals(numOfNodes, expectedTotal); } /** * Axis types for testing. * @return an array contains axis type and its expected number. */ @DataProvider public Object[][] axisProvider(){ return new Object[][]{ {Axis.DESCENDANT, 75538, 10000}, {Axis.DESCENDANTORSELF, 75538, 10001}, {Axis.ANCESTOR, 65536, 1}, {Axis.ANCESTORORSELF, 65537, 2}, }; } }