Search in sources :

Example 16 with Workspace

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

the class ShareableNodeTest method testRemoveMixinFromSharedNode.

/**
     * Remove mix:shareable from a shareable node that has 2 nodes in the shared set. 
     */
public void testRemoveMixinFromSharedNode() 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.getSession().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];
    assertTrue(b2.isSame(b1));
    // (per Section 14.15 of JSR-283 specification)
    try {
        // remove mixin
        b1.removeMixin(mixShareable);
        b1.getSession().save();
        // If this happens, then b1 shouldn't be shareable anymore
        // ...
        assertFalse(b1.isNodeType(mixShareable));
        assertFalse(b2.isSame(b1));
    } catch (ConstraintViolationException e) {
    // one possible outcome if removing 'mix:shareable' isn't supported
    } catch (UnsupportedRepositoryOperationException e) {
    // also possible if the implementation doesn't support this
    // capability
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) Node(javax.jcr.Node) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) Workspace(javax.jcr.Workspace)

Example 17 with Workspace

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

the class ShareableNodeTest method testGetNodesByPattern.

/**
     * Verify that the shareable nodes returned by Node.getNodes(String) have
     * the right name.
     */
public void testGetNodesByPattern() 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);
    // a1.getNodes(*) should return b1
    Node[] children = toArray(a1.getNodes("*"));
    assertEquals(1, children.length);
    assertEquals("b1", children[0].getName());
    // a2.getNodes(*) should return b2
    children = toArray(a2.getNodes("*"));
    assertEquals(1, children.length);
    assertEquals("b2", children[0].getName());
}
Also used : Node(javax.jcr.Node) Workspace(javax.jcr.Workspace)

Example 18 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 19 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 20 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)

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