use of javax.jcr.Workspace in project jackrabbit by apache.
the class ShareableNodeTest method testSameUUID.
/**
* Verify that shareable nodes in the same shared set have the same
* jcr:uuid (6.13.10).
*/
public void testSameUUID() 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 nodes in a shared set have the same jcr:uuid
assertTrue(b1.getUUID().equals(b2.getUUID()));
}
use of javax.jcr.Workspace in project jackrabbit by apache.
the class ShareableNodeTest method testRemoveDescendantAndRemoveShareAndSave.
/**
* Verify that invoking save() on a share-ancestor will save changes in
* all share-descendants.
*/
public void testRemoveDescendantAndRemoveShareAndSave() 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
Session session = b1.getSession();
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();
// remove child node c
c.remove();
// remove share b2 from a2
a2.getNode("b2").removeShare();
// save a2 (having path /testroot/a2): this should save c as well
// since one of the paths to c was /testroot/a2/b2/c
a2.save();
assertFalse("Saving share-ancestor should save share-descendants", session.hasPendingChanges());
}
use of javax.jcr.Workspace in project jackrabbit by apache.
the class ShareableNodeTest method testCopy.
/**
* Copy a subtree that contains shareable nodes. Verify that the nodes
* newly created are not in the shared set that existed before the copy,
* but if two nodes in the source of a copy are in the same shared set, then
* the two corresponding nodes in the destination of the copy must also be
* in the same shared set (6.13.12).
*/
public void testCopy() throws Exception {
// setup parent node and first child
Node s = testRootNode.addNode("s");
Node a1 = s.addNode("a1");
Node a2 = s.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);
// copy source tree to destination
workspace.copy(s.getPath(), testRootNode.getPath() + "/d");
// verify source contains shared set with 2 entries
Node[] shared1 = getSharedSet(b1);
assertEquals(2, shared1.length);
// verify destination contains shared set with 2 entries
Node[] shared2 = getSharedSet(testRootNode.getNode("d/a1/b1"));
assertEquals(2, shared2.length);
// verify elements in source shared set and destination shared set
// don't have the same UUID
String srcUUID = shared1[0].getUUID();
String destUUID = shared2[0].getUUID();
assertFalse("Source and destination of a copy must not have the same UUID", srcUUID.equals(destUUID));
}
use of javax.jcr.Workspace in project jackrabbit by apache.
the class ShareableNodeTest method testRestore.
/**
* Create a shareable node by restoring it (6.13.3).
*/
public void testRestore() 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);
// 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 shared set contains one element only
Node[] shared = getSharedSet(b1);
assertEquals(1, shared.length);
// restore version
a2.restore(v, false);
// verify shared set contains again two elements
shared = getSharedSet(b1);
assertEquals(2, shared.length);
}
use of javax.jcr.Workspace in project jackrabbit by apache.
the class ShareableNodeTest method testSessionImportDocumentViewCollision.
/**
* Verify document view import via session (6.13.14). Export a document
* 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 testSessionImportDocumentViewCollision() 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 {
session.importXML(a3.getPath(), in, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW);
session.save();
} 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