Search in sources :

Example 71 with NotExecutableException

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

the class PredefinedNodeTypeTest method testPredefinedNodeType.

/**
     * Tests that the named node type matches the JSR 170 specification.
     * The test is performed by genererating a node type definition spec
     * string in the format used by the JSR 170 specification, and comparing
     * the result with a static spec file extracted from the specification
     * itself.
     * <p>
     * Note that the extracted spec files are not exact copies of the node
     * type specification in the JSR 170 document. Some formatting and
     * ordering changes have been made to simplify the test code, but the
     * semantics remain the same.
     *
     * @param name node type name
     * @param propsVariant whether the properties of this node type may
     *   have implementation variant autocreated and OPV flags.
     * @throws NotExecutableException if the node type is not supported by
     *   this repository implementation.
     */
private void testPredefinedNodeType(String name, boolean propsVariant) throws NotExecutableException {
    try {
        StringBuffer spec = new StringBuffer();
        String resource = "org/apache/jackrabbit/test/api/nodetype/spec/" + name.replace(':', '-') + ".txt";
        Reader reader = new InputStreamReader(getClass().getClassLoader().getResourceAsStream(resource));
        for (int ch = reader.read(); ch != -1; ch = reader.read()) {
            spec.append((char) ch);
        }
        NodeType type = manager.getNodeType(name);
        String current = getNodeTypeSpec(type, propsVariant).trim();
        if (!System.getProperty("line.separator").equals("\n")) {
            current = normalizeLineSeparators(current);
        }
        String expected = normalizeLineSeparators(spec.toString()).trim();
        assertEquals("Predefined node type " + name, expected, current);
        // check minimum declared supertypes
        Set<String> declaredSupertypes = new HashSet<String>();
        for (Iterator<NodeType> it = Arrays.asList(type.getDeclaredSupertypes()).iterator(); it.hasNext(); ) {
            NodeType nt = it.next();
            declaredSupertypes.add(nt.getName());
        }
        for (Iterator<String> it = Arrays.asList(SUPERTYPES.get(name)).iterator(); it.hasNext(); ) {
            String supertype = it.next();
            assertTrue("Predefined node type " + name + " does not " + "declare supertype " + supertype, declaredSupertypes.contains(supertype));
        }
    } catch (IOException e) {
        fail(e.getMessage());
    } catch (NoSuchNodeTypeException e) {
        // only nt:base is strictly required
        if ("nt:base".equals(name)) {
            fail(e.getMessage());
        } else {
            throw new NotExecutableException("NodeType " + name + " not supported by this repository implementation.");
        }
    } catch (RepositoryException e) {
        fail(e.getMessage());
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) HashSet(java.util.HashSet)

Example 72 with NotExecutableException

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

the class PropertyChangedTest method testPropertyRemoveCreate.

/**
     * Tests if either a
     * <ul>
     * <li>{@link Event#PROPERTY_CHANGED}</li>
     * <li>{@link Event#PROPERTY_REMOVED} and {@link Event#PROPERTY_ADDED}</li>
     * </ul>
     * is triggered if a property is transiently removed and set again with
     * the same name but different type and then saved.
     * <p>
     * If the node type {@link #testNodeType} does not suppport a property with
     * name {@link #propertyName1} of type {@link PropertyType#UNDEFINED} a
     * {@link NotExecutableException} is thrown.
     */
public void testPropertyRemoveCreate() throws RepositoryException, NotExecutableException {
    Node n = testRootNode.addNode(nodeName1, testNodeType);
    NodeType nt = superuser.getWorkspace().getNodeTypeManager().getNodeType(testNodeType);
    Value v1 = superuser.getValueFactory().createValue("foo");
    Value v2 = superuser.getValueFactory().createValue(System.currentTimeMillis());
    if (!nt.canSetProperty(propertyName1, v1) || !nt.canSetProperty(propertyName1, v2)) {
        throw new NotExecutableException("Property " + propertyName1 + " is not of type UNDEFINED");
    }
    n.setProperty(propertyName1, v1);
    testRootNode.getSession().save();
    EventResult result = new EventResult(log);
    addEventListener(result, Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED | Event.PROPERTY_REMOVED);
    n.getProperty(propertyName1).remove();
    n.setProperty(propertyName1, v2);
    testRootNode.getSession().save();
    Event[] events = result.getEvents(DEFAULT_WAIT_TIMEOUT);
    removeEventListener(result);
    if (events.length == 1) {
        checkPropertyChanged(events, new String[] { nodeName1 + "/" + propertyName1 });
    } else {
        // prop remove and add event
        assertEquals("Expected 2 events for a property type change.", 2, events.length);
        int type = Event.PROPERTY_ADDED | Event.PROPERTY_REMOVED;
        String path = testRoot + "/" + nodeName1 + "/" + propertyName1;
        for (int i = 0; i < events.length; i++) {
            assertTrue("Event is not of type PROPERTY_REMOVED or PROPERTY_ADDED", (events[i].getType() & type) > 0);
            assertEquals("Path for event is wrong.", path, events[i].getPath());
        }
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) NodeType(javax.jcr.nodetype.NodeType) Value(javax.jcr.Value) Event(javax.jcr.observation.Event)

Example 73 with NotExecutableException

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

the class AddEventListenerTest method testUUID.

/**
     * Tests if events are only generated for specified UUIDs.
     */
public void testUUID() throws RepositoryException, NotExecutableException {
    Node n1 = null;
    Node n2 = null;
    try {
        n1 = createReferenceable(nodeName1, testNodeType);
        n2 = createReferenceable(nodeName2, testNodeType);
    } catch (RepositoryException e) {
        throw new NotExecutableException("Repository does not support mix:referenceable");
    }
    testRootNode.getSession().save();
    EventResult listener = new EventResult(log);
    obsMgr.addEventListener(listener, Event.PROPERTY_ADDED, testRoot, true, new String[] { n1.getIdentifier() }, null, false);
    n1.setProperty(propertyName1, "foo");
    n2.setProperty(propertyName1, "foo");
    testRootNode.getSession().save();
    Event[] events = listener.getEvents(DEFAULT_WAIT_TIMEOUT);
    obsMgr.removeEventListener(listener);
    checkPropertyAdded(events, new String[] { nodeName1 + "/" + propertyName1 });
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) RepositoryException(javax.jcr.RepositoryException)

Example 74 with NotExecutableException

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

the class EventIteratorTest method testGetSize.

/**
     * Tests if getSize() returns the correct number of events. If getSize()
     * returns -1 a {@link org.apache.jackrabbit.test.NotExecutableException}
     * is thrown.
     */
public void testGetSize() throws RepositoryException, NotExecutableException {
    EventResult listener = new EventResult(log);
    addEventListener(listener, Event.NODE_ADDED);
    testRootNode.addNode(nodeName1, testNodeType);
    testRootNode.getSession().save();
    EventIterator events = listener.getEventIterator(DEFAULT_WAIT_TIMEOUT);
    removeEventListener(listener);
    assertNotNull("No events delivered within " + DEFAULT_WAIT_TIMEOUT + "ms.", events);
    long size = events.getSize();
    if (size == -1) {
        throw new NotExecutableException("EventIterator.getSize() returns unavailable size.");
    }
    assertEquals("Wrong number of events", 1, size);
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) EventIterator(javax.jcr.observation.EventIterator)

Example 75 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)

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