use of javax.jcr.Workspace in project camel by apache.
the class JcrProducerDifferentWorkspaceTest method testJcrProducer.
@Test
public void testJcrProducer() throws Exception {
Exchange exchange = createExchangeWithBody("<hello>world!</hello>");
Exchange out = template.send("direct:a", exchange);
assertNotNull(out);
String uuid = out.getOut().getBody(String.class);
Session session = openSession(CUSTOM_WORKSPACE_NAME);
try {
Node node = session.getNodeByIdentifier(uuid);
Workspace workspace = session.getWorkspace();
assertEquals(CUSTOM_WORKSPACE_NAME, workspace.getName());
assertNotNull(node);
assertEquals("/home/test/node", node.getPath());
assertEquals("<hello>world!</hello>", node.getProperty("my.contents.property").getString());
} finally {
if (session != null && session.isLive()) {
session.logout();
}
}
}
use of javax.jcr.Workspace in project jackrabbit by apache.
the class WorkspaceTest method testCreateWorkspace.
public void testCreateWorkspace() throws Exception {
Session s = null;
try {
Workspace wsp = superuser.getWorkspace();
String name = getNewWorkspaceName(wsp);
wsp.createWorkspace(name);
List<String> wsps = Arrays.asList(wsp.getAccessibleWorkspaceNames());
assertTrue(wsps.contains(name));
s = getHelper().getSuperuserSession(name);
Workspace newW = s.getWorkspace();
assertEquals(name, newW.getName());
} catch (UnsupportedRepositoryOperationException e) {
throw new NotExecutableException();
} catch (UnsupportedOperationException e) {
throw new NotExecutableException();
} finally {
if (s != null) {
s.logout();
}
}
}
use of javax.jcr.Workspace in project jackrabbit by apache.
the class WorkspaceTest method testCreateWorkspaceFromSource.
public void testCreateWorkspaceFromSource() throws Exception {
Session s = null;
try {
Workspace wsp = superuser.getWorkspace();
String name = getNewWorkspaceName(wsp);
wsp.createWorkspace(name, wsp.getName());
List<String> wsps = Arrays.asList(wsp.getAccessibleWorkspaceNames());
assertTrue(wsps.contains(name));
s = getHelper().getSuperuserSession(name);
Workspace newW = s.getWorkspace();
assertEquals(name, newW.getName());
} catch (UnsupportedRepositoryOperationException e) {
throw new NotExecutableException();
} catch (UnsupportedOperationException e) {
throw new NotExecutableException();
} finally {
if (s != null) {
s.logout();
}
}
}
use of javax.jcr.Workspace in project jackrabbit by apache.
the class Clone method execute.
/**
* {@inheritDoc}
*/
public boolean execute(Context ctx) throws Exception {
String srcWorkspace = (String) ctx.get(this.srcWorkspaceKey);
String srcAbsPath = (String) ctx.get(this.srcAbsPathKey);
String destAbsPath = (String) ctx.get(this.destAbsPathKey);
Boolean removeExisting = Boolean.valueOf((String) ctx.get(this.removeExistingKey));
Workspace w = CommandHelper.getSession(ctx).getWorkspace();
if (log.isDebugEnabled()) {
log.debug("cloning node. from [" + srcWorkspace + ":" + srcAbsPath + "] to [" + w.getName() + ":" + destAbsPath + "]");
}
w.clone(srcWorkspace, srcAbsPath, destAbsPath, removeExisting.booleanValue());
return false;
}
use of javax.jcr.Workspace in project jackrabbit by apache.
the class RemoveOrphanVersionHistoryTest method testWorkspaceRemoveOrphanVersionHistory.
/**
* Test orphan version history cleaning in multiple workspace.
* @throws RepositoryException if an error occurs.
*/
public void testWorkspaceRemoveOrphanVersionHistory() throws RepositoryException {
Node n = testRootNode.addNode(nodeName1);
n.addMixin(mixVersionable);
testRootNode.save();
Session session = n.getSession();
VersionHistory vh = n.getVersionHistory();
String vhUuid = vh.getUUID();
assertExists(session, vhUuid);
// First version
Version v10 = n.checkin();
n.checkout();
Workspace defaultWorkspace = n.getSession().getWorkspace();
Session otherWsSession = n.getSession().getRepository().login(new SimpleCredentials("superuser", "".toCharArray()), workspaceName);
// Clone the node in another workspace
otherWsSession.getWorkspace().clone(defaultWorkspace.getName(), n.getPath(), n.getPath(), false);
Node otherWsRootNode = otherWsSession.getRootNode();
Node clonedNode = otherWsRootNode.getNode(n.getPath().substring(1));
// Ensure that version histories are the same
assertEquals(vhUuid, clonedNode.getVersionHistory().getUUID());
Version v11 = clonedNode.checkin();
clonedNode.checkout();
// Remove node
n.remove();
testRootNode.save();
assertExists(session, vhUuid);
assertExists(otherWsSession, vhUuid);
// Remove the first version
vh.removeVersion(v10.getName());
assertExists(session, vhUuid);
assertExists(otherWsSession, vhUuid);
// Remove cloned node
clonedNode.remove();
otherWsRootNode.save();
assertExists(session, vhUuid);
assertExists(otherWsSession, vhUuid);
// Remove the last version
vh.removeVersion(v11.getName());
try {
session.getNodeByUUID(vhUuid);
fail("Orphan version history must have been removed from the default workspace");
} catch (ItemNotFoundException e) {
// Expected
}
try {
otherWsSession.getNodeByUUID(vhUuid);
fail("Orphan version history must have been removed from the other workspace");
} catch (ItemNotFoundException e) {
// Expected
}
}
Aggregations