Search in sources :

Example 6 with JackrabbitNode

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

the class JackrabbitNodeTest method _testRename.

//Ignore("OAK-3658")
public void _testRename() throws RepositoryException {
    Node renamedNode = null;
    NodeIterator it = testRootNode.getNodes();
    int pos = 0;
    while (it.hasNext()) {
        Node n = it.nextNode();
        String name = n.getName();
        assertEquals(new String(new char[] { SEQ_BEFORE.charAt(pos) }), name);
        if (pos == RELPOS) {
            JackrabbitNode node = (JackrabbitNode) n;
            node.rename(name.toUpperCase());
            renamedNode = n;
        }
        pos++;
    }
    it = testRootNode.getNodes();
    pos = 0;
    while (it.hasNext()) {
        Node n = it.nextNode();
        String name = n.getName();
        assertEquals(new String(new char[] { SEQ_AFTER.charAt(pos) }), name);
        if (pos == RELPOS) {
            assertTrue(n.isSame(renamedNode));
        }
        pos++;
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node)

Example 7 with JackrabbitNode

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

the class RepositoryTest method renameNonOrderable.

@Test
public void renameNonOrderable() throws RepositoryException {
    Session session = getAdminSession();
    Node root = session.getRootNode();
    Node parent = root.addNode("parent", NodeTypeConstants.NT_OAK_UNSTRUCTURED);
    parent.addNode("fo");
    Node foo = parent.addNode("foo");
    session.save();
    ((JackrabbitNode) foo).rename("renamed");
    assertEquals("renamed", foo.getName());
    assertFalse(session.nodeExists("/parent/foo"));
    assertTrue(session.nodeExists("/parent/renamed"));
}
Also used : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) Session(javax.jcr.Session) Test(org.junit.Test)

Example 8 with JackrabbitNode

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

the class AbstractWriteTest method testRename.

public void testRename() throws RepositoryException, NotExecutableException {
    Session testSession = getTestSession();
    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.
    }
    // give 'add_child_nodes' and 'nt-management' privilege
    // -> not sufficient privileges for a renaming of the child
    givePrivileges(path, privilegesFromNames(new String[] { Privilege.JCR_ADD_CHILD_NODES, Privilege.JCR_NODE_TYPE_MANAGEMENT }), getRestrictions(superuser, path));
    try {
        ((JackrabbitNode) child).rename("rename");
        testSession.save();
        fail("test session must not be allowed to rename nodes.");
    } catch (AccessDeniedException e) {
    // success.
    }
    // add 'remove_child_nodes' at 'path
    // -> rename of child must now succeed
    givePrivileges(path, privilegesFromName(Privilege.JCR_REMOVE_CHILD_NODES), getRestrictions(superuser, path));
    ((JackrabbitNode) child).rename("rename");
    testSession.save();
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) Session(javax.jcr.Session)

Example 9 with JackrabbitNode

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

the class JackrabbitNodeTest method testSetNewMixins.

/**
     * @since oak 1.0
     */
public void testSetNewMixins() throws RepositoryException {
    // create node with mixin test:AA
    Node n = testRootNode.addNode("foo", "nt:folder");
    ((JackrabbitNode) n).setMixins(new String[] { "test:AA", "test:A" });
    superuser.save();
    assertTrue(n.isNodeType("test:AA"));
    assertTrue(n.isNodeType("test:A"));
    assertTrue(n.hasProperty(JcrConstants.JCR_MIXINTYPES));
}
Also used : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node)

Example 10 with JackrabbitNode

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

the class JackrabbitNodeTest method testUpdateMixins.

/**
     * @since oak 1.0
     */
public void testUpdateMixins() throws RepositoryException {
    // create node with mixin test:AA
    Node n = testRootNode.addNode("foo", "nt:folder");
    ((JackrabbitNode) n).setMixins(new String[] { "test:A", "test:AA" });
    superuser.save();
    assertTrue(n.isNodeType("test:AA"));
    assertTrue(n.isNodeType("test:A"));
    ((JackrabbitNode) n).setMixins(new String[] { "test:A", "test:AA", JcrConstants.MIX_REFERENCEABLE });
    superuser.save();
    assertTrue(n.isNodeType("test:AA"));
    assertTrue(n.isNodeType("test:A"));
    assertTrue(n.isNodeType(JcrConstants.MIX_REFERENCEABLE));
    assertTrue(n.hasProperty(JcrConstants.JCR_UUID));
    ((JackrabbitNode) n).setMixins(new String[] { JcrConstants.MIX_REFERENCEABLE });
    superuser.save();
    assertFalse(n.isNodeType("test:AA"));
    assertFalse(n.isNodeType("test:A"));
    assertTrue(n.isNodeType(JcrConstants.MIX_REFERENCEABLE));
    assertTrue(n.hasProperty(JcrConstants.JCR_UUID));
}
Also used : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node)

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