use of javax.jcr.Workspace in project jackrabbit by apache.
the class ShareableNodeTest method testLock.
/**
* Verify that a lock applies to all nodes in a shared set (6.13.16).
*/
public void testLock() throws Exception {
// setup parent nodes and first child
Node a1 = testRootNode.addNode("a1");
ensureMixinType(a1, mixLockable);
Node a2 = testRootNode.addNode("a2");
Node b1 = a1.addNode("b1");
testRootNode.getSession().save();
// add mixin
ensureMixinType(b1, mixShareable);
ensureMixinType(b1, mixLockable);
b1.save();
// add child c
Node c = b1.addNode("c");
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];
// lock shareable node -> all nodes in shared set are locked
b1.lock(false, true);
try {
assertTrue(b2.isLocked());
} finally {
b1.unlock();
}
// deep-lock parent -> locks (common) child node
a1.lock(true, true);
try {
assertTrue(c.isLocked());
} finally {
a1.unlock();
}
}
use of javax.jcr.Workspace in project jackrabbit by apache.
the class ShareableNodeTest method testRestoreRemoveExisting.
/**
* Restore a shareable node that automatically removes an existing shareable
* node (6.13.19). In this case the particular shared node is removed but
* its descendants continue to exist below the remaining members of the
* shared set.
*/
public void testRestoreRemoveExisting() 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();
// make b1 shareable
ensureMixinType(b1, mixShareable);
b1.save();
// clone
Workspace workspace = b1.getSession().getWorkspace();
workspace.clone(workspace.getName(), b1.getPath(), a2.getPath() + "/b2", false);
// add child c
b1.addNode("c");
b1.save();
// make a2 versionable
ensureMixinType(a2, mixVersionable);
a2.save();
// check in version and check out again
Version v = a2.checkin();
a2.checkout();
// delete b2 and save
a2.getNode("b2").remove();
a2.save();
// verify shareable set contains one elements only
Node[] shared = getSharedSet(b1);
assertEquals(1, shared.length);
// restore version and remove existing (i.e. b1)
a2.restore(v, true);
// verify shareable set contains still one element
shared = getSharedSet(a2.getNode("b2"));
assertEquals(1, shared.length);
// verify child c still exists
Node[] children = toArray(a2.getNode("b2").getNodes());
assertEquals(1, children.length);
}
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
}
}
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());
}
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());
}
Aggregations