use of javax.jcr.Workspace in project jackrabbit by apache.
the class ShareableNodeTest method testPathConstraint.
public void testPathConstraint() throws RepositoryException {
Node n1 = testRootNode.addNode(nodeName1);
Node n2 = testRootNode.addNode(nodeName2);
Node s = n1.addNode(nodeName3);
s.setProperty(propertyName1, "value");
s.addMixin(mixShareable);
Node n4 = s.addNode(nodeName4);
n4.setProperty(propertyName2, "value");
testRootNode.save();
Workspace wsp = superuser.getWorkspace();
wsp.clone(wsp.getName(), s.getPath(), n2.getPath() + "/" + s.getName(), false);
String stmt = testPath + "/" + nodeName1 + "/*[@" + propertyName1 + "='value']";
NodeIterator nodes = executeQuery(stmt).getNodes();
assertEquals("wrong result size", 1, nodes.getSize());
// spec does not say which path must be returned -> use isSame()
assertTrue("wrong node", s.isSame(nodes.nextNode()));
stmt = testPath + "/" + nodeName2 + "/*[@" + propertyName1 + "='value']";
nodes = executeQuery(stmt).getNodes();
assertEquals("wrong result size", 1, nodes.getSize());
// spec does not say which path must be returned -> use isSame()
assertTrue("wrong node", s.isSame(nodes.nextNode()));
stmt = testPath + "//*[@" + propertyName1 + "='value']";
nodes = executeQuery(stmt).getNodes();
assertEquals("wrong result size", 1, nodes.getSize());
// spec does not say which path must be returned -> use isSame()
assertTrue("wrong node", s.isSame(nodes.nextNode()));
stmt = testPath + "//*[@" + propertyName2 + "='value']";
nodes = executeQuery(stmt).getNodes();
assertEquals("wrong result size", 1, nodes.getSize());
// spec does not say which path must be returned -> use isSame()
assertTrue("wrong node", n4.isSame(nodes.nextNode()));
// remove a node from the shared set
s.removeShare();
testRootNode.save();
s = n2.getNode(nodeName3);
stmt = testPath + "/" + nodeName1 + "/*[@" + propertyName1 + "='value']";
nodes = executeQuery(stmt).getNodes();
assertEquals("wrong result size", 0, nodes.getSize());
stmt = testPath + "/" + nodeName2 + "/*[@" + propertyName1 + "='value']";
nodes = executeQuery(stmt).getNodes();
assertEquals("wrong result size", 1, nodes.getSize());
// spec does not say which path must be returned -> use isSame()
assertTrue("wrong node", s.isSame(nodes.nextNode()));
stmt = testPath + "//*[@" + propertyName1 + "='value']";
nodes = executeQuery(stmt).getNodes();
assertEquals("wrong result size", 1, nodes.getSize());
// spec does not say which path must be returned -> use isSame()
assertTrue("wrong node", s.isSame(nodes.nextNode()));
// remove remaining node from the shared set
s.removeShare();
testRootNode.save();
stmt = testPath + "/" + nodeName1 + "/*[@" + propertyName1 + "='value']";
nodes = executeQuery(stmt).getNodes();
assertEquals("wrong result size", 0, nodes.getSize());
stmt = testPath + "/" + nodeName2 + "/*[@" + propertyName1 + "='value']";
nodes = executeQuery(stmt).getNodes();
assertEquals("wrong result size", 0, nodes.getSize());
stmt = testPath + "//*[@" + propertyName1 + "='value']";
nodes = executeQuery(stmt).getNodes();
assertEquals("wrong result size", 0, nodes.getSize());
}
use of javax.jcr.Workspace in project jackrabbit by apache.
the class CopyTest method testCopy.
public void testCopy() throws RepositoryException {
Workspace wsp = superuser.getWorkspace();
VersionManager vMgr = wsp.getVersionManager();
String srcPath = versionableNode.getPath();
String dstPath = getProperty("destination");
wsp.copy(srcPath, dstPath);
// check versionable
Node v = superuser.getNode(dstPath);
assertTrue("Copied Node.isNodeType(mix:simpleVersionable) must return true.", v.isNodeType(mixSimpleVersionable));
assertFalse("Copied Node.isNodeType(mix:versionable) must return false.", v.isNodeType(mixVersionable));
// check different version history
VersionHistory vh1 = vMgr.getVersionHistory(srcPath);
VersionHistory vh2 = vMgr.getVersionHistory(dstPath);
assertFalse("Copied node needs a new version history.", vh1.isSame(vh2));
// check if 1 version
assertEquals("Copied node must have 1 version.", 1, getNumberOfVersions(vh2));
}
use of javax.jcr.Workspace in project jackrabbit by apache.
the class ShareableNodesTest method testRemoveShare.
public void testRemoveShare() throws RepositoryException {
Node n1 = testRootNode.addNode(nodeName1);
Node n2 = testRootNode.addNode(nodeName2);
Node s = n1.addNode(nodeName3);
s.addMixin(mixShareable);
testRootNode.save();
Workspace wsp = superuser.getWorkspace();
wsp.clone(wsp.getName(), s.getPath(), n2.getPath() + "/" + s.getName(), false);
EventResult result = new EventResult(log);
addEventListener(result);
removeFromSharedSet(n2.getNode(nodeName3));
testRootNode.save();
checkNodeRemoved(result.getEvents(DEFAULT_WAIT_TIMEOUT), new String[] { nodeName2 + "/" + nodeName3 }, new String[0]);
}
use of javax.jcr.Workspace in project jackrabbit by apache.
the class ShareableNodesTest method testAddShare.
public void testAddShare() throws RepositoryException {
Node n1 = testRootNode.addNode(nodeName1);
Node n2 = testRootNode.addNode(nodeName2);
Node s = n1.addNode(nodeName3);
s.addMixin(mixShareable);
testRootNode.save();
EventResult result = new EventResult(log);
addEventListener(result);
Workspace wsp = superuser.getWorkspace();
wsp.clone(wsp.getName(), s.getPath(), n2.getPath() + "/" + s.getName(), false);
checkNodeAdded(result.getEvents(DEFAULT_WAIT_TIMEOUT), new String[] { nodeName2 + "/" + nodeName3 }, new String[0]);
}
use of javax.jcr.Workspace in project jackrabbit by apache.
the class ShareableNodeTest method testImportExportNtShare.
/**
* Verify export and import of a tree containing multiple nodes in the
* same shared set (6.13.14). The first serialized node in that shared
* set is serialized in the normal fashion (with all of its properties
* and children), but any subsequent shared node in that shared set is
* serialized as a special node of type <code>nt:share</code>, which
* contains only the <code>jcr:uuid</code> property of the shared node
* and the <code>jcr:primaryType</code> property indicating the type
* <code>nt:share</code>.
*/
public void testImportExportNtShare() throws Exception {
// setup parent nodes and first child
Node p = testRootNode.addNode("p");
Node a1 = p.addNode("a1");
Node a2 = p.addNode("a2");
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);
// create temp file
File tmpFile = File.createTempFile("test", null);
tmpFile.deleteOnExit();
// export system view of /p
OutputStream out = new FileOutputStream(tmpFile);
try {
session.exportSystemView(p.getPath(), out, false, false);
} finally {
out.close();
}
// delete p and save
p.remove();
testRootNode.getSession().save();
// and import again underneath test root
InputStream in = new FileInputStream(tmpFile);
try {
workspace.importXML(testRootNode.getPath(), in, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW);
} finally {
try {
in.close();
} catch (IOException ignore) {
}
}
// verify shared set consists of two nodes
Node[] shared = getSharedSet(testRootNode.getNode("p/a1/b1"));
assertEquals(2, shared.length);
}
Aggregations