use of javax.jcr.Session in project jackrabbit by apache.
the class UtilsGetPathTest method testGetOrCreateByPathNoRoot.
@Test
public void testGetOrCreateByPathNoRoot() throws RepositoryException {
String base = testRoot + "/foo";
Node inter = JcrUtils.getOrCreateByPath(base, "nt:unstructured", superuser);
assertEquals(base, inter.getPath());
superuser.save();
// test what happens if getRootNode() throws
Session mockedSession = Mockito.spy(superuser);
Mockito.when(mockedSession.getRootNode()).thenThrow(new AccessDeniedException("access denied"));
Mockito.when(mockedSession.getNode("/")).thenThrow(new AccessDeniedException("access denied"));
Mockito.when(mockedSession.getItem("/")).thenThrow(new AccessDeniedException("access denied"));
Mockito.when(mockedSession.nodeExists("/")).thenReturn(false);
Node result = JcrUtils.getOrCreateByPath(base + "/bar", false, null, null, mockedSession, false);
mockedSession.save();
assertEquals(base + "/bar", result.getPath());
// already exists -> nop
Node result2 = JcrUtils.getOrCreateByPath(base + "/bar", false, null, null, mockedSession, false);
mockedSession.save();
assertEquals(base + "/bar", result2.getPath());
// create unique
Node result3 = JcrUtils.getOrCreateByPath(base + "/bar", true, null, null, mockedSession, false);
mockedSession.save();
assertEquals(base + "/bar0", result3.getPath());
// already exists with createUnique == false should pass even when parent isn't readable
Mockito.when(mockedSession.getNode(base)).thenThrow(new AccessDeniedException("access denied"));
Mockito.when(mockedSession.getItem(base)).thenThrow(new AccessDeniedException("access denied"));
Mockito.when(mockedSession.nodeExists(base)).thenReturn(false);
Node result4 = JcrUtils.getOrCreateByPath(base + "/bar", false, null, null, mockedSession, false);
mockedSession.save();
assertEquals(base + "/bar", result4.getPath());
}
use of javax.jcr.Session in project jackrabbit by apache.
the class VersioningTest method tearDown.
protected void tearDown() throws Exception {
super.tearDown();
Session s1 = n1.getSession();
n1.remove();
s1.save();
s1.logout();
Session s2 = n2.getSession();
n2.remove();
s2.save();
s2.logout();
}
use of javax.jcr.Session in project jackrabbit by apache.
the class SessionImplTest method testSessionAttributes.
/**
* JCR-1932: Session.getAttributes( ) call always returns an empty array
*
* @see <a href="https://issues.apache.org/jira/browse/JCR-1932">JCR-1932</a>
*/
public void testSessionAttributes() throws RepositoryException {
SimpleCredentials credentials = new SimpleCredentials("admin", "admin".toCharArray());
credentials.setAttribute("test", "attribute");
Session session = getHelper().getRepository().login(credentials);
try {
String[] names = session.getAttributeNames();
assertEquals(1, names.length);
assertEquals("test", names[0]);
assertEquals("attribute", session.getAttribute("test"));
} finally {
session.logout();
}
}
use of javax.jcr.Session in project jackrabbit by apache.
the class SimpleBench method test.
void test(int run) throws Exception {
this.run = run;
new File("target/jcr.log").delete();
FileUtils.deleteQuietly(new File("repository"));
start();
repository = new TransientRepository();
Session session = repository.login(new SimpleCredentials("", "".toCharArray()));
if (session.getRootNode().hasNode("test")) {
session.getRootNode().getNode("test").remove();
session.save();
}
session.getRootNode().addNode("test");
session.save();
end("init");
Node node = session.getRootNode().getNode("test");
Node n = null;
int len = run == 0 ? 100 : 1000;
start();
for (int i = 0; i < len; i++) {
if (i % 100 == 0) {
n = node.addNode("sub" + i);
}
Node x = n.addNode("x" + (i % 100));
x.setProperty("name", "John");
x.setProperty("firstName", "Doe");
session.save();
}
end("addNodes");
session.logout();
}
use of javax.jcr.Session in project jackrabbit by apache.
the class ItemStateHierarchyManagerDeadlockTest method createNodesUnderInvRootNode.
public void createNodesUnderInvRootNode() {
System.out.println("Start createNodesUnderInvRootNode ");
Session session = null;
try {
session = login();
Node inventoryRoot = getInvRootNode(session);
for (int num = 0; num < 3; num++) {
Node current = inventoryRoot.addNode("Test" + num + "_" + System.currentTimeMillis());
current.setProperty("profondeur", 123);
current.setProperty("tree", "1");
current.setProperty("clientid", 1);
current.setProperty("propId", System.currentTimeMillis());
current.setProperty("name", "Node " + System.currentTimeMillis());
current.setProperty("address", "1.22.3.3");
}
session.save();
System.out.println("End createNodesUnderInvRootNode ");
} catch (Exception e) {
System.err.println("Exception in createNodesUnderInvRootNode:" + e.getMessage());
} finally {
if (session != null)
session.logout();
}
}
Aggregations