Search in sources :

Example 26 with Workspace

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

the class ShareableNodesTest method testRemoveShare.

public void testRemoveShare() throws RepositoryException {
    Node n1 = testRootNode.addNode(nodeName1);
    Node n2 = testRootNode.addNode(nodeName2);
    Node s = n1.addNode(nodeName3);
    s.addMixin(mixShareable);
    testRootNode.save();
    Workspace wsp = superuser.getWorkspace();
    wsp.clone(wsp.getName(), s.getPath(), n2.getPath() + "/" + s.getName(), false);
    EventResult result = new EventResult(log);
    addEventListener(result);
    removeFromSharedSet(n2.getNode(nodeName3));
    testRootNode.save();
    checkNodeRemoved(result.getEvents(DEFAULT_WAIT_TIMEOUT), new String[] { nodeName2 + "/" + nodeName3 }, new String[0]);
}
Also used : EventResult(org.apache.jackrabbit.test.api.observation.EventResult) Node(javax.jcr.Node) Workspace(javax.jcr.Workspace)

Example 27 with Workspace

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

the class ShareableNodesTest method testAddShare.

public void testAddShare() throws RepositoryException {
    Node n1 = testRootNode.addNode(nodeName1);
    Node n2 = testRootNode.addNode(nodeName2);
    Node s = n1.addNode(nodeName3);
    s.addMixin(mixShareable);
    testRootNode.save();
    EventResult result = new EventResult(log);
    addEventListener(result);
    Workspace wsp = superuser.getWorkspace();
    wsp.clone(wsp.getName(), s.getPath(), n2.getPath() + "/" + s.getName(), false);
    checkNodeAdded(result.getEvents(DEFAULT_WAIT_TIMEOUT), new String[] { nodeName2 + "/" + nodeName3 }, new String[0]);
}
Also used : EventResult(org.apache.jackrabbit.test.api.observation.EventResult) Node(javax.jcr.Node) Workspace(javax.jcr.Workspace)

Example 28 with Workspace

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

the class ShareableNodeTest method testImportExportNtShare.

/**
     * Verify export and import of a tree containing multiple nodes in the
     * same shared set (6.13.14). The first serialized node in that shared
     * set is serialized in the normal fashion (with all of its properties
     * and children), but any subsequent shared node in that shared set is
     * serialized as a special node of type <code>nt:share</code>, which
     * contains only the <code>jcr:uuid</code> property of the shared node
     * and the <code>jcr:primaryType</code> property indicating the type
     * <code>nt:share</code>.
     */
public void testImportExportNtShare() throws Exception {
    // setup parent nodes and first child
    Node p = testRootNode.addNode("p");
    Node a1 = p.addNode("a1");
    Node a2 = p.addNode("a2");
    Node b1 = a1.addNode("b1");
    testRootNode.getSession().save();
    // add mixin
    ensureMixinType(b1, mixShareable);
    b1.save();
    // clone
    Session session = b1.getSession();
    Workspace workspace = session.getWorkspace();
    workspace.clone(workspace.getName(), b1.getPath(), a2.getPath() + "/b2", false);
    // create temp file
    File tmpFile = File.createTempFile("test", null);
    tmpFile.deleteOnExit();
    // export system view of /p
    OutputStream out = new FileOutputStream(tmpFile);
    try {
        session.exportSystemView(p.getPath(), out, false, false);
    } finally {
        out.close();
    }
    // delete p and save
    p.remove();
    testRootNode.getSession().save();
    // and import again underneath test root
    InputStream in = new FileInputStream(tmpFile);
    try {
        workspace.importXML(testRootNode.getPath(), in, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW);
    } finally {
        try {
            in.close();
        } catch (IOException ignore) {
        }
    }
    // verify shared set consists of two nodes
    Node[] shared = getSharedSet(testRootNode.getNode("p/a1/b1"));
    assertEquals(2, shared.length);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Node(javax.jcr.Node) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) Session(javax.jcr.Session) Workspace(javax.jcr.Workspace)

Example 29 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 30 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)

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