Search in sources :

Example 6 with Value

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

the class WriteTest method testAutocreatedProperties.

public void testAutocreatedProperties() throws RepositoryException, NotExecutableException {
    givePrivileges(path, testUser.getPrincipal(), privilegesFromName(PrivilegeRegistry.REP_WRITE), getRestrictions(superuser, path));
    // test user is not allowed to READ the protected property jcr:created.
    Map<String, Value> restr = getRestrictions(superuser, path);
    restr.put(((SessionImpl) superuser).getJCRName(ACLTemplate.P_GLOB), superuser.getValueFactory().createValue("/afolder/jcr:created"));
    withdrawPrivileges(path, testUser.getPrincipal(), privilegesFromName(Privilege.JCR_READ), restr);
    // still: adding a nt:folder node should be possible
    Node n = getTestSession().getNode(path);
    Node folder = n.addNode("afolder", "nt:folder");
    assertFalse(folder.hasProperty("jcr:created"));
}
Also used : Node(javax.jcr.Node) Value(javax.jcr.Value)

Example 7 with Value

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

the class AuthorizableImplTest method testMembersPropertyType.

public void testMembersPropertyType() throws NotExecutableException, RepositoryException {
    GroupImpl gr = (GroupImpl) getTestGroup(superuser);
    NodeImpl n = gr.getNode();
    if (!n.hasProperty(UserConstants.P_MEMBERS)) {
        gr.addMember(getTestUser(superuser));
    }
    Property p = n.getProperty(UserConstants.P_MEMBERS);
    for (Value v : p.getValues()) {
        assertEquals(PropertyType.WEAKREFERENCE, v.getType());
    }
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) Value(javax.jcr.Value) StringValue(org.apache.jackrabbit.value.StringValue) Property(javax.jcr.Property)

Example 8 with Value

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

the class AuthorizableImplTest method testMultiValuedToSingle.

public void testMultiValuedToSingle() throws Exception {
    AuthorizableImpl user = (AuthorizableImpl) getTestUser(superuser);
    UserManager uMgr = getUserManager(superuser);
    try {
        Value v = superuser.getValueFactory().createValue("anyValue");
        Value[] vs = new Value[] { v, v };
        user.setProperty("someProp", vs);
        if (!uMgr.isAutoSave()) {
            superuser.save();
        }
        user.setProperty("someProp", v);
        if (!uMgr.isAutoSave()) {
            superuser.save();
        }
    } finally {
        if (user.removeProperty("someProp") && !uMgr.isAutoSave()) {
            superuser.save();
        }
    }
}
Also used : UserManager(org.apache.jackrabbit.api.security.user.UserManager) Value(javax.jcr.Value) StringValue(org.apache.jackrabbit.value.StringValue)

Example 9 with Value

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

the class AuthorizableImplTest method testSingleToMultiValued.

public void testSingleToMultiValued() throws Exception {
    AuthorizableImpl user = (AuthorizableImpl) getTestUser(superuser);
    UserManager uMgr = getUserManager(superuser);
    try {
        Value v = superuser.getValueFactory().createValue("anyValue");
        user.setProperty("someProp", v);
        if (!uMgr.isAutoSave()) {
            superuser.save();
        }
        Value[] vs = new Value[] { v, v };
        user.setProperty("someProp", vs);
        if (!uMgr.isAutoSave()) {
            superuser.save();
        }
    } finally {
        if (user.removeProperty("someProp") && !uMgr.isAutoSave()) {
            superuser.save();
        }
    }
}
Also used : UserManager(org.apache.jackrabbit.api.security.user.UserManager) Value(javax.jcr.Value) StringValue(org.apache.jackrabbit.value.StringValue)

Example 10 with Value

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

the class PropertyReadMethodsTest method testGetValueCopyStoredValues.

/**
     * Tests if <code>Property.getValues()</code> returns an array that is a copy
     * of the stored values, so changes to it are not reflected in internal storage.
     */
public void testGetValueCopyStoredValues() throws NotExecutableException, RepositoryException {
    Property prop = PropertyUtil.searchMultivalProp(testRootNode);
    if (prop == null) {
        throw new NotExecutableException("No multivalued property found.");
    }
    // acquire the values of the property and change the zeroth value
    Value[] values = prop.getValues();
    if (values.length == 0) {
        throw new NotExecutableException("No testable property found.");
    }
    values[0] = null;
    // re-acquire the values and check if nulled value still exists
    Value[] values2 = prop.getValues();
    assertNotNull("Changes on the array returned by Property.getValues() must " + "not be reflected in the internal storage.", values2[0]);
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Value(javax.jcr.Value) Property(javax.jcr.Property)

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