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
}
}
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));
}
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());
}
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());
}
Aggregations