Search in sources :

Example 1 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 2 with JackrabbitNode

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

the class JackrabbitNodeTest method testSetMixins.

public void testSetMixins() throws RepositoryException {
    // create node with mixin test:AA
    Node n = testRootNode.addNode("foo", "nt:folder");
    n.addMixin("test:AA");
    n.setProperty("test:propAA", "AA");
    n.setProperty("test:propA", "A");
    superuser.save();
    // 'downgrade' from test:AA to test:A
    ((JackrabbitNode) n).setMixins(new String[] { "test:A" });
    superuser.save();
    assertTrue(n.hasProperty("test:propA"));
    assertFalse(n.hasProperty("test:propAA"));
    // 'upgrade' from test:A to test:AA
    ((JackrabbitNode) n).setMixins(new String[] { "test:AA" });
    n.setProperty("test:propAA", "AA");
    superuser.save();
    assertTrue(n.hasProperty("test:propA"));
    assertTrue(n.hasProperty("test:propAA"));
    // replace test:AA with mix:title
    ((JackrabbitNode) n).setMixins(new String[] { "mix:title" });
    n.setProperty("jcr:title", "...");
    n.setProperty("jcr:description", "blah blah");
    superuser.save();
    assertTrue(n.hasProperty("jcr:title"));
    assertTrue(n.hasProperty("jcr:description"));
    assertFalse(n.hasProperty("test:propA"));
    assertFalse(n.hasProperty("test:propAA"));
    // clean up
    n.remove();
    superuser.save();
}
Also used : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node)

Example 3 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 4 with JackrabbitNode

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

the class JackrabbitNodeTest method testSetEmptyMixins.

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

Example 5 with JackrabbitNode

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

the class JackrabbitNodeTest method _testRenameEventHandling.

// Ignore("OAK-3658")
public void _testRenameEventHandling() throws RepositoryException, InterruptedException {
    Session s = getHelper().getSuperuserSession();
    ObservationManager mgr = s.getWorkspace().getObservationManager();
    final List<Event> events = newArrayList();
    final CountDownLatch latch1 = new CountDownLatch(1);
    final CountDownLatch latch2 = new CountDownLatch(1);
    try {
        mgr.addEventListener(new EventListener() {

            CountDownLatch latch = latch1;

            @Override
            public void onEvent(EventIterator eventIterator) {
                synchronized (events) {
                    while (eventIterator.hasNext()) {
                        events.add(eventIterator.nextEvent());
                    }
                    latch.countDown();
                    latch = latch2;
                }
            }
        }, Event.PERSIST | Event.NODE_ADDED | Event.NODE_MOVED | Event.NODE_REMOVED, testRootNode.getPath(), true, null, null, false);
        NodeIterator it = testRootNode.getNodes();
        Node n = it.nextNode();
        String name = n.getName();
        JackrabbitNode node = (JackrabbitNode) n;
        node.rename(name + 'X');
        superuser.save();
        StringBuilder diags = new StringBuilder();
        if (!latch1.await(60, SECONDS)) {
            diags.append("latch1 timed out ");
        }
        boolean foundMove = false;
        synchronized (events) {
            for (Event event : events) {
                if (diags.length() != 0) {
                    diags.append(", ");
                }
                diags.append("type " + event.getType() + " " + event.getDate() + "ms " + event.getPath());
                if (Event.NODE_MOVED == event.getType()) {
                    foundMove = true;
                    break;
                }
            }
            if (events.isEmpty()) {
                diags.append("none");
            }
        }
        if (!foundMove) {
            // force another event, wait some more
            testRootNode.addNode(name + "XYZ");
            superuser.save();
            StringBuffer addDiags = new StringBuffer();
            if (!latch2.await(60, SECONDS)) {
                addDiags.append("latch2 timed out ");
            }
            synchronized (events) {
                for (Event event : events) {
                    if (addDiags.length() != 0) {
                        addDiags.append(", ");
                    }
                    addDiags.append("type " + event.getType() + " " + event.getDate() + "ms " + event.getPath());
                }
            }
            if (addDiags.length() > 0) {
                diags.append("; next event after additional addNode/save operation: " + addDiags);
            }
        }
        if (!foundMove) {
            fail("Expected NODE_MOVED event upon renaming a node (received: " + diags + ")");
        }
    } finally {
        s.logout();
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) ObservationManager(javax.jcr.observation.ObservationManager) CountDownLatch(java.util.concurrent.CountDownLatch) Event(javax.jcr.observation.Event) EventListener(javax.jcr.observation.EventListener) EventIterator(javax.jcr.observation.EventIterator) Session(javax.jcr.Session)

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