Search in sources :

Example 51 with NotExecutableException

use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.

the class NodeTest method testRemoveNodeParentLocked.

/**
     * Tests if <code>Node.remove()</code> throws a <code>LockException</code>
     * if the parent node of <code>Node</code> is locked.
     * <p>
     * The test creates a node <code>nodeName1</code> of type
     * <code>testNodeType</code> under <code>testRoot</code>, adds a child node
     * <code>nodeName2</code> and locks it with the superuser session. Then the
     * test tries to remove the <code>nodeName2</code>.
     */
public void testRemoveNodeParentLocked() throws LockException, NotExecutableException, RepositoryException {
    Session session = testRootNode.getSession();
    if (!isSupported(Repository.OPTION_LOCKING_SUPPORTED)) {
        throw new NotExecutableException("Locking is not supported.");
    }
    // create a node that is lockable
    Node node = testRootNode.addNode(nodeName1, testNodeType);
    // or try to make it lockable if it is not
    ensureMixinType(node, mixLockable);
    // create a child node
    Node subNode = node.addNode(nodeName2, testNodeType);
    testRootNode.getSession().save();
    // lock the node
    // remove first slash of path to get rel path to root
    String pathRelToRoot = node.getPath().substring(1);
    // access node through another session to lock it
    Session session2 = getHelper().getSuperuserSession();
    try {
        Node node2 = session2.getRootNode().getNode(pathRelToRoot);
        node2.lock(true, true);
        try {
            subNode.remove();
            session.save();
            fail("Removal of a Node must throw a LockException upon remove() " + "or upon save() if the parent of the node is locked");
        } catch (LockException e) {
        // success
        }
        // unlock to remove node at tearDown()
        node2.unlock();
    } finally {
        session2.logout();
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) LockException(javax.jcr.lock.LockException) Node(javax.jcr.Node) Session(javax.jcr.Session)

Example 52 with NotExecutableException

use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.

the class NodeAddMixinTest method testLocked.

/**
     * Tests if <code>Node.addMixin(String mixinName)</code> throws a
     * <code>LockException</code> if <code>Node</code> is locked
     * <p>
     * The test creates a node <code>nodeName1</code> of type
     * <code>testNodeType</code> under <code>testRoot</code> and locks the node
     * with the superuser session. Then the test tries to add a mixin to
     * <code>nodeName1</code>  with the readWrite <code>Session</code>.
     */
public void testLocked() throws NotExecutableException, RepositoryException {
    Session session = testRootNode.getSession();
    if (!isSupported(Repository.OPTION_LOCKING_SUPPORTED)) {
        throw new NotExecutableException("Locking is not supported.");
    }
    // create a node that is lockable
    Node node = testRootNode.addNode(nodeName1, testNodeType);
    // or try to make it lockable if it is not
    ensureMixinType(node, mixLockable);
    testRootNode.getSession().save();
    String mixinName = NodeMixinUtil.getAddableMixinName(session, node);
    if (mixinName == null) {
        throw new NotExecutableException("No testable mixin node type found");
    }
    // remove first slash of path to get rel path to root
    String pathRelToRoot = node.getPath().substring(1);
    // access node through another session to lock it
    Session session2 = getHelper().getSuperuserSession();
    try {
        Node node2 = session2.getRootNode().getNode(pathRelToRoot);
        node2.lock(true, true);
        try {
            // implementation specific: either throw LockException upon
            // addMixin or upon save.
            node.addMixin(mixinName);
            node.save();
            fail("Node.addMixin(String mixinName) must throw a LockException " + "if the node is locked.");
        } catch (LockException e) {
        // success
        }
        // unlock to remove node at tearDown()
        node2.unlock();
    } finally {
        session2.logout();
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) LockException(javax.jcr.lock.LockException) Node(javax.jcr.Node) Session(javax.jcr.Session)

Example 53 with NotExecutableException

use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.

the class NodeCanAddMixinTest method testLocked.

/**
     * Tests if <code>Node.canAddMixin(String mixinName)</code> throws a
     * <code>LockException</code> if <code>Node</code> is locked
     */
public void testLocked() throws ConstraintViolationException, NotExecutableException, RepositoryException {
    Session session = testRootNode.getSession();
    if (!isSupported(Repository.OPTION_LOCKING_SUPPORTED)) {
        throw new NotExecutableException("Locking is not supported.");
    }
    // create a node that is lockable
    Node node = testRootNode.addNode(nodeName1, testNodeType);
    // or try to make it lockable if it is not
    ensureMixinType(node, mixLockable);
    testRootNode.getSession().save();
    String mixinName = NodeMixinUtil.getAddableMixinName(session, node);
    if (mixinName == null) {
        throw new NotExecutableException("No testable mixin node type found");
    }
    // remove first slash of path to get rel path to root
    String pathRelToRoot = node.getPath().substring(1);
    // access node through another session to lock it
    Session session2 = getHelper().getSuperuserSession();
    try {
        Node node2 = session2.getRootNode().getNode(pathRelToRoot);
        node2.lock(true, true);
        node.refresh(false);
        assertFalse("Node.canAddMixin(String mixinName) must return false " + "if the node is locked.", node.canAddMixin(mixinName));
        node2.unlock();
    } finally {
        session2.logout();
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) Session(javax.jcr.Session)

Example 54 with NotExecutableException

use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.

the class NodeReadMethodsTest method testGetReferences.

public void testGetReferences() throws NotExecutableException, RepositoryException {
    Node node = locateNodeWithReference(testRootNode);
    if (node == null) {
        throw new NotExecutableException("Workspace does not contain a node with a reference property set");
    }
    PropertyIterator properties = node.getProperties();
    while (properties.hasNext()) {
        Property p = properties.nextProperty();
        if (p.getType() == PropertyType.REFERENCE && !p.getDefinition().isMultiple()) {
            Node referencedNode = p.getNode();
            PropertyIterator refs = referencedNode.getReferences();
            boolean referenceFound = false;
            while (refs.hasNext()) {
                Property ref = refs.nextProperty();
                if (ref.isSame(p)) {
                    referenceFound = true;
                }
            }
            assertTrue("Correct reference not found", referenceFound);
        }
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property)

Example 55 with NotExecutableException

use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.

the class NodeReadMethodsTest method testGetNodesNamePattern.

/**
     * Test getNodes(String namePattern) with all possible patterns. Tested
     * node: root - NotExecutableException is thrown when root node has no sub
     * nodes.
     */
public void testGetNodesNamePattern() throws NotExecutableException, RepositoryException {
    // get root node and build an ArrayList of its sub nodes
    Node node = testRootNode;
    if (!node.hasNodes()) {
        throw new NotExecutableException("Workspace does not have sufficient content for this test. " + "Root node must have at least one child node.");
    }
    NodeIterator allNodesIt = node.getNodes();
    List<Node> allNodes = new ArrayList<Node>();
    while (allNodesIt.hasNext()) {
        Node n = allNodesIt.nextNode();
        allNodes.add(n);
    }
    // test if an empty NodeIterator is returned
    // when the pattern is not matching any child node
    String pattern0 = "";
    NodeIterator nodes0 = node.getNodes(pattern0);
    try {
        nodes0.nextNode();
        fail("An empty NodeIterator must be returned if pattern does" + "not match any child node.");
    } catch (NoSuchElementException e) {
    // success
    }
    // all further tests are using root's first sub node
    Node firstNode = allNodes.get(0);
    // test pattern "*"
    String pattern1 = "*";
    String assertString1 = "node.getNodes(\"" + pattern1 + "\"): ";
    NodeIterator nodes1 = node.getNodes(pattern1);
    // test if the number of found nodes is correct
    assertEquals(assertString1 + "number of nodes found: ", allNodes.size(), getSize(nodes1));
    // test pattern "nodeName"
    String pattern2 = firstNode.getName();
    String assertString2 = "node.getNodes(\"" + pattern2 + "\"): ";
    // test if the names of the found nodes are matching the pattern
    NodeIterator nodes2 = node.getNodes(pattern2);
    while (nodes2.hasNext()) {
        Node n = nodes2.nextNode();
        assertEquals(assertString2 + "name comparison failed: ", firstNode.getName(), n.getName());
    }
    // test if the number of found nodes is correct
    int numExpected2 = 0;
    for (int i = 0; i < allNodes.size(); i++) {
        Node n = allNodes.get(i);
        if (n.getName().equals(firstNode.getName())) {
            numExpected2++;
        }
    }
    nodes2 = node.getNodes(pattern2);
    assertEquals(assertString2 + "number of nodes found: ", numExpected2, getSize(nodes2));
    // test pattern "nodeName|nodeName"
    String pattern3 = firstNode.getName() + "|" + firstNode.getName();
    String assertString3 = "node.getNodes(\"" + pattern3 + "\"): ";
    // test if the names of the found nodes are matching the pattern
    NodeIterator nodes3 = node.getNodes(pattern3);
    while (nodes3.hasNext()) {
        Node n = nodes3.nextNode();
        assertEquals(assertString2 + "name comparison failed: ", firstNode.getName(), n.getName());
    }
    // test if the number of found nodes is correct
    int numExpected3 = 0;
    for (int i = 0; i < allNodes.size(); i++) {
        Node n = allNodes.get(i);
        if (n.getName().equals(firstNode.getName())) {
            numExpected3++;
        }
    }
    nodes3 = node.getNodes(pattern3);
    assertEquals(assertString3 + "number of nodes found: ", numExpected3, getSize(nodes3));
    // test pattern "*odeNam*"
    if (firstNode.getName().length() > 2) {
        String name = firstNode.getName();
        String shortenName = name.substring(1, name.length() - 1);
        String pattern4 = "*" + shortenName + "*";
        String assertString4 = "node.getNodes(\"" + pattern4 + "\"): ";
        // test if the names of the found nodes are matching the pattern
        NodeIterator nodes4 = node.getNodes(pattern4);
        while (nodes4.hasNext()) {
            Node n = nodes4.nextNode();
            assertTrue(assertString4 + "name comparison failed: *" + shortenName + "* not found in " + n.getName(), n.getName().indexOf(shortenName) != -1);
        }
        // test if the number of found nodes is correct
        int numExpected4 = 0;
        for (int i = 0; i < allNodes.size(); i++) {
            Node n = allNodes.get(i);
            if (n.getName().indexOf(shortenName) != -1) {
                numExpected4++;
            }
        }
        nodes4 = node.getNodes(pattern4);
        assertEquals(assertString4 + "number of nodes found: ", numExpected4, getSize(nodes4));
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)381 Node (javax.jcr.Node)149 NodeType (javax.jcr.nodetype.NodeType)84 Value (javax.jcr.Value)81 RepositoryException (javax.jcr.RepositoryException)64 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)61 Session (javax.jcr.Session)59 Property (javax.jcr.Property)47 NodeDefinition (javax.jcr.nodetype.NodeDefinition)29 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)28 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)25 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)23 AccessControlPolicyIterator (javax.jcr.security.AccessControlPolicyIterator)22 Test (org.junit.Test)22 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)21 User (org.apache.jackrabbit.api.security.user.User)19 Principal (java.security.Principal)18 NodeIterator (javax.jcr.NodeIterator)18 UserManager (org.apache.jackrabbit.api.security.user.UserManager)17 ItemExistsException (javax.jcr.ItemExistsException)16