Search in sources :

Example 51 with Node

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

the class PropertyTypeTest method testType.

/**
     * Tests if the type of a property is set according to the node type as well
     * as no property is of type UNDEFINED. This test runs recursively through
     * the workspace starting at {@link #testRoot}.
     */
public void testType() throws RepositoryException {
    Session session = getHelper().getReadOnlySession();
    try {
        Node root = session.getRootNode().getNode(testPath);
        typeCheckChildren(root);
    } finally {
        session.logout();
    }
}
Also used : Node(javax.jcr.Node) Session(javax.jcr.Session)

Example 52 with Node

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

the class ReferenceableRootNodesTest method testReferenceableRootNode.

/**
     * A repository implementation may make its workspace root nodes
     * mix:referenceable. If so, then the root node of all workspaces must be
     * referenceable, and all must have the same UUID.
     */
public void testReferenceableRootNode() throws RepositoryException, NotExecutableException {
    // compare UUID of default workspace and a second workspace
    Node rootNode = session.getRootNode();
    if (rootNode.isNodeType(mixReferenceable)) {
        // check if root node in second workspace is referenceable too
        Node rootNodeW2 = sessionW2.getRootNode();
        if (!rootNodeW2.isNodeType(mixReferenceable)) {
            fail("Root node in second workspace is not referenceable.");
        }
        // check if all root nodes have the same UUID
        assertEquals("Referenceable root nodes of different workspaces must have same UUID.", rootNode.getUUID(), rootNodeW2.getUUID());
    } else {
        throw new NotExecutableException("Root node is not referenceable");
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node)

Example 53 with Node

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

the class PathPropertyTest method testGetNode.

/**
     * Since JCR 2.0 a path property can be dereferenced if it points to a
     * Node.
     * TODO: create several tests out of this one
     */
public void testGetNode() throws RepositoryException {
    if (!multiple) {
        String nodePath = prop.getParent().getPath();
        String propName = prop.getName();
        // absolute nodes path
        prop.getParent().setProperty(propName, nodePath, PropertyType.PATH);
        String value = prop.getString();
        Node n = prop.getNode();
        assertEquals("The path of the dereferenced property must be equal to the value", n.getPath(), value);
        assertTrue("The property value must be resolved to the correct node.", prop.getParent().isSame(n));
        // relative node path
        prop.getParent().setProperty(propName, ".", PropertyType.PATH);
        n = prop.getNode();
        assertTrue("The property value must be resolved to the correct node.", prop.getParent().getNode(".").isSame(n));
        // non-existing property path
        while (session.nodeExists(nodePath)) {
            nodePath += "x";
        }
        prop.getParent().setProperty(propName, nodePath, PropertyType.PATH);
        try {
            prop.getNode();
            fail("Calling Property.getNode() for a PATH value that doesn't have a corresponding Node, ItemNotFoundException is expected");
        } catch (ItemNotFoundException e) {
        //ok
        }
    } else {
        try {
            prop.getNode();
            fail("Property.getNode() called on a multivalue property " + "should throw a ValueFormatException.");
        } catch (ValueFormatException vfe) {
        //ok
        }
    }
}
Also used : Node(javax.jcr.Node) ValueFormatException(javax.jcr.ValueFormatException) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 54 with Node

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

the class SessionTest method testRefreshBooleanFalse.

/**
     * Checks if {@link javax.jcr.Session#refresh(boolean refresh)} works
     * properly with <code>refresh</code> set to <code>false</code>.
     * <p>
     * Procedure: <ul> <li>Creates two nodes with session 1</li> <li>Modifies
     * node 1 with session 1 by adding a child node</li> <li>Get node 2 with
     * session 2</li> <li>Modifies node 2 with session 2 by adding a child
     * node</li> <li>saves session 2 changes using {@link
     * javax.jcr.Session#save()}</li> <li>calls <code>Session.refresh(false)</code>
     * on session 1</li> </ul> Session 1 changes should be cleared and session 2
     * changes should now be visible to session 1.
     * <p>
     * Prerequisites: <ul>
     * <li><code>javax.jcr.tck.nodetype</code> must accept children of same
     * nodetype</li> </ul>
     */
public void testRefreshBooleanFalse() throws RepositoryException {
    // get default workspace test root node using superuser session
    Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
    // create a node
    Node testNode1Session1 = defaultRootNode.addNode(nodeName1, testNodeType);
    // create a second node
    Node testNode2Session1 = defaultRootNode.addNode(nodeName2, testNodeType);
    // save the new nodes
    superuser.save();
    // add child node to test node 1 using session 1
    testNode1Session1.addNode(nodeName2, testNodeType);
    // get session 2
    Session session2 = getHelper().getReadWriteSession();
    try {
        // get the second node
        Node testNode2Session2 = (Node) session2.getItem(testNode2Session1.getPath());
        // adds a child node
        testNode2Session2.addNode(nodeName3, testNodeType);
        // save the changes
        session2.save();
        // call refresh on session 1
        superuser.refresh(false);
        // check if session 1 flag has been cleared
        assertFalse("Session should have no pending changes recorded after Session.refresh(false)!", superuser.hasPendingChanges());
        // check if added child node for node 1 by session 1 has been removed
        assertFalse("Node Modifications have not been flushed after session.refresh(false)", testNode1Session1.hasNodes());
        // check if added child node for node 2 by session 2 has become visible in session 1
        assertTrue("Node modified by a different session has not been updated after Session.refresh(false)", testNode2Session1.hasNodes());
    } finally {
        session2.logout();
    }
}
Also used : Node(javax.jcr.Node) Session(javax.jcr.Session)

Example 55 with Node

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

the class SessionTest method testMoveConstraintViolationExceptionSrc.

/**
     * Moves a node using {@link javax.jcr.Session#move(String src, String dest)},
     * afterwards it tries to only save the old parent node.
     * <p>
     * This should throw {@link javax.jcr.nodetype.ConstraintViolationException}.
     * <p>
     * Prerequisites: <ul> <li><code>javax.jcr.tck.nodetype</code>
     * must accept children of same nodetype</li> </ul>
     */
public void testMoveConstraintViolationExceptionSrc() throws RepositoryException {
    // get default workspace test root node using superuser session
    Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
    // create parent node
    Node srcParentNode = defaultRootNode.addNode(nodeName1, testNodeType);
    // create node to be moved
    Node moveNode = srcParentNode.addNode(nodeName2, testNodeType);
    // create a node that will serve as new parent
    Node destParentNode = defaultRootNode.addNode(nodeName3, testNodeType);
    // save the new nodes
    superuser.save();
    // move the node
    superuser.move(moveNode.getPath(), destParentNode.getPath() + "/" + nodeName2);
    // save only old parent node
    try {
        srcParentNode.save();
        fail("Saving only the source parent node after a Session.move() operation must throw ConstraintViolationException");
    } catch (ConstraintViolationException e) {
    // ok both work as expected
    }
}
Also used : Node(javax.jcr.Node) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException)

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