use of javax.jcr.Workspace in project jackrabbit by apache.
the class ShareableNodeTest method testImportDocumentViewCollision.
/**
* Verify document view import via workspace (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 testImportDocumentViewCollision() 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.exportDocumentView(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);
}
use of javax.jcr.Workspace in project jackrabbit by apache.
the class ShareableNodeTest method testGetNode.
/**
* Verify that the shareable node returned by Node.getNode() has the right
* name.
*/
public void testGetNode() 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.getNode("b1") should return b1
b1 = a1.getNode("b1");
assertEquals("b1", b1.getName());
// a2.getNode("b2") should return b2
Node b2 = a2.getNode("b2");
assertEquals("b2", b2.getName());
}
use of javax.jcr.Workspace in project jackrabbit by apache.
the class ShareableNodeTest method testGetNodes.
/**
* Verify that the shareable nodes returned by Node.getNodes() have
* the right name.
*/
public void testGetNodes() 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());
}
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:cersionable) must return true.", 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));
// check if jcr:copiedFrom is set correctly
assertTrue("Version history of desination must have a jcr:copiedFrom property", vh2.hasProperty(jcrCopiedFrom));
Node ref = vh2.getProperty(jcrCopiedFrom).getNode();
Version base = vMgr.getBaseVersion(srcPath);
assertTrue("jcr:copiedFrom must point to the base version of the original.", ref.isSame(base));
}
use of javax.jcr.Workspace in project jackrabbit by apache.
the class CreateWorkspace method execute.
/**
* {@inheritDoc}
*/
public boolean execute(Context ctx) throws Exception {
String name = (String) ctx.get(this.nameKey);
if (log.isDebugEnabled()) {
log.debug("creating workspace for name " + name);
}
Workspace w = CommandHelper.getSession(ctx).getWorkspace();
if (!(w instanceof WorkspaceImpl)) {
throw new IllegalStateException(bundle.getString("phrase.jackrabbit.command"));
}
WorkspaceImpl jrw = (WorkspaceImpl) w;
jrw.createWorkspace(name);
return false;
}
Aggregations