Search in sources :

Example 91 with NotExecutableException

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

the class UpdateTest method testPendingChangesOnOtherNode.

public void testPendingChangesOnOtherNode() throws RepositoryException, NotExecutableException {
    try {
        Node root = testRootNode.getSession().getRootNode();
        if (root.isSame(testRootNode)) {
            throw new NotExecutableException();
        }
        if (root.canAddMixin(mixLockable)) {
            root.addMixin(mixLockable);
        } else {
            root.setProperty(propertyName1, "anyValue");
        }
    } catch (RepositoryException e) {
        throw new NotExecutableException();
    }
    String srcWorkspace = getAnotherWorkspace();
    try {
        testRootNode.update(srcWorkspace);
        fail("Update while changes are pending must fail with InvalidItemStateException");
    } catch (InvalidItemStateException e) {
    // ok
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException)

Example 92 with NotExecutableException

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

the class UpdateTest method testUpdateAddsMissingSubtree.

public void testUpdateAddsMissingSubtree() throws RepositoryException, NotExecutableException {
    String srcWorkspace = getAnotherWorkspace();
    // get the root node in the second workspace
    Session session2 = getHelper().getSuperuserSession(srcWorkspace);
    try {
        // make sure the source-session has the corresponding node.
        Node testRootW2 = (Node) session2.getItem(testRootNode.getCorrespondingNodePath(srcWorkspace));
        // create test node in second workspace
        Node aNode2 = testRootW2.addNode(nodeName1, testNodeType);
        aNode2.addNode(nodeName2, testNodeType);
        aNode2.setProperty(propertyName2, "test");
        Property p2 = testRootW2.setProperty(propertyName1, "test");
        testRootW2.save();
        // call the update method on test node in default workspace
        testRootNode.update(srcWorkspace);
        // ok check if the child has been added
        boolean allPresent = testRootNode.hasNode(nodeName1) && testRootNode.hasNode(nodeName1 + "/" + nodeName2) && testRootNode.hasProperty(nodeName1 + "/" + propertyName2) && testRootNode.hasProperty(propertyName1);
        assertTrue("Node updated with Node.update() should have received childrens", allPresent);
    } catch (PathNotFoundException e) {
        throw new NotExecutableException();
    } catch (ItemNotFoundException e) {
        throw new NotExecutableException();
    } finally {
        session2.logout();
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) PathNotFoundException(javax.jcr.PathNotFoundException) Property(javax.jcr.Property) Session(javax.jcr.Session) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 93 with NotExecutableException

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

the class UpdateTest method testUpdateRemovesExtraProperty.

public void testUpdateRemovesExtraProperty() throws RepositoryException, NotExecutableException {
    // create test node in default workspace
    testRootNode.setProperty(propertyName2, "test");
    testRootNode.save();
    String srcWorkspace = getAnotherWorkspace();
    // get the root node in the second workspace
    Session session2 = getHelper().getSuperuserSession(srcWorkspace);
    try {
        // make sure the source-session has the corresponding node.
        Node testRootW2 = (Node) session2.getItem(testRootNode.getCorrespondingNodePath(srcWorkspace));
        if (testRootW2.hasProperty(propertyName2)) {
            throw new NotExecutableException();
        }
        // call the update method on test node in default workspace
        testRootNode.update(srcWorkspace);
        // ok first check if node has no longer properties
        assertFalse("Node updated with Node.update() should have property removed", testRootNode.hasProperty(propertyName2));
    } catch (PathNotFoundException e) {
        throw new NotExecutableException();
    } catch (ItemNotFoundException e) {
        throw new NotExecutableException();
    } finally {
        session2.logout();
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) PathNotFoundException(javax.jcr.PathNotFoundException) Session(javax.jcr.Session) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 94 with NotExecutableException

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

the class WorkspaceMoveTest method testMovePropertyExists.

/**
     * Tries to move a node using to a location where a property already exists
     * with same name.
     * <br/> <br/>
     * With JCR 1.0 this should throw an <code>{@link javax.jcr.ItemExistsException}</code>.
     * With JCR 2.0 the support for same-named property and node is optional and
     * the expected behaviour depends on the
     * {@link Repository#OPTION_NODE_AND_PROPERTY_WITH_SAME_NAME_SUPPORTED} descriptor.
     */
@Override
public void testMovePropertyExists() throws RepositoryException, NotExecutableException {
    // try to create a property with the name of the node to be moved
    // to the destination parent
    Property destProperty;
    try {
        destProperty = destParentNode.setProperty(nodeName2, "anyString");
        destParentNode.save();
    } catch (RepositoryException e) {
        throw new NotExecutableException("Cannot create property with name '" + nodeName2 + "' and value 'anyString' at move destination.");
    }
    // TODO: fix 2.0 behaviour according to the OPTION_NODE_AND_PROPERTY_WITH_SAME_NAME_SUPPORTED descriptor
    if ("1.0".equals(getHelper().getRepository().getDescriptor(Repository.SPEC_VERSION_DESC))) {
        try {
            // move the node
            doMove(moveNode.getPath(), destProperty.getPath());
            fail("Moving a node to a location where a property exists must throw ItemExistsException");
        } catch (ItemExistsException e) {
        // ok, works as expected
        }
    } else {
        // JCR 2.0 move the node: same name property and node must be supported
        doMove(moveNode.getPath(), destProperty.getPath());
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) ItemExistsException(javax.jcr.ItemExistsException) RepositoryException(javax.jcr.RepositoryException) Property(javax.jcr.Property)

Example 95 with NotExecutableException

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

the class WorkspaceTest method testCreateWorkspace.

public void testCreateWorkspace() throws Exception {
    Session s = null;
    try {
        Workspace wsp = superuser.getWorkspace();
        String name = getNewWorkspaceName(wsp);
        wsp.createWorkspace(name);
        List<String> wsps = Arrays.asList(wsp.getAccessibleWorkspaceNames());
        assertTrue(wsps.contains(name));
        s = getHelper().getSuperuserSession(name);
        Workspace newW = s.getWorkspace();
        assertEquals(name, newW.getName());
    } catch (UnsupportedRepositoryOperationException e) {
        throw new NotExecutableException();
    } catch (UnsupportedOperationException e) {
        throw new NotExecutableException();
    } finally {
        if (s != null) {
            s.logout();
        }
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Session(javax.jcr.Session) Workspace(javax.jcr.Workspace)

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