Search in sources :

Example 86 with ValueMap

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));
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) ModifiableValueMap(org.apache.sling.api.resource.ModifiableValueMap) NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Resource(org.apache.sling.api.resource.Resource) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 87 with ValueMap

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);
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) ModifiableValueMap(org.apache.sling.api.resource.ModifiableValueMap) NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Resource(org.apache.sling.api.resource.Resource) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 88 with ValueMap

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();
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) ModifiableValueMap(org.apache.sling.api.resource.ModifiableValueMap) ArrayList(java.util.ArrayList) Resource(org.apache.sling.api.resource.Resource)

Example 89 with ValueMap

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));
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) AbstractPipeTest(org.apache.sling.pipes.AbstractPipeTest) Test(org.junit.Test)

Example 90 with ValueMap

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);
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest) AbstractPipeTest(org.apache.sling.pipes.AbstractPipeTest) ContainerPipeTest(org.apache.sling.pipes.ContainerPipeTest) Test(org.junit.Test)

Aggregations

ValueMap (org.apache.sling.api.resource.ValueMap)278 Resource (org.apache.sling.api.resource.Resource)205 Test (org.junit.Test)160 ModifiableValueMap (org.apache.sling.api.resource.ModifiableValueMap)59 HashMap (java.util.HashMap)54 ValueMapDecorator (org.apache.sling.api.wrappers.ValueMapDecorator)44 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)26 Map (java.util.Map)21 SlingHttpServletResponse (org.apache.sling.api.SlingHttpServletResponse)21 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)20 RewriterResponse (org.apache.sling.security.impl.ContentDispositionFilter.RewriterResponse)20 Expectations (org.jmock.Expectations)20 ArrayList (java.util.ArrayList)18 PersistenceException (org.apache.sling.api.resource.PersistenceException)17 Calendar (java.util.Calendar)16 Date (java.util.Date)15 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15 NonExistingResource (org.apache.sling.api.resource.NonExistingResource)12 InputStream (java.io.InputStream)11 Node (javax.jcr.Node)11