Search in sources :

Example 6 with Workspace

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

the class ShareableNodeTest method testPathConstraint.

public void testPathConstraint() throws RepositoryException {
    Node n1 = testRootNode.addNode(nodeName1);
    Node n2 = testRootNode.addNode(nodeName2);
    Node s = n1.addNode(nodeName3);
    s.setProperty(propertyName1, "value");
    s.addMixin(mixShareable);
    Node n4 = s.addNode(nodeName4);
    n4.setProperty(propertyName2, "value");
    testRootNode.save();
    Workspace wsp = superuser.getWorkspace();
    wsp.clone(wsp.getName(), s.getPath(), n2.getPath() + "/" + s.getName(), false);
    String stmt = testPath + "/" + nodeName1 + "/*[@" + propertyName1 + "='value']";
    NodeIterator nodes = executeQuery(stmt).getNodes();
    assertEquals("wrong result size", 1, nodes.getSize());
    // spec does not say which path must be returned -> use isSame()
    assertTrue("wrong node", s.isSame(nodes.nextNode()));
    stmt = testPath + "/" + nodeName2 + "/*[@" + propertyName1 + "='value']";
    nodes = executeQuery(stmt).getNodes();
    assertEquals("wrong result size", 1, nodes.getSize());
    // spec does not say which path must be returned -> use isSame()
    assertTrue("wrong node", s.isSame(nodes.nextNode()));
    stmt = testPath + "//*[@" + propertyName1 + "='value']";
    nodes = executeQuery(stmt).getNodes();
    assertEquals("wrong result size", 1, nodes.getSize());
    // spec does not say which path must be returned -> use isSame()
    assertTrue("wrong node", s.isSame(nodes.nextNode()));
    stmt = testPath + "//*[@" + propertyName2 + "='value']";
    nodes = executeQuery(stmt).getNodes();
    assertEquals("wrong result size", 1, nodes.getSize());
    // spec does not say which path must be returned -> use isSame()
    assertTrue("wrong node", n4.isSame(nodes.nextNode()));
    // remove a node from the shared set
    s.removeShare();
    testRootNode.save();
    s = n2.getNode(nodeName3);
    stmt = testPath + "/" + nodeName1 + "/*[@" + propertyName1 + "='value']";
    nodes = executeQuery(stmt).getNodes();
    assertEquals("wrong result size", 0, nodes.getSize());
    stmt = testPath + "/" + nodeName2 + "/*[@" + propertyName1 + "='value']";
    nodes = executeQuery(stmt).getNodes();
    assertEquals("wrong result size", 1, nodes.getSize());
    // spec does not say which path must be returned -> use isSame()
    assertTrue("wrong node", s.isSame(nodes.nextNode()));
    stmt = testPath + "//*[@" + propertyName1 + "='value']";
    nodes = executeQuery(stmt).getNodes();
    assertEquals("wrong result size", 1, nodes.getSize());
    // spec does not say which path must be returned -> use isSame()
    assertTrue("wrong node", s.isSame(nodes.nextNode()));
    // remove remaining node from the shared set
    s.removeShare();
    testRootNode.save();
    stmt = testPath + "/" + nodeName1 + "/*[@" + propertyName1 + "='value']";
    nodes = executeQuery(stmt).getNodes();
    assertEquals("wrong result size", 0, nodes.getSize());
    stmt = testPath + "/" + nodeName2 + "/*[@" + propertyName1 + "='value']";
    nodes = executeQuery(stmt).getNodes();
    assertEquals("wrong result size", 0, nodes.getSize());
    stmt = testPath + "//*[@" + propertyName1 + "='value']";
    nodes = executeQuery(stmt).getNodes();
    assertEquals("wrong result size", 0, nodes.getSize());
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node) Workspace(javax.jcr.Workspace)

Example 7 with Workspace

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

the class CopyTest method testCopy.

public void testCopy() throws RepositoryException {
    Workspace wsp = superuser.getWorkspace();
    VersionManager vMgr = wsp.getVersionManager();
    String srcPath = versionableNode.getPath();
    String dstPath = getProperty("destination");
    wsp.copy(srcPath, dstPath);
    // check versionable
    Node v = superuser.getNode(dstPath);
    assertTrue("Copied Node.isNodeType(mix:simpleVersionable) must return true.", v.isNodeType(mixSimpleVersionable));
    assertFalse("Copied Node.isNodeType(mix:versionable) must return false.", v.isNodeType(mixVersionable));
    // check different version history
    VersionHistory vh1 = vMgr.getVersionHistory(srcPath);
    VersionHistory vh2 = vMgr.getVersionHistory(dstPath);
    assertFalse("Copied node needs a new version history.", vh1.isSame(vh2));
    // check if 1 version
    assertEquals("Copied node must have 1 version.", 1, getNumberOfVersions(vh2));
}
Also used : Node(javax.jcr.Node) VersionManager(javax.jcr.version.VersionManager) VersionHistory(javax.jcr.version.VersionHistory) Workspace(javax.jcr.Workspace)

Example 8 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 9 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 10 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)

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