Search in sources :

Example 91 with Node

use of javax.jcr.Node 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 Node

use of javax.jcr.Node 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 Node

use of javax.jcr.Node 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 Node

use of javax.jcr.Node in project jackrabbit by apache.

the class AddMixinTest method testImplicitMixinOnNewNode.

/**
     * Implementation specific test adding a new Node with a nodeType, that has
     * a mixin-supertype. The mixin must only take effect upon save.
     *
     * @throws NotExecutableException
     * @throws RepositoryException
     */
public void testImplicitMixinOnNewNode() throws NotExecutableException, RepositoryException {
    Node newNode;
    try {
        String ntResource = superuser.getNamespacePrefix(NS_NT_URI) + ":resource";
        newNode = testRootNode.addNode(nodeName1, ntResource);
    } catch (RepositoryException e) {
        throw new NotExecutableException();
    }
    assertFalse("Implict Mixin inherited by primary Nodetype must not be active before Node has been saved.", newNode.isNodeType(mixReferenceable));
    NodeType[] mixins = newNode.getMixinNodeTypes();
    for (int i = 0; i < mixins.length; i++) {
        if (mixins[i].getName().equals(testNodeType)) {
            fail("Implict Mixin inherited by primary Nodetype must not be active before Node has been saved.");
        }
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) NodeType(javax.jcr.nodetype.NodeType) RepositoryException(javax.jcr.RepositoryException)

Example 95 with Node

use of javax.jcr.Node in project jackrabbit by apache.

the class AddMixinTest method testAddItemsDefinedByMixin.

public void testAddItemsDefinedByMixin() throws NotExecutableException, RepositoryException {
    // register mixin
    NodeTypeManager ntm = superuser.getWorkspace().getNodeTypeManager();
    NodeTypeTemplate ntd = ntm.createNodeTypeTemplate();
    ntd.setName("testMixin");
    ntd.setMixin(true);
    NodeDefinitionTemplate nodeDef = ntm.createNodeDefinitionTemplate();
    nodeDef.setName("child");
    nodeDef.setRequiredPrimaryTypeNames(new String[] { "nt:folder" });
    ntd.getNodeDefinitionTemplates().add(nodeDef);
    ntm.registerNodeType(ntd, true);
    // create node and add mixin
    Node node = testRootNode.addNode(nodeName1, "nt:resource");
    node.setProperty("jcr:data", "abc");
    node.addMixin("testMixin");
    superuser.save();
    // create a child node defined by the mixin
    node.addNode("child", "nt:folder");
    node.save();
}
Also used : NodeDefinitionTemplate(javax.jcr.nodetype.NodeDefinitionTemplate) NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) Node(javax.jcr.Node)

Aggregations

Node (javax.jcr.Node)2620 Session (javax.jcr.Session)645 Test (org.junit.Test)643 RepositoryException (javax.jcr.RepositoryException)317 Property (javax.jcr.Property)251 NodeIterator (javax.jcr.NodeIterator)214 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)182 Value (javax.jcr.Value)158 Version (javax.jcr.version.Version)155 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)151 Query (javax.jcr.query.Query)122 QueryResult (javax.jcr.query.QueryResult)108 Event (javax.jcr.observation.Event)103 VersionManager (javax.jcr.version.VersionManager)97 Resource (org.apache.sling.api.resource.Resource)96 ArrayList (java.util.ArrayList)93 AccessDeniedException (javax.jcr.AccessDeniedException)89 InvalidItemStateException (javax.jcr.InvalidItemStateException)82 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)82 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)81