Search in sources :

Example 11 with JackrabbitNode

use of org.apache.jackrabbit.api.JackrabbitNode in project jackrabbit-oak by apache.

the class SameNameSiblingTest method renameSiblings.

@Test
public void renameSiblings() throws RepositoryException {
    for (String name : SIBLINGS) {
        JackrabbitNode sib = (JackrabbitNode) sns.getNode(name);
        sib.rename(rename(name));
    }
    session.save();
    for (String name : SIBLINGS) {
        assertFalse(sns.hasNode(name));
        assertTrue(sns.hasNode(rename(name)));
    }
}
Also used : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Test(org.junit.Test)

Example 12 with JackrabbitNode

use of org.apache.jackrabbit.api.JackrabbitNode in project jackrabbit-oak by apache.

the class ObservationTest method testRename.

@Test
public void testRename() throws RepositoryException, ExecutionException, InterruptedException {
    Node testNode = getNode(TEST_PATH);
    Session session = testNode.getSession();
    Node nodeA = testNode.addNode("a");
    String parentPath = testNode.getPath();
    session.save();
    assumeTrue(nodeA instanceof JackrabbitNode);
    ExpectationListener listener = new ExpectationListener();
    observationManager.addEventListener(listener, NODE_MOVED, "/", true, null, null, false);
    ((JackrabbitNode) nodeA).rename("b");
    listener.expectMove(parentPath + "/a", parentPath + "/b");
    session.save();
    List<Expectation> missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
    assertTrue("Missing events: " + missing, missing.isEmpty());
    List<Event> unexpected = listener.getUnexpected();
    assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
}
Also used : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) Session(javax.jcr.Session) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest) Test(org.junit.Test)

Example 13 with JackrabbitNode

use of org.apache.jackrabbit.api.JackrabbitNode in project jackrabbit-oak by apache.

the class RenameTest method testRename2.

@Test
public void testRename2() throws Exception {
    // give 'add_child_nodes' and 'nt-management' privilege
    // -> not sufficient privileges for a renaming of the child
    allow(path, privilegesFromNames(new String[] { Privilege.JCR_ADD_CHILD_NODES, Privilege.JCR_NODE_TYPE_MANAGEMENT }));
    Node child = testSession.getNode(childNPath);
    try {
        ((JackrabbitNode) child).rename("rename");
        testSession.save();
        fail("test session must not be allowed to rename nodes.");
    } catch (AccessDeniedException e) {
    // success.
    }
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Test(org.junit.Test)

Example 14 with JackrabbitNode

use of org.apache.jackrabbit.api.JackrabbitNode in project jackrabbit-oak by apache.

the class RenameTest method testRename.

@Test
public void testRename() throws Exception {
    Node child = testSession.getNode(childNPath);
    try {
        ((JackrabbitNode) child).rename("rename");
        testSession.save();
        fail("test session must not be allowed to rename nodes.");
    } catch (AccessDeniedException e) {
    // success.
    }
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Test(org.junit.Test)

Example 15 with JackrabbitNode

use of org.apache.jackrabbit.api.JackrabbitNode in project jackrabbit-oak by apache.

the class RenameTest method testRename3.

/**
     * @since OAK 1.0 : Renaming a node requires the same permission as moving it
     * around. This behavior differs from Jackrabbit 2.x where renaming just
     * required the ability to change the child collection of the parent.
     */
@Test
public void testRename3() throws Exception {
    // grant 'add_child_nodes', 'nt-management' and remove_child_nodes' at 'path
    // -> rename of child must now succeed
    allow(path, privilegesFromNames(new String[] { Privilege.JCR_ADD_CHILD_NODES, Privilege.JCR_NODE_TYPE_MANAGEMENT, Privilege.JCR_REMOVE_CHILD_NODES, Privilege.JCR_REMOVE_NODE }));
    Node child = testSession.getNode(childNPath);
    ((JackrabbitNode) child).rename("rename");
    testSession.save();
}
Also used : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Test(org.junit.Test)

Aggregations

JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)15 Node (javax.jcr.Node)14 Test (org.junit.Test)6 Session (javax.jcr.Session)4 AccessDeniedException (javax.jcr.AccessDeniedException)3 NodeIterator (javax.jcr.NodeIterator)2 Event (javax.jcr.observation.Event)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 EventIterator (javax.jcr.observation.EventIterator)1 EventListener (javax.jcr.observation.EventListener)1 ObservationManager (javax.jcr.observation.ObservationManager)1 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)1