Search in sources :

Example 86 with Property

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

the class SetValueValueFormatExceptionTest method testString.

/**
     * Tests if setValue(String) throws a ValueFormatException immediately (not
     * on save) if a conversion fails.
     */
public void testString() throws NotExecutableException, RepositoryException {
    Property dateProperty = createProperty(PropertyType.DATE, false);
    try {
        dateProperty.setValue("abc");
        fail("Property.setValue(String) must throw a ValueFormatException " + "immediately if a conversion fails.");
    } catch (ValueFormatException e) {
    // success
    }
}
Also used : ValueFormatException(javax.jcr.ValueFormatException) Property(javax.jcr.Property)

Example 87 with Property

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

the class RSessionAccessControlTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    Node n = testRootNode.addNode(nodeName1, testNodeType);
    testNodePath = n.getPath();
    Value v = getJcrValue(superuser, RepositoryStub.PROP_PROP_VALUE1, RepositoryStub.PROP_PROP_TYPE1, "test");
    Property p = n.setProperty(propertyName1, v);
    testPropertyPath = p.getPath();
    testRootNode.getSession().save();
    readOnlySession = getHelper().getReadOnlySession();
}
Also used : Node(javax.jcr.Node) Value(javax.jcr.Value) Property(javax.jcr.Property)

Example 88 with Property

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

the class RetentionPolicyEffectTest 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("Retention policy 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("Retention policy 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("Retention policy present must prevent the child property from being modified.");
    } catch (RepositoryException e) {
        // success
        s.refresh(false);
    }
    try {
        targetNode.addNode(childName2);
        s.save();
        fail("Retention policy 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("Retention policy present must prevent the target node from having new properties set.");
    } 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) Value(javax.jcr.Value) RepositoryException(javax.jcr.RepositoryException) Property(javax.jcr.Property) Session(javax.jcr.Session)

Example 89 with Property

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

the class ExternalModificationTest method testExternalRemoval2.

public void testExternalRemoval2() throws RepositoryException, NotExecutableException {
    Node childN = refNode.addNode(nodeName3);
    Property p = childN.setProperty(propertyName1, "anyvalue");
    refNode.save();
    String uuid = refNode.getUUID();
    Node refNode2 = testSession.getNodeByUUID(uuid);
    Node c2 = (Node) testSession.getItem(childN.getPath());
    Property p2 = (Property) testSession.getItem(p.getPath());
    // transiently remove the property -> test effect of external removal.
    p2.remove();
    String srcPath = refNode.getPath();
    String destPath = destParentNode.getPath() + "/" + nodeName2;
    superuser.move(srcPath, destPath);
    superuser.save();
    try {
        refNode2.refresh(true);
        Node parent = refNode2.getParent();
    } catch (InvalidItemStateException e) {
    }
    assertItemStatus(refNode2, Status.REMOVED);
    assertItemStatus(c2, Status.STALE_DESTROYED);
    assertItemStatus(p2, Status.REMOVED);
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node) Property(javax.jcr.Property)

Example 90 with Property

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

the class GetPropertyTest method testGetPropertyOfRemovedAncestor.

public void testGetPropertyOfRemovedAncestor() throws RepositoryException {
    Session rw = getHelper().getReadWriteSession();
    try {
        // add modification to a property.
        Property p = (Property) rw.getItem(prop1Path);
        p.setValue("changedValue");
        // transiently remove the test root node
        rw.getItem(testRootNode.getPath()).remove();
        try {
            p.getValue();
            fail("modified property must be marked removed upon parent removal");
        } catch (InvalidItemStateException e) {
        // success
        }
        try {
            rw.getItem(prop1Path);
            fail("modified property must be marked removed upon parent removal");
        } catch (PathNotFoundException e) {
        // success
        }
        try {
            Property p2 = (Property) rw.getItem(prop2Path);
            fail("existing property must be marked removed upon parent removal");
        } catch (PathNotFoundException e) {
        // success
        }
        // revert all transient modifications
        rw.refresh(false);
        Property pAgain = (Property) rw.getItem(prop1Path);
        // TODO: for generic jsr 170 test: change assert to p.isSame(pAgain)
        assertTrue(p.isSame(pAgain));
        assertEquals("string1", p.getString());
    } finally {
        rw.logout();
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) PathNotFoundException(javax.jcr.PathNotFoundException) Property(javax.jcr.Property) Session(javax.jcr.Session)

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