Search in sources :

Example 16 with Value

use of javax.jcr.Value 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 17 with Value

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

the class HoldEffectTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    childN = testRootNode.addNode(nodeName2);
    Value v = getJcrValue(superuser, RepositoryStub.PROP_PROP_VALUE1, RepositoryStub.PROP_PROP_TYPE1, "test");
    childP = testRootNode.setProperty(propertyName1, v);
    superuser.save();
    otherS = getHelper().getSuperuserSession();
}
Also used : Value(javax.jcr.Value)

Example 18 with Value

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

the class QueryObjectModelFactoryTest method testLiteral.

/**
     * Test case for {@link QueryObjectModelFactory#literal(Value)}
     */
public void testLiteral() throws RepositoryException {
    Value v = superuser.getValueFactory().createValue("test");
    Literal literal = qf.literal(v);
    assertEquals("Wrong literal value", v.getString(), literal.getLiteralValue().getString());
}
Also used : Literal(javax.jcr.query.qom.Literal) BindVariableValue(javax.jcr.query.qom.BindVariableValue) Value(javax.jcr.Value) PropertyValue(javax.jcr.query.qom.PropertyValue)

Example 19 with Value

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

the class RowTest method testGetValues.

public void testGetValues() throws RepositoryException {
    Row r = getRow();
    Value[] values = r.getValues();
    assertEquals("wrong number of columns", 1, values.length);
    assertEquals("property value does not match", TEST_VALUE, values[0].getString());
}
Also used : Value(javax.jcr.Value) Row(javax.jcr.query.Row)

Example 20 with Value

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

the class VersionHistoryTest method testSetProperty.

/**
     * Tests if <ul> <li><code>VersionHistory.setProperty(String,
     * String[])</code></li> <li><code>VersionHistory.setProperty(String,
     * String[], int)</code></li> <li><code>VersionHistory.setProperty(String,
     * Value[])</code></li> <li><code>VersionHistory.setProperty(String,
     * Value[], int)</code></li> <li><code>VersionHistory.setProperty(String,
     * boolean)</code></li> <li><code>VersionHistory.setProperty(String,
     * double)</code></li> <li><code>VersionHistory.setProperty(String,
     * InputStream)</code></li> <li><code>VersionHistory.setProperty(String,
     * String)</code></li> <li><code>VersionHistory.setProperty(String,
     * Calendar)</code></li> <li><code>VersionHistory.setProperty(String,
     * Node)</code></li> <li><code>VersionHistory.setProperty(String,
     * Value)</code></li> <li><code>VersionHistory.setProperty(String,
     * long)</code></li> </ul> all throw a {@link javax.jcr.nodetype.ConstraintViolationException}
     */
public void testSetProperty() throws Exception {
    // create Value[] object
    Value[] vArray = new Value[3];
    vArray[0] = superuser.getValueFactory().createValue("abc");
    vArray[1] = superuser.getValueFactory().createValue("xyz");
    vArray[2] = superuser.getValueFactory().createValue("123");
    // create String array
    String[] s = { "abc", "xyz", "123" };
    try {
        vHistory.setProperty(propertyName1, s);
        vHistory.getSession().save();
        fail("VersionHistory should be read-only: VersionHistory.setProperty(String,String[]) did not throw a ConstraintViolationException");
    } catch (ConstraintViolationException success) {
    }
    try {
        vHistory.setProperty(propertyName1, s, PropertyType.STRING);
        vHistory.getSession().save();
        fail("VersionHistory should be read-only: VersionHistory.setProperty(String,String[],int) did not throw a ConstraintViolationException");
    } catch (ConstraintViolationException success) {
    }
    try {
        vHistory.setProperty(propertyName1, vArray);
        vHistory.getSession().save();
        fail("VersionHistory should be read-only: VersionHistory.setProperty(String,Value[]) did not throw a ConstraintViolationException");
    } catch (ConstraintViolationException success) {
    }
    try {
        vHistory.setProperty(propertyName1, vArray, PropertyType.STRING);
        vHistory.getSession().save();
        fail("VersionHistory should be read-only: VersionHistory.setProperty(String,Value[],int]) did not throw a ConstraintViolationException");
    } catch (ConstraintViolationException success) {
    }
    try {
        vHistory.setProperty(propertyName1, true);
        vHistory.getSession().save();
        fail("VersionHistory should be read-only: VersionHistory.setProperty(String,boolean) did not throw a ConstraintViolationException");
    } catch (ConstraintViolationException success) {
    }
    try {
        vHistory.setProperty(propertyName1, 123);
        vHistory.getSession().save();
        fail("VersionHistory should be read-only: VersionHistory.setProperty(String,double) did not throw a ConstraintViolationException");
    } catch (ConstraintViolationException success) {
    }
    try {
        byte[] bytes = { 73, 26, 32, -36, 40, -43, -124 };
        InputStream inpStream = new ByteArrayInputStream(bytes);
        vHistory.setProperty(propertyName1, inpStream);
        vHistory.getSession().save();
        fail("VersionHistory should be read-only: VersionHistory.setProperty(String,InputStream) did not throw a ConstraintViolationException");
    } catch (ConstraintViolationException success) {
    }
    try {
        vHistory.setProperty(propertyName1, "abc");
        vHistory.getSession().save();
        fail("VersionHistory should be read-only: VersionHistory.setProperty(String,String) did not throw a ConstraintViolationException");
    } catch (ConstraintViolationException success) {
    }
    try {
        Calendar c = new GregorianCalendar(1945, 1, 6, 16, 20, 0);
        vHistory.setProperty(propertyName1, c);
        vHistory.getSession().save();
        fail("VersionHistory should be read-only: VersionHistory.setProperty(String,Calendar) did not throw a ConstraintViolationException");
    } catch (ConstraintViolationException success) {
    }
    try {
        vHistory.setProperty(propertyName1, vHistory);
        vHistory.getSession().save();
        fail("VersionHistory should be read-only: VersionHistory.setProperty(String,Node) did not throw a ConstraintViolationException");
    } catch (ConstraintViolationException success) {
    }
    try {
        Value v = superuser.getValueFactory().createValue("abc");
        vHistory.setProperty(propertyName1, v);
        vHistory.getSession().save();
        fail("VersionHistory should be read-only: VersionHistory.setProperty(String,Value) did not throw a ConstraintViolationException");
    } catch (ConstraintViolationException success) {
    }
    try {
        vHistory.setProperty(propertyName1, -2147483650L);
        vHistory.getSession().save();
        fail("VersionHistory should be read-only: VersionHistory.setProperty(String,long) did not throw a ConstraintViolationException");
    } catch (ConstraintViolationException success) {
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) Value(javax.jcr.Value) GregorianCalendar(java.util.GregorianCalendar) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException)

Aggregations

Value (javax.jcr.Value)600 Node (javax.jcr.Node)158 Test (org.junit.Test)118 Property (javax.jcr.Property)99 RepositoryException (javax.jcr.RepositoryException)82 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)82 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)70 Session (javax.jcr.Session)63 NodeType (javax.jcr.nodetype.NodeType)57 ValueFormatException (javax.jcr.ValueFormatException)53 ValueFactory (javax.jcr.ValueFactory)51 QValue (org.apache.jackrabbit.spi.QValue)51 HashMap (java.util.HashMap)46 ArrayList (java.util.ArrayList)31 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)30 Privilege (javax.jcr.security.Privilege)30 InputStream (java.io.InputStream)29 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)29 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)29 QValueValue (org.apache.jackrabbit.spi.commons.value.QValueValue)27