/** * Tests the <code>first()</code> function. * <p> * For configuration description see {@link XPathDocOrderTest}. */ public void testDocOrderFirstFunction() throws Exception { String xpath = xpathRoot + "/*[first()]"; String resultPath = testRootNode.getNodes().nextNode().getPath(); docOrderTest(new Statement(xpath, qsXPATH), resultPath); }
public void testParentInAttribute4() throws RepositoryException { String stmt = testPath + "//child[../@foo1 = 'bar1']"; QueryResult result = qm.createQuery(stmt, Query.XPATH).execute(); assertTrue("Wrong size of NodeIterator in result", result.getNodes().getSize() > 0); assertEquals("child", result.getNodes().nextNode().getName()); }
/** * Orders the node first among its siblings. */ public static void orderFirst(Node node) throws RepositoryException { Node parent = node.getParent(); NodeIterator siblings = parent.getNodes(); Node firstSibling = siblings.nextNode(); if (!firstSibling.isSame(node)) { parent.orderBefore(node.getName(), firstSibling.getName()); } }
@Test public void testSearchForAreasContainingImage() throws InvalidQueryException, RepositoryException { String statement = "select * from [mgnl:component] where image is not null"; NodeIterator result = QueryUtil.search("website", statement, Query.JCR_SQL2, NodeTypes.Area.NAME); while (result.hasNext()) { Node node = result.nextNode(); assertEquals(NodeTypes.Area.NAME, node.getPrimaryNodeType().getName()); assertEquals("/queryTest/subPage2/subPage2/content", node.getPath()); } }
/** * @return the overall size of the query without limit */ private long getResultSetSize(String queryString) throws RepositoryException { QueryResult qr = doQuery(queryString, Integer.MAX_VALUE, 0); NodeIterator iter = NodeUtil.filterDuplicates(NodeUtil.filterParentNodeType(qr.getNodes(), NodeTypes.Page.NAME)); long count = 0; while (iter.hasNext()) { iter.nextNode(); count++; } return count; }
private Node getLastChild(Node parent, Collection<String> childNames) throws RepositoryException { Node lastMatch = null; NodeIterator nodes = parent.getNodes(); while (nodes.hasNext()) { Node child = nodes.nextNode(); if (childNames.contains(child.getName())) { lastMatch = child; } } return lastMatch; }
public void testParentInAttribute1() throws RepositoryException { String stmt = testPath + "//child[../@foo1]"; QueryResult result = qm.createQuery(stmt, Query.XPATH).execute(); assertTrue("Wrong size of NodeIterator in result", result.getNodes().getSize() > 0); assertEquals("child", result.getNodes().nextNode().getName()); }
private void assertNodeOrder(Node node, String[] names) throws RepositoryException { NodeIterator nodes = node.getNodes(); for (String name : names) { Node childNode = nodes.nextNode(); if (!childNode.getName().equals(name)) { fail("Expected [" + name + "] was [" + childNode.getName() + "]"); } } } }
public void testParentInAttribute2() throws RepositoryException { String stmt = testPath + "//child[../child/@foo2]"; QueryResult result = qm.createQuery(stmt, Query.XPATH).execute(); assertTrue("Wrong size of NodeIterator in result", result.getNodes().getSize() > 0); assertEquals("child", result.getNodes().nextNode().getName()); }
public void testParentInPath() throws RepositoryException { String stmt = testPath + "//child/..[@foo1]"; QueryResult result = qm.createQuery(stmt, Query.XPATH).execute(); assertEquals("Wrong size of NodeIterator in result", 1, result.getNodes().getSize()); assertEquals("base", result.getNodes().nextNode().getName()); }
public void testParentInAttribute3() throws RepositoryException { String stmt = testPath + "//child[../../base/@foo1]"; QueryResult result = qm.createQuery(stmt, Query.XPATH).execute(); assertTrue("Wrong size of NodeIterator in result", result.getNodes().getSize() > 0); assertEquals("child", result.getNodes().nextNode().getName()); }
public void testParentAttributeWithDescendant() throws RepositoryException { String stmt = testPath + "//base[../base/@foo1 = 'bar1']/child"; QueryResult result = qm.createQuery(stmt, Query.XPATH).execute(); assertTrue("Wrong size of NodeIterator in result", result.getNodes().getSize() > 0); assertEquals("child", result.getNodes().nextNode().getName()); }