Search in sources :

Example 36 with Workspace

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

the class ShareableNodeTest method testRemoveSharedSetSaveOneParentOnly.

/**
     * Invoke Node.removeSharedSet(), but save only one of the parent nodes
     * of the shared set. This doesn't need to be supported according to the
     * specification (6.13.4).
     */
public void testRemoveSharedSetSaveOneParentOnly() 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);
    // remove shared set
    b1.removeSharedSet();
    try {
        // save only one of the parents, should fail
        a1.save();
        fail("Removing a shared set requires saving all parents.");
    } catch (ConstraintViolationException e) {
    // expected
    }
}
Also used : Node(javax.jcr.Node) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) Workspace(javax.jcr.Workspace)

Example 37 with Workspace

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

the class ShareableNodeTest method testDetectShareCycleOnClone.

/**
     * Verify that a share cycle is detected (6.13.13) when a shareable node
     * is cloned.
     */
public void testDetectShareCycleOnClone() throws Exception {
    // setup parent nodes and first child
    Node a1 = testRootNode.addNode("a1");
    Node b1 = a1.addNode("b1");
    testRootNode.getSession().save();
    // add mixin
    ensureMixinType(b1, mixShareable);
    b1.save();
    Workspace workspace = b1.getSession().getWorkspace();
    try {
        // clone underneath b1: this must fail
        workspace.clone(workspace.getName(), b1.getPath(), b1.getPath() + "/c", false);
        fail("Share cycle not detected on clone.");
    } catch (RepositoryException e) {
    // expected
    }
}
Also used : Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) Workspace(javax.jcr.Workspace)

Example 38 with Workspace

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

the class ShareableNodeTest method testRemoveShare.

/**
     * Check new API Node.removeShare() (6.13.4).
     */
public void testRemoveShare() 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);
    Node[] shared = getSharedSet(b1);
    assertEquals(2, shared.length);
    b1 = shared[0];
    Node b2 = shared[1];
    // remove b1 from shared set
    b1.removeShare();
    a1.save();
    // verify shared set of b2 contains only 1 item, namely b2 itself
    shared = getSharedSet(b2);
    assertEquals(1, shared.length);
    assertTrue(shared[0].isSame(b2));
}
Also used : Node(javax.jcr.Node) Workspace(javax.jcr.Workspace)

Example 39 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 40 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)

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