Search in sources :

Example 11 with NodeIterator

use of javax.jcr.NodeIterator in project jackrabbit by apache.

the class VersionHistoryTest method testGetAllFrozenNodes.

/**
     * Test that {@link VersionHistory#getAllFrozenNodes()} returns an iterator
     * containing the frozen nodes of all versions that have been created by
     * {@link VersionManager#checkpoint(String)}.
     *
     * @see javax.jcr.version.VersionHistory#getAllFrozenNodes()
     * @since JCR 2.0
     */
public void testGetAllFrozenNodes() throws RepositoryException {
    VersionManager vm = versionableNode.getSession().getWorkspace().getVersionManager();
    String path = versionableNode.getPath();
    int cnt = 2;
    for (int i = 0; i < cnt; i++) {
        vm.checkpoint(path);
    }
    Set<String> frozenIds = new HashSet<String>();
    for (VersionIterator it = vm.getVersionHistory(path).getAllVersions(); it.hasNext(); ) {
        Version v = it.nextVersion();
        frozenIds.add(v.getFrozenNode().getIdentifier());
    }
    Set<String> test = new HashSet<String>();
    for (NodeIterator it = vHistory.getAllFrozenNodes(); it.hasNext(); ) {
        Node n = it.nextNode();
        assertTrue("Node " + n.getPath() + " must be of type frozen node", n.isNodeType("nt:frozenNode"));
        test.add(n.getIdentifier());
    }
    assertEquals("getAllFrozenNodes must return the IDs of all frozen nodes", frozenIds, test);
}
Also used : NodeIterator(javax.jcr.NodeIterator) Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionIterator(javax.jcr.version.VersionIterator) VersionManager(javax.jcr.version.VersionManager) HashSet(java.util.HashSet)

Example 12 with NodeIterator

use of javax.jcr.NodeIterator in project jackrabbit by apache.

the class MergeSubNodeTest method disable_testMergeNodeSubNodesMergeTest.

/**
     * Node.merge(): For each versionable node N in the subtree rooted at this
     * node,<br> a merge test is performed comparing N with its corresponding
     * node in workspace, N'.<br>
     */
@SuppressWarnings("deprecation")
public void disable_testMergeNodeSubNodesMergeTest() throws RepositoryException {
    //setCheckProperty(nodeToMerge);
    nodeToMerge.checkout();
    nodeToMerge.merge(workspace.getName(), true);
    // check subnodes if they were touched
    for (NodeIterator ni = nodeToMerge.getNodes(); ni.hasNext(); ) {
        Node n = ni.nextNode();
        if (n.getBaseVersion() != null) {
            assertTrue(n.getProperty(propertyName1).getString().equals(CHANGED_STRING));
        }
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node)

Example 13 with NodeIterator

use of javax.jcr.NodeIterator in project jackrabbit by apache.

the class RestoreTest method testRestoreOrder.

/**
     * Test the child ordering of restored nodes.
     * @throws RepositoryException
     */
@SuppressWarnings("deprecation")
public void testRestoreOrder() throws RepositoryException, NotExecutableException {
    // create a test-root that has orderable child nodes
    Node testRoot = versionableNode.addNode(nodeName4, "nt:unstructured");
    ensureMixinType(testRoot, mixVersionable);
    versionableNode.getSession().save();
    // create children of vNode and checkin
    Node child1 = testRoot.addNode(nodeName1);
    ensureMixinType(child1, mixVersionable);
    Node child2 = testRoot.addNode(nodeName2);
    ensureMixinType(child2, mixVersionable);
    testRoot.getSession().save();
    child1.checkin();
    child2.checkin();
    Version v1 = testRoot.checkin();
    // remove node 1
    testRoot.checkout();
    child1.remove();
    testRoot.getSession().save();
    testRoot.checkin();
    // restore version 1.0
    testRoot.restore(v1, true);
    // check order
    NodeIterator iter = testRoot.getNodes();
    assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext());
    Node n1 = iter.nextNode();
    assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext());
    Node n2 = iter.nextNode();
    String orderOk = nodeName1 + ", " + nodeName2;
    String order = n1.getName() + ", " + n2.getName();
    assertEquals("Invalid child node ordering", orderOk, order);
}
Also used : NodeIterator(javax.jcr.NodeIterator) Version(javax.jcr.version.Version) Node(javax.jcr.Node)

Example 14 with NodeIterator

