Search in sources :

Example 81 with ValueMap

use of org.apache.sling.api.resource.ValueMap in project sling by apache.

the class AbstractContentLoaderJsonTest method testContentProperties.

@Test
public void testContentProperties() {
    Resource resource = context.resourceResolver().getResource(path + "/sample/en/jcr:content/header");
    ValueMap props = ResourceUtil.getValueMap(resource);
    assertEquals("/content/dam/sample/header.png", props.get("imageReference", String.class));
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 82 with ValueMap

use of org.apache.sling.api.resource.ValueMap in project sling by apache.

the class SlingCrudResourceResolverTest method testStringToCalendarConversion.

@Test
public void testStringToCalendarConversion() throws IOException {
    Resource resource1 = resourceResolver.getResource(testRoot.getPath() + "/node1");
    ModifiableValueMap modProps = resource1.adaptTo(ModifiableValueMap.class);
    modProps.put("dateISO8601String", ISO8601.format(CALENDAR_VALUE));
    resourceResolver.commit();
    resource1 = resourceResolver.getResource(testRoot.getPath() + "/node1");
    ValueMap props = ResourceUtil.getValueMap(resource1);
    assertEquals(CALENDAR_VALUE.getTime(), props.get("calendarProp", Calendar.class).getTime());
}
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) ModifiableValueMap(org.apache.sling.api.resource.ModifiableValueMap) Test(org.junit.Test)

Example 83 with ValueMap

use of org.apache.sling.api.resource.ValueMap in project sling by apache.

the class SlingCrudResourceResolverTest method testSimpleProperties_DeepPathAccess.

@Test
public void testSimpleProperties_DeepPathAccess() throws IOException {
    Resource resource1 = resourceResolver.getResource(testRoot.getPath());
    assertNotNull(resource1);
    assertEquals(testRoot.getName(), resource1.getName());
    ValueMap props = ResourceUtil.getValueMap(resource1);
    assertEquals(STRING_VALUE, props.get("node1/stringProp", String.class));
    assertArrayEquals(STRING_ARRAY_VALUE, props.get("node1/stringArrayProp", String[].class));
    assertEquals((Integer) INTEGER_VALUE, props.get("node1/integerProp", Integer.class));
    assertEquals((Long) LONG_VALUE, props.get("node1/longProp", Long.class));
    assertEquals(DOUBLE_VALUE, props.get("node1/doubleProp", Double.class), 0.0001);
    assertEquals(BIGDECIMAL_VALUE, props.get("node1/bigDecimalProp", BigDecimal.class));
    assertEquals(BOOLEAN_VALUE, props.get("node1/booleanProp", Boolean.class));
    assertEquals(STRING_VALUE, props.get("node1/node11/stringProp11", String.class));
    assertTrue(STRING_VALUE, props.containsKey("node1/stringProp"));
    assertFalse(STRING_VALUE, props.containsKey("node1/unknownProp"));
}
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 84 with ValueMap

use of org.apache.sling.api.resource.ValueMap in project sling by apache.

the class SlingCrudResourceResolverTest method testDateProperty.

@Test
public void testDateProperty() throws IOException {
    Resource resource1 = resourceResolver.getResource(testRoot.getPath() + "/node1");
    ValueMap props = ResourceUtil.getValueMap(resource1);
    assertEquals(DATE_VALUE, props.get("dateProp", Date.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) Date(java.util.Date) Test(org.junit.Test)

Example 85 with ValueMap

use of org.apache.sling.api.resource.ValueMap in project sling by apache.

the class SlingCrudResourceResolverTest method testDatePropertyToCalendar.

@Test
public void testDatePropertyToCalendar() throws IOException {
    Resource resource1 = resourceResolver.getResource(testRoot.getPath() + "/node1");
    ValueMap props = ResourceUtil.getValueMap(resource1);
    Calendar calendarValue = props.get("dateProp", Calendar.class);
    assertNotNull(calendarValue);
    assertEquals(DATE_VALUE, calendarValue.getTime());
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) ModifiableValueMap(org.apache.sling.api.resource.ModifiableValueMap) Calendar(java.util.Calendar) NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Resource(org.apache.sling.api.resource.Resource) 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