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"));
}
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());
}
}
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();
}
}
}
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();
}
}
}
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]);
}
Aggregations