Search in sources :

Example 76 with ValueMap

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

the class ValueMapTest method testModifiableValueMap.

@Test
public void testModifiableValueMap() throws IOException {
    Resource resource1 = resourceResolver.getResource(testRoot.getPath() + "/node1");
    ValueMap map = resource1.adaptTo(ModifiableValueMap.class);
    assertTrue(map instanceof ValueMap && map instanceof ModifiableValueMap);
    assertEquals("value1", map.get("prop1"));
    map.put("prop1", "value2");
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) ModifiableValueMap(org.apache.sling.api.resource.ModifiableValueMap) Resource(org.apache.sling.api.resource.Resource) ModifiableValueMap(org.apache.sling.api.resource.ModifiableValueMap) Test(org.junit.Test)

Example 77 with ValueMap

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

the class ValueMapTest method testValueMapMap_Readonly.

@Test(expected = UnsupportedOperationException.class)
public void testValueMapMap_Readonly() throws IOException {
    Resource resource1 = resourceResolver.getResource(testRoot.getPath() + "/node1");
    ValueMap map = resource1.adaptTo(ValueMap.class);
    map.put("prop1", "value2");
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) ModifiableValueMap(org.apache.sling.api.resource.ModifiableValueMap) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 78 with ValueMap

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

the class ValueMapTest method testMap.

@SuppressWarnings("unchecked")
@Test
public void testMap() throws IOException {
    Resource resource1 = resourceResolver.getResource(testRoot.getPath() + "/node1");
    Map<String, Object> map = resource1.adaptTo(Map.class);
    assertTrue(map instanceof ValueMap && !(map instanceof ModifiableValueMap));
    assertEquals("value1", map.get("prop1"));
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) ModifiableValueMap(org.apache.sling.api.resource.ModifiableValueMap) Resource(org.apache.sling.api.resource.Resource) ModifiableValueMap(org.apache.sling.api.resource.ModifiableValueMap) Test(org.junit.Test)

Example 79 with ValueMap

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

the class ValueMapTest method testValueMap.

@Test
public void testValueMap() throws IOException {
    Resource resource1 = resourceResolver.getResource(testRoot.getPath() + "/node1");
    ValueMap map = resource1.adaptTo(ValueMap.class);
    assertTrue(map instanceof ValueMap && !(map instanceof ModifiableValueMap));
    assertEquals("value1", map.get("prop1"));
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) ModifiableValueMap(org.apache.sling.api.resource.ModifiableValueMap) Resource(org.apache.sling.api.resource.Resource) ModifiableValueMap(org.apache.sling.api.resource.ModifiableValueMap) Test(org.junit.Test)

Example 80 with ValueMap

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

the class ContentBuilderTest method testResourceWithProperties_ObjectArray.

@Test
public void testResourceWithProperties_ObjectArray() {
    Resource resource = context.create().resource("/content/test1/resource2", "jcr:title", "Test Title", "stringProp", "value1");
    assertNotNull(resource);
    assertEquals("resource2", resource.getName());
    ValueMap props = ResourceUtil.getValueMap(resource);
    assertEquals("Test Title", props.get("jcr:title", String.class));
    assertEquals("value1", props.get("stringProp", String.class));
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) 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