Search in sources :

Example 96 with NotExecutableException

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

the class NodeReorderTest method testNodeReorderSameName.

/**
     * Tests if reordering a child node triggers a {@link Event#NODE_REMOVED}
     * and a {@link Event#NODE_ADDED} event with same name siblings.
     */
public void testNodeReorderSameName() throws RepositoryException, NotExecutableException {
    if (!testRootNode.getDefinition().getDeclaringNodeType().hasOrderableChildNodes()) {
        throw new NotExecutableException("Node at '" + testRoot + "' does not support orderable child nodes.");
    }
    /**
         * Initial tree:
         *  + testroot
         *      + nodename1[1]
         *      + nodename1[2]
         *      + nodename1[3]
         *
         * After reorder:
         *  + testroot
         *      + nodename1[1]
         *      + nodename1[2] (was 3)
         *      + nodename1[3] (was 2)
         */
    Node n = testRootNode.addNode(nodeName1, testNodeType);
    if (!n.getDefinition().allowsSameNameSiblings()) {
        throw new NotExecutableException("Node at " + testRoot + " does not allow same name siblings with name " + nodeName1);
    }
    testRootNode.addNode(nodeName1, testNodeType);
    testRootNode.addNode(nodeName1, testNodeType);
    testRootNode.getSession().save();
    EventResult addNodeListener = new EventResult(log);
    EventResult removeNodeListener = new EventResult(log);
    EventResult moveNodeListener = new EventResult(log);
    addEventListener(addNodeListener, Event.NODE_ADDED);
    addEventListener(removeNodeListener, Event.NODE_REMOVED);
    addEventListener(moveNodeListener, Event.NODE_MOVED);
    testRootNode.orderBefore(nodeName1 + "[3]", nodeName1 + "[2]");
    //testRootNode.orderBefore(nodeName1 + "[2]", null);
    testRootNode.getSession().save();
    Event[] added = addNodeListener.getEvents(DEFAULT_WAIT_TIMEOUT);
    Event[] removed = removeNodeListener.getEvents(DEFAULT_WAIT_TIMEOUT);
    Event[] moved = moveNodeListener.getEvents(DEFAULT_WAIT_TIMEOUT);
    removeEventListener(addNodeListener);
    removeEventListener(removeNodeListener);
    removeEventListener(moveNodeListener);
    // either
    // 1) nodename1[2] has been reordered to the end
    // or:
    // 2) nodename1[3] has been reordered before nodename1[2]
    // that is, the following event sets are correct:
    // 1) nodename1[2]:remove, nodename1[3]:add
    // or:
    // 2) nodename1[3]:remove, nodename1[2]:add
    // if true, check for option 1)
    boolean reorderEnd = false;
    for (int i = 0; i < added.length; i++) {
        if (added[i].getPath().endsWith(nodeName1 + "[3]")) {
            reorderEnd = true;
            break;
        }
    }
    if (reorderEnd) {
        checkNodeAdded(added, new String[] { nodeName1 + "[3]" }, null);
        checkNodeRemoved(removed, new String[] { nodeName1 + "[2]" }, null);
        checkNodeReordered(moved, nodeName1 + "[2]", nodeName1 + "[3]", null);
    } else {
        checkNodeAdded(added, new String[] { nodeName1 + "[2]" }, null);
        checkNodeRemoved(removed, new String[] { nodeName1 + "[3]" }, null);
        checkNodeReordered(moved, nodeName1 + "[3]", nodeName1 + "[2]", nodeName1 + "[2]");
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) Event(javax.jcr.observation.Event)

Example 97 with NotExecutableException

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

the class WorkspaceRestoreTest method testWorkspaceRestoreWithUUIDConflict.

/**
     * Tests if restoring the <code>Version</code> of an existing node throws an
     * <code>ItemExistsException</code> if removeExisting is set to FALSE.
     */
@SuppressWarnings("deprecation")
public void testWorkspaceRestoreWithUUIDConflict() throws RepositoryException, NotExecutableException {
    try {
        // Verify that nodes used for the test are indeed versionable
        NodeDefinition nd = wVersionableNode.getDefinition();
        if (nd.getOnParentVersion() != OnParentVersionAction.COPY && nd.getOnParentVersion() != OnParentVersionAction.VERSION) {
            throw new NotExecutableException("Nodes must be versionable in order to run this test.");
        }
        Version v = wVersionableNode.checkin();
        wVersionableNode.checkout();
        wSuperuser.move(wVersionableChildNode.getPath(), wVersionableNode2.getPath() + "/" + wVersionableChildNode.getName());
        wSuperuser.save();
        wSuperuser.getWorkspace().restore(new Version[] { v }, false);
        fail("Node.restore( Version, boolean ): An ItemExistsException must be thrown if the node to be restored already exsits and removeExisting was set to false.");
    } catch (ItemExistsException e) {
    // success
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Version(javax.jcr.version.Version) ItemExistsException(javax.jcr.ItemExistsException) NodeDefinition(javax.jcr.nodetype.NodeDefinition)

Example 98 with NotExecutableException

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

the class RestoreTest method testRestoreWithUUIDConflictJcr2_3.

/**
     * Tests if restoring the <code>Version</code> of an existing node throws an
     * <code>ItemExistsException</code> if removeExisting is set to FALSE.
     */
public void testRestoreWithUUIDConflictJcr2_3() throws RepositoryException, NotExecutableException {
    try {
        Node naa = createVersionableNode(versionableNode, nodeName4, versionableNodeType);
        // Verify that nodes used for the test have proper opv behaviour
        NodeDefinition nd = naa.getDefinition();
        if (nd.getOnParentVersion() != OnParentVersionAction.COPY && nd.getOnParentVersion() != OnParentVersionAction.VERSION) {
            throw new NotExecutableException("Child nodes must have OPV COPY or VERSION in order to be able to test Node.restore with uuid conflict.");
        }
        Version v = versionManager.checkin(versionableNode.getPath());
        versionManager.checkout(versionableNode.getPath());
        superuser.move(naa.getPath(), versionableNode2.getPath() + "/" + naa.getName());
        superuser.save();
        versionManager.restore(versionableNode.getPath(), v.getName(), false);
        fail("Node.restore( Version, boolean ): An ItemExistsException must be thrown if the node to be restored already exsits and removeExisting was set to false.");
    } catch (ItemExistsException e) {
    // success
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Version(javax.jcr.version.Version) ItemExistsException(javax.jcr.ItemExistsException) Node(javax.jcr.Node) NodeDefinition(javax.jcr.nodetype.NodeDefinition)

Example 99 with NotExecutableException

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

the class SessionImportTest method testEmptyMixins2.

/**
     * Test case for issue <a href="https://issues.apache.org/jira/browse/JCR-1857">JCR-1857</href>
     *
     * @throws IOException
     * @throws RepositoryException
     */
public void testEmptyMixins2() throws IOException, RepositoryException, NotExecutableException {
    /*
        look for a a node type that includes mix:referenceable but isn't any
        of the known internal nodetypes that ev. cannot be created through a
        session-import
        */
    String referenceableNt = null;
    NodeTypeIterator it = superuser.getWorkspace().getNodeTypeManager().getPrimaryNodeTypes();
    while (it.hasNext() && referenceableNt == null) {
        NodeType nt = it.nextNodeType();
        String ntName = nt.getName();
        if (nt.isNodeType(mixReferenceable) && !nt.isAbstract() && // ignore are built-in nodetypes (mostly version related)
        !ntName.startsWith("nt:") && // also skip all internal node types...
        !ntName.startsWith("rep:")) {
            referenceableNt = ntName;
        }
    }
    if (referenceableNt == null) {
        throw new NotExecutableException("No primary type found that extends from mix:referenceable.");
    }
    /*
        TODO: retrieve valid jcr:uuid value from test-properties.
        */
    String uuid = UUID.randomUUID().toString();
    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<sv:node xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\"\n" + "         xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\"\n" + "         xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\"\n" + "         xmlns:jcr=\"http://www.jcp.org/jcr/1.0\"\n" + "         sv:name=\"testnode1\">\n" + "    <sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\">\n" + "        <sv:value>" + referenceableNt + "</sv:value>\n" + "    </sv:property>\n" + "    <sv:property sv:name=\"jcr:uuid\" sv:type=\"String\">\n" + "        <sv:value>" + uuid + "</sv:value>\n" + "    </sv:property>\n" + "</sv:node>";
    InputStream in = new ByteArrayInputStream(xml.getBytes());
    superuser.importXML(testRootNode.getPath(), in, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW);
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NodeType(javax.jcr.nodetype.NodeType) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator)

Example 100 with NotExecutableException

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

the class SetPropertyConstraintViolationExceptionTest method testBinaryProperty.

/**
     * Tests if setProperty(String name, InputStream value) and
     * setProperty(String name, Value value) where value is a BinaryValue throw
     * a ConstraintViolationException either immediately (by setProperty()), or
     * on save, if the change would violate a node type constraint
     */
public void testBinaryProperty() throws NotExecutableException, RepositoryException {
    // locate a PropertyDefinition with ValueConstraints
    PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(superuser, PropertyType.BINARY, false, false, true, false);
    if (propDef == null) {
        throw new NotExecutableException("No binary property def with " + "testable value constraints has been found");
    }
    // find a Value that does not satisfy the ValueConstraints of propDef
    Value valueNotSatisfied1 = NodeTypeUtil.getValueAccordingToValueConstraints(superuser, propDef, false);
    Value valueNotSatisfied2 = NodeTypeUtil.getValueAccordingToValueConstraints(superuser, propDef, false);
    if (valueNotSatisfied1 == null || valueNotSatisfied2 == null) {
        throw new NotExecutableException("No binary property def with " + "testable value constraints has been found");
    }
    // create a sub node of testRootNode of type propDef.getDeclaringNodeType()
    Node node;
    try {
        String nodeType = propDef.getDeclaringNodeType().getName();
        node = testRootNode.addNode(nodeName2, nodeType);
        testRootNode.getSession().save();
    } catch (ConstraintViolationException e) {
        // implementation specific constraints do not allow to set up test environment
        throw new NotExecutableException("Not able to create required test items.");
    }
    // test of signature setProperty(String name, InputStream value)
    InputStream in = valueNotSatisfied1.getStream();
    try {
        node.setProperty(propDef.getName(), in);
        node.save();
        fail("setProperty(String name, InputStream value) must throw a " + "ConstraintViolationException if the change would violate a " + "node type constraint either immediately or on save");
    } catch (ConstraintViolationException e) {
    // success
    } finally {
        try {
            in.close();
        } catch (IOException ignore) {
        }
    }
    // test of signature setProperty(String name, Value value)
    try {
        node.setProperty(propDef.getName(), valueNotSatisfied2);
        node.save();
        fail("setProperty(String name, Value value) must throw a " + "ConstraintViolationException if the change would violate a " + "node type constraint either immediately or on save");
    } catch (ConstraintViolationException e) {
    // success
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) InputStream(java.io.InputStream) Node(javax.jcr.Node) Value(javax.jcr.Value) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) IOException(java.io.IOException) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

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