use of javax.jcr.Workspace in project jackrabbit by apache.
the class ShareableNodeTest method testClone.
/**
* Clone a mix:shareable node to the same workspace (6.13.20). Verify
* that cloning without mix:shareable fails.
*/
public void testClone() 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();
Workspace workspace = b1.getSession().getWorkspace();
try {
// clone (1st attempt, without mix:shareable, should fail)
workspace.clone(workspace.getName(), b1.getPath(), a2.getPath() + "/b2", false);
fail("Cloning a node into the same workspace should fail.");
} catch (RepositoryException e) {
// expected
}
// add mixin
ensureMixinType(b1, mixShareable);
b1.save();
// clone (2nd attempt, with mix:shareable)
workspace.clone(workspace.getName(), b1.getPath(), a2.getPath() + "/b2", false);
}
use of javax.jcr.Workspace in project jackrabbit by apache.
the class ShareableNodeTest method testAddChild.
/**
* Add a child to a shareable node and verify that another node in the
* same shared set has the same child and is modified when the first
* one is (6.13.11).
*/
public void testAddChild() 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];
// add node to b1, verify b2 is modified as well and contains that child
b1.addNode("c");
assertTrue(b2.isModified());
assertTrue(b2.hasNode("c"));
b1.save();
}
use of javax.jcr.Workspace in project jackrabbit by apache.
the class ShareableNodeTest method testMoveShareableNode.
/**
* Move a node in a shared set.
*/
public void testMoveShareableNode() throws Exception {
// setup parent nodes and first children
Node a1 = testRootNode.addNode("a1");
Node a2 = testRootNode.addNode("a2");
Node b = a1.addNode("b");
testRootNode.getSession().save();
// add mixin
ensureMixinType(b, mixShareable);
b.getSession().save();
// move
Workspace workspace = b.getSession().getWorkspace();
// move shareable node
String newPath = a2.getPath() + "/b";
workspace.move(b.getPath(), newPath);
// move was performed using the workspace, so refresh the session
b.getSession().refresh(false);
assertEquals(newPath, b.getPath());
}
use of javax.jcr.Workspace in project jackrabbit by apache.
the class ShareableNodeTest method testGetSharedSet.
/**
* Check new API Node.getSharedSet() (6.13.1)
*/
public void testGetSharedSet() 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);
// verify shared set contains 2 items
Node[] shared = getSharedSet(b1);
assertEquals(2, shared.length);
}
use of javax.jcr.Workspace in project jackrabbit by apache.
the class ShareableNodeTest method testImportSystemViewCollision.
/**
* Verify system view import via workspace (6.13.14). Export a system view
* containing a shareable node and verify, that reimporting underneath
* a different parent adds another member to the shared set and does not
* duplicate children nodes.
*/
public void testImportSystemViewCollision() throws Exception {
// setup parent nodes and first child
Node a1 = testRootNode.addNode("a1");
Node a2 = testRootNode.addNode("a2");
Node a3 = testRootNode.addNode("a3");
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);
// add child c to shareable nodes b1 & b2
b1.addNode("c");
b1.save();
// create temp file
File tmpFile = File.createTempFile("test", null);
tmpFile.deleteOnExit();
// export system view of /a1/b1
OutputStream out = new FileOutputStream(tmpFile);
try {
session.exportSystemView(b1.getPath(), out, false, false);
} finally {
out.close();
}
// and import again underneath /a3
InputStream in = new FileInputStream(tmpFile);
try {
workspace.importXML(a3.getPath(), in, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW);
} finally {
try {
in.close();
} catch (IOException ignore) {
}
}
// verify there's another element in the shared set
Node[] shared = getSharedSet(b1);
assertEquals(3, shared.length);
// verify child c has not been duplicated
Node[] children = toArray(b1.getNodes());
assertEquals(1, children.length);
}
Aggregations