use of javax.jcr.Workspace in project jackrabbit by apache.
the class ShareableNodeTest method testRemoveMixinFromSharedNode.
/**
* Remove mix:shareable from a shareable node that has 2 nodes in the shared set.
*/
public void testRemoveMixinFromSharedNode() 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.getSession().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];
assertTrue(b2.isSame(b1));
// (per Section 14.15 of JSR-283 specification)
try {
// remove mixin
b1.removeMixin(mixShareable);
b1.getSession().save();
// If this happens, then b1 shouldn't be shareable anymore
// ...
assertFalse(b1.isNodeType(mixShareable));
assertFalse(b2.isSame(b1));
} catch (ConstraintViolationException e) {
// one possible outcome if removing 'mix:shareable' isn't supported
} catch (UnsupportedRepositoryOperationException e) {
// also possible if the implementation doesn't support this
// capability
}
}
use of javax.jcr.Workspace in project jackrabbit by apache.
the class ShareableNodeTest method testGetNodesByPattern.
/**
* Verify that the shareable nodes returned by Node.getNodes(String) have
* the right name.
*/
public void testGetNodesByPattern() 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);
// a1.getNodes(*) should return b1
Node[] children = toArray(a1.getNodes("*"));
assertEquals(1, children.length);
assertEquals("b1", children[0].getName());
// a2.getNodes(*) should return b2
children = toArray(a2.getNodes("*"));
assertEquals(1, children.length);
assertEquals("b2", children[0].getName());
}
use of javax.jcr.Workspace in project jackrabbit by apache.
the class ShareableNodeTest method testRemoveSharedSetSaveOneParentOnly.
/**
* Invoke Node.removeSharedSet(), but save only one of the parent nodes
* of the shared set. This doesn't need to be supported according to the
* specification (6.13.4).
*/
public void testRemoveSharedSetSaveOneParentOnly() 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();
try {
// save only one of the parents, should fail
a1.save();
fail("Removing a shared set requires saving all parents.");
} catch (ConstraintViolationException e) {
// expected
}
}
use of javax.jcr.Workspace in project jackrabbit by apache.
the class ShareableNodeTest method testDetectShareCycleOnClone.
/**
* Verify that a share cycle is detected (6.13.13) when a shareable node
* is cloned.
*/
public void testDetectShareCycleOnClone() throws Exception {
// setup parent nodes and first child
Node a1 = testRootNode.addNode("a1");
Node b1 = a1.addNode("b1");
testRootNode.getSession().save();
// add mixin
ensureMixinType(b1, mixShareable);
b1.save();
Workspace workspace = b1.getSession().getWorkspace();
try {
// clone underneath b1: this must fail
workspace.clone(workspace.getName(), b1.getPath(), b1.getPath() + "/c", false);
fail("Share cycle not detected on clone.");
} catch (RepositoryException e) {
// expected
}
}
use of javax.jcr.Workspace in project jackrabbit by apache.
the class ShareableNodeTest method testRemoveShare.
/**
* Check new API Node.removeShare() (6.13.4).
*/
public void testRemoveShare() 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];
// remove b1 from shared set
b1.removeShare();
a1.save();
// verify shared set of b2 contains only 1 item, namely b2 itself
shared = getSharedSet(b2);
assertEquals(1, shared.length);
assertTrue(shared[0].isSame(b2));
}
Aggregations