use of org.apache.sling.api.resource.ValueMap in project sling by apache.
the class SlingCrudResourceResolverTest method testSimpleProperties.
@Test
public void testSimpleProperties() throws IOException {
Resource resource1 = resourceResolver.getResource(testRoot.getPath() + "/node1");
assertNotNull(resource1);
assertEquals("node1", resource1.getName());
ValueMap props = ResourceUtil.getValueMap(resource1);
assertEquals(STRING_VALUE, props.get("stringProp", String.class));
assertArrayEquals(STRING_ARRAY_VALUE, props.get("stringArrayProp", String[].class));
assertEquals((Integer) INTEGER_VALUE, props.get("integerProp", Integer.class));
assertEquals((Long) LONG_VALUE, props.get("longProp", Long.class));
assertEquals(DOUBLE_VALUE, props.get("doubleProp", Double.class), 0.0001);
assertEquals(BIGDECIMAL_VALUE, props.get("bigDecimalProp", BigDecimal.class));
assertEquals(BOOLEAN_VALUE, props.get("booleanProp", Boolean.class));
}
use of org.apache.sling.api.resource.ValueMap in project sling by apache.
the class SlingCrudResourceResolverTest method testSimpleProperties_DecimalConversion.
@Test
public void testSimpleProperties_DecimalConversion() throws IOException {
Resource resource1 = resourceResolver.getResource(testRoot.getPath() + "/node1");
ValueMap props = ResourceUtil.getValueMap(resource1);
assertEquals(new BigDecimal(DOUBLE_VALUE).doubleValue(), props.get("doubleProp", BigDecimal.class).doubleValue(), 0.0001d);
assertEquals(BIGDECIMAL_VALUE.doubleValue(), props.get("bigDecimalProp", Double.class), 0.0001d);
}
use of org.apache.sling.api.resource.ValueMap in project sling by apache.
the class ResourceCollectionImpl method getResources.
/**
* {@inheritDoc}
*/
public Iterator<Resource> getResources() {
ValueMap vm = membersResource.adaptTo(ValueMap.class);
String[] references = vm.get(ResourceCollectionConstants.REFERENCES_PROP, new String[] {});
List<Resource> resources = new ArrayList<Resource>();
for (String path : references) {
Resource resource = resolver.getResource(path);
if (resource != null) {
resources.add(resource);
}
}
return resources.iterator();
}
use of org.apache.sling.api.resource.ValueMap in project sling by apache.
the class WritePipeTest method testVariablePiped.
@Test
public void testVariablePiped() throws Exception {
Iterator<Resource> it = getOutput(PATH_PIPE + "/" + NN_VARIABLE_PIPED);
Resource resource = it.next();
assertEquals("path should be the one configured in first pipe", PATH_PIPE + "/" + NN_VARIABLE_PIPED + "/conf/fruit/conf/apple", resource.getPath());
context.resourceResolver().commit();
ValueMap properties = resource.adaptTo(ValueMap.class);
assertEquals("Configured value should be written", "apple is a fruit and its color is green", properties.get("jcr:description", ""));
assertEquals("Worm has been removed", "", properties.get("worm", ""));
Resource archive = resource.getChild("archive/wasthereworm");
assertNotNull("there is an archive of the worm value", archive);
assertEquals("Worm value has been written at the same time", "true", archive.adaptTo(String.class));
}
use of org.apache.sling.api.resource.ValueMap in project sling by apache.
the class PlumberServletTest method testDryRun.
@Test
public void testDryRun() throws Exception {
SlingHttpServletRequest dryRunRequest = mockPlumberServletRequest(context.resourceResolver(), pipedWritePath, null, null, null, "true", null);
servlet.execute(dryRunRequest, response, true);
Resource resource = context.resourceResolver().getResource("/content/fruits");
ValueMap properties = resource.adaptTo(ValueMap.class);
assertFalse("property fruits shouldn't have been written", properties.containsKey("fruits"));
SlingHttpServletRequest request = mockPlumberServletRequest(context.resourceResolver(), pipedWritePath, null, null, null, "false", null);
servlet.execute(request, response, true);
WritePipeTest.assertPiped(resource);
}
Aggregations