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