Search in sources :

Example 11 with Workspace

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

the class ShareableNodeTest method testSearch.

/**
     * Verify that a descendant of a shareable node appears once in the
     * result set (6.13.23)
     */
public void testSearch() 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 new referenceable child
    Node c = b1.addNode("c");
    ensureMixinType(c, mixReferenceable);
    b1.save();
    String sql = "SELECT * FROM nt:unstructured WHERE jcr:uuid = '" + c.getUUID() + "'";
    QueryResult res = workspace.getQueryManager().createQuery(sql, Query.SQL).execute();
    List<Node> list = new ArrayList<Node>();
    NodeIterator iter = res.getNodes();
    while (iter.hasNext()) {
        list.add(iter.nextNode());
    }
    assertEquals(1, list.size());
    assertTrue(list.get(0).isSame(c));
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) Workspace(javax.jcr.Workspace)

Example 12 with Workspace

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

the class ShareableNodeTest method testRemoveSharedSet.

/**
     * Check new API Node.removeSharedSet() (6.13.4).
     */
public void testRemoveSharedSet() 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();
    testRootNode.getSession().save();
    // verify neither a1 nor a2 contain any more children
    assertFalse(a1.hasNodes());
    assertFalse(a2.hasNodes());
}
Also used : Node(javax.jcr.Node) Workspace(javax.jcr.Workspace)

Example 13 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 14 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 15 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)

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