Search in sources :

Example 6 with Property

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

the class PropertyTypeTest method typeCheckChildren.

private void typeCheckChildren(Node parentNode) throws RepositoryException {
    NodeIterator nodes = parentNode.getNodes();
    while (nodes.hasNext()) {
        Node node = nodes.nextNode();
        PropertyIterator props = node.getProperties();
        while (props.hasNext()) {
            Property prop = props.nextProperty();
            int reqType = prop.getDefinition().getRequiredType();
            int type = PropertyType.UNDEFINED;
            boolean isEmptyMultipleArray = false;
            if (prop.getDefinition().isMultiple()) {
                if (prop.getValues().length > 0) {
                    type = prop.getValues()[0].getType();
                } else {
                    isEmptyMultipleArray = true;
                }
            } else {
                type = prop.getValue().getType();
            }
            if (!isEmptyMultipleArray && reqType != PropertyType.UNDEFINED) {
                assertFalse("The type of a property must not " + "be UNDEFINED", type == PropertyType.UNDEFINED);
                assertEquals("The type of a property has to match " + "the type of the property definition.", type, reqType);
            }
        }
        typeCheckChildren(node);
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property)

Example 7 with Property

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

the class PropertyTest method testIsSameMustNotCompareStates.

/**
     * Tests if <code>Item.isSame(Item otherItem)</code> will return true when
     * two <code>Property</code> objects representing the same actual repository
     * item have been retrieved through two different sessions and one has been
     * modified.
     * 
     * @since JCR 2.0
     */
public void testIsSameMustNotCompareStates() throws RepositoryException {
    // create a node, add a property and save it
    Node testNode1 = testRootNode.addNode(nodeName1, testNodeType);
    Property prop1 = testNode1.setProperty(propertyName1, "value1");
    testRootNode.getSession().save();
    // accuire the same property through a different session
    Session session = getHelper().getSuperuserSession();
    try {
        Property prop2 = session.getProperty(prop1.getPath());
        // change the value of prop2
        prop2.setValue("value2");
        assertTrue("Two references of same property must return true for " + "property1.isSame(property2)", prop1.isSame(prop2));
    } finally {
        session.logout();
    }
}
Also used : Node(javax.jcr.Node) Property(javax.jcr.Property) Session(javax.jcr.Session)

Example 8 with Property

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

the class PropertyItemIsModifiedTest method testTransientPropertyItemIsModified.

/**
     * Test if Item.isModified() returns true for an already existing and modified
     * PropertyItem (modifications aren't saved (transient)).
     *
     * @see javax.jcr.Item#isModified()
     */
public void testTransientPropertyItemIsModified() throws RepositoryException {
    Property testProperty = testNode.setProperty(propertyName1, "test1");
    testNode.save();
    testProperty.setValue("test2");
    Item testPropertyItem = superuser.getItem(testProperty.getPath());
    // check testPropertyItem.isModified() before save
    assertTrue("Item.isModified() must return true directly after an existing Property is modified (before current node is saved)", testPropertyItem.isModified());
}
Also used : Item(javax.jcr.Item) Property(javax.jcr.Property)

Example 9 with Property

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

the class PropertyItemIsModifiedTest method testTransientNewPropertyItemIsModified.

/**
     * Test if Item.isModified() returns false after a new PropertyItem is set
     * (before node is saved (transient). That means the PropertyItem don't exists
     * persistent).
     *
     * @see javax.jcr.Item#isModified()
     */
public void testTransientNewPropertyItemIsModified() throws RepositoryException {
    Property testProperty = testNode.setProperty(propertyName1, "test");
    Item testPropertyItem = superuser.getItem(testProperty.getPath());
    // check testPropertyItem.isModified() for a new PropertyItem before save
    assertFalse("Item.isModified() must return false directly after a new PropertyItem is set (before current node is saved)", testPropertyItem.isModified());
}
Also used : Item(javax.jcr.Item) Property(javax.jcr.Property)

Example 10 with Property

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

the class PropertyItemIsModifiedTest method testPersistentNewPropertyItemIsModified.

/**
     * Test if Item.isModified() returns false after a new PropertyItem is set
     * and saved (persistent). That means the PropertyItem exists persistently but
     * isn't modified after save.
     * This is equivalent to the test if Item.isModified() returns false for an
     * already exixting and not modified PropertyItem.
     *
     * @see javax.jcr.Item#isModified()
     */
public void testPersistentNewPropertyItemIsModified() throws RepositoryException {
    Property testProperty = testNode.setProperty(propertyName1, "test");
    testNode.save();
    Item testPropertyItem = superuser.getItem(testProperty.getPath());
    // check testPropertyItem.isModified() for a new PropertyItem after save
    assertFalse("Item.isModified() must return false after a new PropertyItem is set and current node is saved", testPropertyItem.isModified());
}
Also used : Item(javax.jcr.Item) 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