use of javax.jcr.NodeIterator in project jackrabbit by apache.

the class RestoreTest method testRestoreOrder2Jcr2.

/**
     * Test the child ordering of restored nodes.
     * @throws RepositoryException
     */
public void testRestoreOrder2Jcr2() throws RepositoryException, NotExecutableException {
    // create a test-root that has orderable child nodes
    Node testRoot = versionableNode.addNode(nodeName4, "nt:unstructured");
    ensureMixinType(testRoot, mixVersionable);
    versionableNode.getSession().save();
    // create children of vNode and checkin
    Node child1 = testRoot.addNode(nodeName1);
    ensureMixinType(child1, mixVersionable);
    Node child2 = testRoot.addNode(nodeName2);
    ensureMixinType(child2, mixVersionable);
    testRoot.getSession().save();
    versionManager.checkin(child1.getPath());
    versionManager.checkin(child2.getPath());
    Version v1 = versionManager.checkin(testRoot.getPath());
    // reoder nodes
    versionManager.checkout(testRoot.getPath());
    testRoot.orderBefore(nodeName2, nodeName1);
    testRoot.getSession().save();
    versionManager.checkin(testRoot.getPath());
    // restore version 1.0
    versionManager.restore(v1, true);
    // check order
    NodeIterator iter = testRoot.getNodes();
    assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext());
    Node n1 = iter.nextNode();
    assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext());
    Node n2 = iter.nextNode();
    String orderOk = nodeName1 + ", " + nodeName2;
    String order = n1.getName() + ", " + n2.getName();
    assertEquals("Invalid child node ordering", orderOk, order);
}
Also used : NodeIterator(javax.jcr.NodeIterator) Version(javax.jcr.version.Version) Node(javax.jcr.Node)

Example 15 with NodeIterator

use of javax.jcr.NodeIterator in project jackrabbit by apache.

the class RestoreTest method testRestoreOrderJcr2_3.

/**
     * Test the child ordering of restored nodes.
     * @throws RepositoryException
     */
public void testRestoreOrderJcr2_3() throws RepositoryException, NotExecutableException {
    // create a test-root that has orderable child nodes
    Node testRoot = versionableNode.addNode(nodeName4, "nt:unstructured");
    ensureMixinType(testRoot, mixVersionable);
    versionableNode.getSession().save();
    // create children of vNode and checkin
    Node child1 = testRoot.addNode(nodeName1);
    ensureMixinType(child1, mixVersionable);
    Node child2 = testRoot.addNode(nodeName2);
    ensureMixinType(child2, mixVersionable);
    testRoot.getSession().save();
    versionManager.checkin(child1.getPath());
    versionManager.checkin(child2.getPath());
    Version v1 = versionManager.checkin(testRoot.getPath());
    // remove node 1
    versionManager.checkout(testRoot.getPath());
    child1.remove();
    testRoot.getSession().save();
    versionManager.checkout(testRoot.getPath());
    // restore version 1.0
    versionManager.restore(testRoot.getPath(), v1.getName(), true);
    // check order
    NodeIterator iter = testRoot.getNodes();
    assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext());
    Node n1 = iter.nextNode();
    assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext());
    Node n2 = iter.nextNode();
    String orderOk = nodeName1 + ", " + nodeName2;
    String order = n1.getName() + ", " + n2.getName();
    assertEquals("Invalid child node ordering", orderOk, order);
}
Also used : NodeIterator(javax.jcr.NodeIterator) Version(javax.jcr.version.Version) Node(javax.jcr.Node)

Aggregations

NodeIterator (javax.jcr.NodeIterator)307 Node (javax.jcr.Node)214 Session (javax.jcr.Session)55 QueryResult (javax.jcr.query.QueryResult)52 RepositoryException (javax.jcr.RepositoryException)40 Query (javax.jcr.query.Query)40 Test (org.junit.Test)36 QueryManager (javax.jcr.query.QueryManager)34 PropertyIterator (javax.jcr.PropertyIterator)30 ArrayList (java.util.ArrayList)26 Property (javax.jcr.Property)24 Version (javax.jcr.version.Version)23 NoSuchElementException (java.util.NoSuchElementException)19 Value (javax.jcr.Value)19 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)19 HashSet (java.util.HashSet)13 PathNotFoundException (javax.jcr.PathNotFoundException)12 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)11 NodeImpl (org.apache.jackrabbit.core.NodeImpl)11 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)11