Search in sources :

Example 56 with NotExecutableException

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

the class NodeSetPrimaryTypeTest method testCheckedIn.

/**
     * Tests if <code>Node.setPrimaryType(String)</code> throws a
     * <code>VersionException</code> if <code>Node</code> is checked-in.
     */
public void testCheckedIn() throws NotExecutableException, RepositoryException {
    Session session = testRootNode.getSession();
    if (!isSupported(Repository.OPTION_VERSIONING_SUPPORTED)) {
        throw new NotExecutableException("Versioning is not supported.");
    }
    // create a node that is versionable
    Node node = testRootNode.addNode(nodeName1, testNodeType);
    // or try to make it versionable if it is not
    ensureMixinType(node, mixVersionable);
    superuser.save();
    String primaryTypeName = getPrimaryTypeName(session, node);
    if (primaryTypeName == null) {
        throw new NotExecutableException("No testable node type found");
    }
    node.checkin();
    try {
        node.setPrimaryType(primaryTypeName);
        fail("Node.setPrimaryType(String) must throw a VersionException if the node is checked-in.");
    } catch (VersionException e) {
    // success
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) Session(javax.jcr.Session) VersionException(javax.jcr.version.VersionException)

Example 57 with NotExecutableException

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

the class NodeSetPrimaryTypeTest method testLocked.

/**
     * Tests if <code>Node.setPrimaryType(String)</code> throws a
     * <code>LockException</code> if <code>Node</code> is locked.
     */
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 primaryTypeName = getPrimaryTypeName(session, node);
    if (primaryTypeName == null) {
        throw new NotExecutableException("No testable 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.setPrimaryType(primaryTypeName);
            node.save();
            fail("Node.setPrimaryType(String) 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 58 with NotExecutableException

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

the class NodeReadMethodsTest method testGetPrimaryItemItemNotFoundException.

/**
     * Test if getPrimaryItem does throw an ItemNotFoundException if the primary
     * node type does not define a primary item. Therefor a node without a
     * primary item is located recursively in the entire repository. A
     * NotExecutableException is thrown when no such node is found.
     */
public void testGetPrimaryItemItemNotFoundException() throws NotExecutableException, RepositoryException {
    Node node = locateNodeWithoutPrimaryItem(testRootNode);
    if (node == null) {
        throw new NotExecutableException("Workspace does not contain a node without primary item defined");
    }
    try {
        node.getPrimaryItem();
        fail("getPrimaryItem() must throw a ItemNotFoundException " + "if the primary node type does not define one");
    } catch (ItemNotFoundException e) {
    // success
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 59 with NotExecutableException

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

the class NodeReadMethodsTest method testGetUUIDOfNonReferenceableNode.

/**
     * Test if getUUID() throws a UnsupportedRepositoryOperationException if
     * Node is not referenceable
     */
public void testGetUUIDOfNonReferenceableNode() throws NotExecutableException, RepositoryException {
    // find a node NOT of type mix:referenceable
    Node node = locateNonReferenceableNode(testRootNode);
    if (node == null) {
        throw new NotExecutableException("Workspace does not contain a non referenceable node");
    }
    try {
        node.getUUID();
        fail("UnsupportedRepositoryOperationException expected");
    } catch (UnsupportedRepositoryOperationException e) {
    // success
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node)

Example 60 with NotExecutableException

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

the class NodeReadMethodsTest method testHasNode.

/**
     * Test if hasNode(String relPath) returns true if the required node exists
     * and false if it doesn't. Tested node: root
     */
public void testHasNode() throws NotExecutableException, RepositoryException {
    Node node = testRootNode;
    NodeIterator nodes = node.getNodes();
    StringBuffer notExistingNodeName = new StringBuffer();
    while (nodes.hasNext()) {
        Node n = nodes.nextNode();
        assertTrue("hasNode(String relPath) returns false although " + "node at relPath is existing", node.hasNode(n.getName()));
        notExistingNodeName.append(n.getName() + "X");
    }
    if (notExistingNodeName.toString().equals("")) {
        throw new NotExecutableException("Workspace does not have sufficient content for this test. " + "Root node must have at least one child node.");
    }
    assertFalse("hasNode(String relPath) returns true although " + "node at relPath is not existing", node.hasNode(notExistingNodeName.toString().replaceAll(":", "")));
}
Also used : NodeIterator(javax.jcr.NodeIterator) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node)

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