Search in sources :

Example 31 with Workspace

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

the class ShareableNodeTest method testDetectShareCycleOnMove.

/**
     * Verify that a share cycle is detected (6.13.13) when a node is moved.
     */
public void testDetectShareCycleOnMove() 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
    Node c = b1.addNode("c");
    b1.save();
    Node[] shared = getSharedSet(b1);
    assertEquals(2, shared.length);
    // move node
    try {
        workspace.move(testRootNode.getPath() + "/a2", c.getPath() + "/d");
        fail("Share cycle not detected on move.");
    } catch (RepositoryException e) {
    // expected
    }
}
Also used : Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) Workspace(javax.jcr.Workspace)

Example 32 with Workspace

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

the class ShareableNodeTest method testIsSame.

/**
     * Verify that Node.isSame returns <code>true</code> for shareable nodes
     * in the same shared set (6.13.21)
     */
public void testIsSame() 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];
    // verify b1 is same as b2 (and vice-versa)
    assertTrue(b1.isSame(b2));
    assertTrue(b2.isSame(b1));
}
Also used : Node(javax.jcr.Node) Workspace(javax.jcr.Workspace)

Example 33 with Workspace

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

the class ShareableNodeTest method testGetName.

/**
     * Verify that Node.getName returns the correct name in a shareable node
     * (6.13).
     */
public void testGetName() 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];
    // verify names of nodes b1/b2 in shared set
    assertEquals("b1", b1.getName());
    assertEquals("b2", b2.getName());
}
Also used : Node(javax.jcr.Node) Workspace(javax.jcr.Workspace)

Example 34 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 35 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)

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