Search in sources :

Example 21 with Property

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

the class HoldEffectTest method assertEffect.

private void assertEffect(Node targetNode, String childName, String propName, String childName2, String propName2) throws RepositoryException {
    Session s = targetNode.getSession();
    try {
        Node child = targetNode.getNode(childName);
        child.remove();
        s.save();
        fail("Hold present must prevent a child node from being removed.");
    } catch (RepositoryException e) {
        // success
        s.refresh(false);
    }
    try {
        Property p = targetNode.getProperty(propName);
        p.remove();
        s.save();
        fail("Hold present must prevent a child property from being removed.");
    } catch (RepositoryException e) {
        // success
        s.refresh(false);
    }
    try {
        Property p = targetNode.getProperty(propName);
        p.setValue("test2");
        s.save();
        fail("Hold present must prevent the child property from being modified.");
    } catch (RepositoryException e) {
        // success
        s.refresh(false);
    }
    try {
        targetNode.addNode(childName2);
        s.save();
        fail("Hold present must prevent the target node from having new nodes added.");
    } catch (RepositoryException e) {
        // success
        s.refresh(false);
    }
    try {
        Value v = getJcrValue(s, RepositoryStub.PROP_PROP_VALUE2, RepositoryStub.PROP_PROP_TYPE2, "test");
        targetNode.setProperty(propName2, v);
        s.save();
        fail("Hold present must prevent the target node from having new properties set.");
    } catch (RepositoryException e) {
        // success
        s.refresh(false);
    }
    NodeType[] mixins = targetNode.getMixinNodeTypes();
    if (mixins.length > 0) {
        try {
            targetNode.removeMixin(mixins[0].getName());
            s.save();
            fail("Hold present must prevent the target node from having it's mixin types changed.");
        } catch (RepositoryException e) {
            // success
            s.refresh(false);
        }
    }
    try {
        targetNode.remove();
        s.save();
        fail("Hold present must prevent the target node from being removed.");
    } catch (RepositoryException e) {
        // success
        s.refresh(false);
    }
}
Also used : Node(javax.jcr.Node) NodeType(javax.jcr.nodetype.NodeType) Value(javax.jcr.Value) RepositoryException(javax.jcr.RepositoryException) Property(javax.jcr.Property) Session(javax.jcr.Session)

Example 22 with Property

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

the class VersionGraphTest method testInitialNodePredecessors.

/**
     * Test if after creation of a versionable node N the multi-value
     * REFERENCE property jcr:predecessors of N is initialized to contain a
     * single UUID, that of the root version (the same as jcr:baseVersion).
     *
     * @throws RepositoryException
     */
public void testInitialNodePredecessors() throws RepositoryException {
    Property predecessors = versionableNode.getProperty(jcrPredecessors);
    Value[] values = predecessors.getValues();
    Version rV = versionableNode.getVersionHistory().getRootVersion();
    if (values.length != 1) {
        fail("The jcr:predecessors property of a versionable node must be initialized to contain a single value");
    }
    Value initialVal = values[0];
    assertTrue("The jcr:predecessors property of a versionable node is initialized to contain a single UUID, that of the root version", initialVal.equals(superuser.getValueFactory().createValue(rV)));
}
Also used : Version(javax.jcr.version.Version) Value(javax.jcr.Value) Property(javax.jcr.Property)

Example 23 with Property

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

the class VersionHistoryTest method testGetReferences.

/**
     * Tests if <code>VersionHistory.getReferences()</code> returns the right
     * reference of the versionable node
     */
public void testGetReferences() throws Exception {
    PropertyIterator pi = vHistory.getReferences();
    boolean hasNodeReference = false;
    while (pi.hasNext()) {
        Property p = pi.nextProperty();
        if (p.getName().equals(jcrVersionHistory) && superuser.getNodeByUUID(p.getString()).isSame(vHistory)) {
            hasNodeReference = true;
            break;
        }
    }
    assertTrue("VersionHistory.getReferences() does not return the jcr:versionHistory property of the versioned Node", hasNodeReference);
}
Also used : PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property)

Example 24 with Property

use of javax.jcr.Property 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 25 with Property

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

the class WorkspaceMoveTest method testMovePropertyExists.

/**
     * Tries to move a node using to a location where a property already exists
     * with same name.
     * <br/> <br/>
     * With JCR 1.0 this should throw an <code>{@link javax.jcr.ItemExistsException}</code>.
     * With JCR 2.0 the support for same-named property and node is optional and
     * the expected behaviour depends on the
     * {@link Repository#OPTION_NODE_AND_PROPERTY_WITH_SAME_NAME_SUPPORTED} descriptor.
     */
@Override
public void testMovePropertyExists() throws RepositoryException, NotExecutableException {
    // try to create a property with the name of the node to be moved
    // to the destination parent
    Property destProperty;
    try {
        destProperty = destParentNode.setProperty(nodeName2, "anyString");
        destParentNode.save();
    } catch (RepositoryException e) {
        throw new NotExecutableException("Cannot create property with name '" + nodeName2 + "' and value 'anyString' at move destination.");
    }
    // TODO: fix 2.0 behaviour according to the OPTION_NODE_AND_PROPERTY_WITH_SAME_NAME_SUPPORTED descriptor
    if ("1.0".equals(getHelper().getRepository().getDescriptor(Repository.SPEC_VERSION_DESC))) {
        try {
            // move the node
            doMove(moveNode.getPath(), destProperty.getPath());
            fail("Moving a node to a location where a property exists must throw ItemExistsException");
        } catch (ItemExistsException e) {
        // ok, works as expected
        }
    } else {
        // JCR 2.0 move the node: same name property and node must be supported
        doMove(moveNode.getPath(), destProperty.getPath());
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) ItemExistsException(javax.jcr.ItemExistsException) RepositoryException(javax.jcr.RepositoryException) Property(javax.jcr.Property)

Aggregations

Property (javax.jcr.Property)445 Node (javax.jcr.Node)252 Value (javax.jcr.Value)99 Test (org.junit.Test)87 Session (javax.jcr.Session)78 PropertyIterator (javax.jcr.PropertyIterator)68 RepositoryException (javax.jcr.RepositoryException)64 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)47 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)37 ValueFormatException (javax.jcr.ValueFormatException)34 QValue (org.apache.jackrabbit.spi.QValue)29 ArrayList (java.util.ArrayList)24 NodeIterator (javax.jcr.NodeIterator)24 QValueValue (org.apache.jackrabbit.spi.commons.value.QValueValue)23 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)20 Item (javax.jcr.Item)19 PathNotFoundException (javax.jcr.PathNotFoundException)17 InvalidItemStateException (javax.jcr.InvalidItemStateException)16 Version (javax.jcr.version.Version)16 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)15