Search in sources :

Example 41 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 42 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 43 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)

Example 44 with Workspace

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

the class ShareableNodeTest method testRemoveDescendantAndSave.

//----------------------------------------------------- implementation tests
/**
     * Verify that invoking save() on a share-ancestor will save changes in
     * all share-descendants.
     */
public void testRemoveDescendantAndSave() 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
    Session session = b1.getSession();
    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();
    // remove child node c
    c.remove();
    // 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", session.hasPendingChanges());
}
Also used : Node(javax.jcr.Node) Session(javax.jcr.Session) Workspace(javax.jcr.Workspace)

Example 45 with Workspace

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

the class ShareableNodeTest method testGetIndex.

//------------------------------------------------------ specification tests
/**
     * Verify that Node.getIndex returns the correct index in a shareable
     * node (6.13).
     */
public void testGetIndex() throws Exception {
    // setup parent nodes and first child
    Node a1 = testRootNode.addNode("a1");
    Node a2 = testRootNode.addNode("a2");
    Node b1 = a1.addNode("b1");
    a2.addNode("b");
    testRootNode.getSession().save();
    // add mixin
    ensureMixinType(b1, mixShareable);
    b1.save();
    // clone
    Workspace workspace = b1.getSession().getWorkspace();
    workspace.clone(workspace.getName(), b1.getPath(), a2.getPath() + "/b", false);
    Node[] shared = getSharedSet(b1);
    assertEquals(2, shared.length);
    b1 = shared[0];
    Node b2 = shared[1];
    // verify indices of nodes b1/b2 in shared set
    assertEquals(1, b1.getIndex());
    assertEquals(2, b2.getIndex());
}
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