use of org.apache.sling.api.resource.ModifiableValueMap in project sling by apache.
the class ResourceAccessSecurityImplTests method testCannotUpdateUsingReadableResourceIfCannotRead.
@Test
public void testCannotUpdateUsingReadableResourceIfCannotRead() {
initMocks("/content", new String[] { "read", "update" });
Resource resource = mock(Resource.class);
when(resource.getPath()).thenReturn("/content");
ModifiableValueMap valueMap = mock(ModifiableValueMap.class);
when(resource.adaptTo(ModifiableValueMap.class)).thenReturn(valueMap);
when(resourceAccessGate.canRead(resource)).thenReturn(ResourceAccessGate.GateResult.DENIED);
when(resourceAccessGate.canUpdate(resource)).thenReturn(ResourceAccessGate.GateResult.GRANTED);
Resource readableResource = resourceAccessSecurity.getReadableResource(resource);
assertNull(readableResource);
}
use of org.apache.sling.api.resource.ModifiableValueMap in project sling by apache.
the class JcrModifiableValueMapTest method testSerializable.
public void testSerializable() throws Exception {
this.rootNode.getSession().refresh(false);
final ModifiableValueMap pvm = new JcrModifiableValueMap(this.rootNode, getHelperData());
assertContains(pvm, initialSet());
assertNull(pvm.get("something"));
// now put a serializable object
final List<String> strings = new ArrayList<String>();
strings.add("a");
strings.add("b");
pvm.put("something", strings);
// check if we get the list again
@SuppressWarnings("unchecked") final List<String> strings2 = (List<String>) pvm.get("something");
assertEquals(strings, strings2);
getSession().save();
final ModifiableValueMap pvm2 = new JcrModifiableValueMap(this.rootNode, getHelperData());
// check if we get the list again
@SuppressWarnings("unchecked") final List<String> strings3 = (List<String>) pvm2.get("something", Serializable.class);
assertEquals(strings, strings3);
}
use of org.apache.sling.api.resource.ModifiableValueMap in project sling by apache.
the class JcrModifiableValueMapTest method testMixins.
public void testMixins() throws Exception {
this.rootNode.getSession().refresh(false);
final Node testNode = this.rootNode.addNode("testMixins" + System.currentTimeMillis());
testNode.getSession().save();
final ModifiableValueMap pvm = new JcrModifiableValueMap(testNode, getHelperData());
final String[] types = pvm.get("jcr:mixinTypes", String[].class);
final Set<String> exNodeTypes = getMixinNodeTypes(testNode);
assertEquals(exNodeTypes.size(), (types == null ? 0 : types.length));
if (types != null) {
for (final String name : types) {
assertTrue(exNodeTypes.contains(name));
}
String[] newTypes = new String[types.length + 1];
System.arraycopy(types, 0, newTypes, 0, types.length);
newTypes[types.length] = "mix:referenceable";
pvm.put("jcr:mixinTypes", newTypes);
} else {
pvm.put("jcr:mixinTypes", "mix:referenceable");
}
getSession().save();
final Set<String> newNodeTypes = getMixinNodeTypes(testNode);
assertEquals(newNodeTypes.size(), exNodeTypes.size() + 1);
}
use of org.apache.sling.api.resource.ModifiableValueMap in project sling by apache.
the class JcrModifiableValueMapTest method testRemove.
public void testRemove() throws Exception {
getSession().refresh(false);
final ModifiableValueMap pvm = new JcrModifiableValueMap(this.rootNode, getHelperData());
final String key = "removeMe";
final Long longValue = 5L;
pvm.put(key, longValue);
final Object removedValue = pvm.remove(key);
assertTrue(removedValue instanceof Long);
assertTrue(removedValue == longValue);
assertFalse(pvm.containsKey(key));
}
use of org.apache.sling.api.resource.ModifiableValueMap in project sling by apache.
the class DefaultConfigurationPersistenceStrategy method replaceProperties.
private void replaceProperties(Resource resource, Map<String, Object> properties) {
if (log.isTraceEnabled()) {
log.trace("! Store properties for resource {}: {}", resource.getPath(), MapUtil.traceOutput(properties));
}
ModifiableValueMap modValueMap = resource.adaptTo(ModifiableValueMap.class);
if (modValueMap == null) {
throw new ConfigurationPersistenceAccessDeniedException("No write access: Unable to store configuration data to " + resource.getPath() + ".");
}
// remove all existing properties that are not filterd
Set<String> propertyNamesToRemove = new HashSet<>(modValueMap.keySet());
PropertiesFilterUtil.removeIgnoredProperties(propertyNamesToRemove, configurationManagementSettings);
for (String propertyName : propertyNamesToRemove) {
modValueMap.remove(propertyName);
}
modValueMap.putAll(properties);
}
Aggregations