Search in sources :

Example 21 with Workspace

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

the class ShareableNodeTest method testLock.

/**
     * Verify that a lock applies to all nodes in a shared set (6.13.16).
     */
public void testLock() throws Exception {
    // setup parent nodes and first child
    Node a1 = testRootNode.addNode("a1");
    ensureMixinType(a1, mixLockable);
    Node a2 = testRootNode.addNode("a2");
    Node b1 = a1.addNode("b1");
    testRootNode.getSession().save();
    // add mixin
    ensureMixinType(b1, mixShareable);
    ensureMixinType(b1, mixLockable);
    b1.save();
    // add child c
    Node c = b1.addNode("c");
    b1.save();
    // clone
    Workspace workspace = b1.getSession().getWorkspace();
    workspace.clone(workspace.getName(), b1.getPath(), a2.getPath() + "/b2", false);
    Node[] shared = getSharedSet(b1);
    assertEquals(2, shared.length);
    b1 = shared[0];
    Node b2 = shared[1];
    // lock shareable node -> all nodes in shared set are locked
    b1.lock(false, true);
    try {
        assertTrue(b2.isLocked());
    } finally {
        b1.unlock();
    }
    // deep-lock parent -> locks (common) child node
    a1.lock(true, true);
    try {
        assertTrue(c.isLocked());
    } finally {
        a1.unlock();
    }
}
Also used : Node(javax.jcr.Node) Workspace(javax.jcr.Workspace)

Example 22 with Workspace

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

the class ShareableNodeTest method testRestoreRemoveExisting.

/**
     * Restore a shareable node that automatically removes an existing shareable
     * node (6.13.19). In this case the particular shared node is removed but
     * its descendants continue to exist below the remaining members of the
     * shared set.
     */
public void testRestoreRemoveExisting() throws Exception {
    // setup parent nodes and first child
    Node a1 = testRootNode.addNode("a1");
    Node a2 = testRootNode.addNode("a2");
    Node b1 = a1.addNode("b1");
    testRootNode.getSession().save();
    // make b1 shareable
    ensureMixinType(b1, mixShareable);
    b1.save();
    // clone
    Workspace workspace = b1.getSession().getWorkspace();
    workspace.clone(workspace.getName(), b1.getPath(), a2.getPath() + "/b2", false);
    // add child c
    b1.addNode("c");
    b1.save();
    // make a2 versionable
    ensureMixinType(a2, mixVersionable);
    a2.save();
    // check in version and check out again
    Version v = a2.checkin();
    a2.checkout();
    // delete b2 and save
    a2.getNode("b2").remove();
    a2.save();
    // verify shareable set contains one elements only
    Node[] shared = getSharedSet(b1);
    assertEquals(1, shared.length);
    // restore version and remove existing (i.e. b1)
    a2.restore(v, true);
    // verify shareable set contains still one element
    shared = getSharedSet(a2.getNode("b2"));
    assertEquals(1, shared.length);
    // verify child c still exists
    Node[] children = toArray(a2.getNode("b2").getNodes());
    assertEquals(1, children.length);
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) Workspace(javax.jcr.Workspace)

Example 23 with Workspace

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

the class ShareableNodeTest method testCloneToSameParent.

//--------------------------------------------------------- limitation tests
/**
     * Clone a mix:shareable node to the same workspace, with the same
     * parent. This is unsupported in Jackrabbit.
     */
public void testCloneToSameParent() throws Exception {
    // setup parent nodes and first child
    Node a = testRootNode.addNode("a");
    Node b1 = a.addNode("b1");
    testRootNode.getSession().save();
    // add mixin
    ensureMixinType(b1, mixShareable);
    b1.save();
    Workspace workspace = b1.getSession().getWorkspace();
    try {
        // clone to same parent
        workspace.clone(workspace.getName(), b1.getPath(), a.getPath() + "/b2", false);
        fail("Cloning inside same parent should fail.");
    } catch (UnsupportedRepositoryOperationException e) {
    // expected
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) Node(javax.jcr.Node) Workspace(javax.jcr.Workspace)

Example 24 with Workspace

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

the class ShareableNodeTest method testModifyDescendantAndSave.

/**
     * Verify that invoking save() on a share-ancestor will save changes in
     * all share-descendants.
     */
public void testModifyDescendantAndSave() throws Exception {
    // setup parent nodes and first child
    Node a1 = testRootNode.addNode("a1");
    Node a2 = testRootNode.addNode("a2");
    Node b1 = a1.addNode("b1");
    testRootNode.getSession().save();
    // add mixin
    ensureMixinType(b1, mixShareable);
    b1.save();
    // clone
    Workspace workspace = b1.getSession().getWorkspace();
    workspace.clone(workspace.getName(), b1.getPath(), a2.getPath() + "/b2", false);
    // add child node c to b1
    Node c = b1.addNode("c");
    b1.save();
    // add child d to c, this modifies c
    c.addNode("d");
    // save a2 (having path /testroot/a2): this should save c as well
    // since one of the paths to c is /testroot/a2/b2/c
    a2.save();
    assertFalse("Saving share-ancestor should save share-descendants", c.isModified());
}
Also used : Node(javax.jcr.Node) Workspace(javax.jcr.Workspace)

Example 25 with Workspace

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

the class ShareableNodeTest method testSharedNodePath.

/**
     * Verify that shared nodes return correct paths.
     */
public void testSharedNodePath() throws Exception {
    Node a1 = testRootNode.addNode("a1");
    Node a2 = a1.addNode("a2");
    Node b1 = a1.addNode("b1");
    ensureMixinType(b1, mixShareable);
    testRootNode.getSession().save();
    //now we have a shareable node N with path a1/b1
    Session session = testRootNode.getSession();
    Workspace workspace = session.getWorkspace();
    String path = a2.getPath() + "/b2";
    workspace.clone(workspace.getName(), b1.getPath(), path, false);
    //now we have another shareable node N' in the same shared set as N with path a1/a2/b2
    //using the path a1/a2/b2, we should get the node N' here
    Item item = session.getItem(path);
    assertEquals("unexpectedly got the path from another node from the same shared set", path, item.getPath());
}
Also used : Item(javax.jcr.Item) Node(javax.jcr.Node) Session(javax.jcr.Session) Workspace(javax.jcr.Workspace)

Aggregations

Workspace (javax.jcr.Workspace)105 Node (javax.jcr.Node)51 Session (javax.jcr.Session)25 AccessDeniedException (javax.jcr.AccessDeniedException)18 Test (org.junit.Test)18 RepositoryException (javax.jcr.RepositoryException)16 JackrabbitWorkspace (org.apache.jackrabbit.api.JackrabbitWorkspace)16 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)10 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)8 NodeTypeTemplate (javax.jcr.nodetype.NodeTypeTemplate)7 File (java.io.File)6 FileInputStream (java.io.FileInputStream)6 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 OutputStream (java.io.OutputStream)6 ObservationManager (javax.jcr.observation.ObservationManager)6 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)6 FileOutputStream (java.io.FileOutputStream)5 NodeIterator (javax.jcr.NodeIterator)4 Version (javax.jcr.version.Version)4