Search in sources :

Example 36 with ValueMap

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

the class JsonContentTest method testFile21aNodeDescriptor.

@Test
public void testFile21aNodeDescriptor() throws RepositoryException {
    Resource file21a = fsroot.getChild("folder2/folder21/file21a.txt");
    assertEquals("nt:file", file21a.getResourceType());
    assertEquals("/my/super/type", file21a.getResourceSuperType());
    ValueMap props = file21a.getValueMap();
    assertEquals("nt:file", props.get("jcr:primaryType", String.class));
    assertEquals("/my/super/type", props.get("sling:resourceSuperType", String.class));
    assertEquals("en", props.get("jcr:language", String.class));
    assertArrayEquals(new String[] { "mix:language" }, props.get("jcr:mixinTypes", String[].class));
    assertNull(fsroot.getChild("folder2/folder21/file21a.txt.xml"));
    Node node = file21a.adaptTo(Node.class);
    assertNotNull(node);
    assertEquals("/my/super/type", node.getProperty("sling:resourceSuperType").getString());
    assertEquals("en", node.getProperty("jcr:language").getString());
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Node(javax.jcr.Node) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 37 with ValueMap

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

the class DefaultTest method testDefaultWrappersConstructor.

@Test
public void testDefaultWrappersConstructor() {
    ValueMap vm = new ValueMapDecorator(Collections.<String, Object>emptyMap());
    Resource res = mock(Resource.class);
    when(res.adaptTo(ValueMap.class)).thenReturn(vm);
    org.apache.sling.models.testmodels.classes.constructorinjection.DefaultWrappersModel model = factory.getAdapter(res, org.apache.sling.models.testmodels.classes.constructorinjection.DefaultWrappersModel.class);
    assertNotNull(model);
    assertEquals(Boolean.valueOf(true), model.getBooleanWrapperProperty());
    // we need to wait for JUnit 4.12 for this assertArrayEquals to be working on primitive boolean arrays, https://github.com/junit-team/junit/issues/86!
    assertTrue(Arrays.equals(new Boolean[] { Boolean.TRUE, Boolean.TRUE }, model.getBooleanWrapperArrayProperty()));
    assertEquals(Long.valueOf(1L), model.getLongWrapperProperty());
    assertArrayEquals(new Long[] { Long.valueOf(1L), Long.valueOf(1L) }, model.getLongWrapperArrayProperty());
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) ValueMapDecorator(org.apache.sling.api.wrappers.ValueMapDecorator) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 38 with ValueMap

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

the class DefaultTest method testDefaultStringValueOnInterfaceField.

@Test
public void testDefaultStringValueOnInterfaceField() {
    ValueMap vm = new ValueMapDecorator(Collections.<String, Object>singletonMap("first", "first value"));
    Resource res = mock(Resource.class);
    when(res.adaptTo(ValueMap.class)).thenReturn(vm);
    PropertyModelWithDefaults model = factory.getAdapter(res, PropertyModelWithDefaults.class);
    assertNotNull(model);
    assertEquals("first value", model.getFirst());
    assertEquals("second default", model.getSecond());
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) ValueMapDecorator(org.apache.sling.api.wrappers.ValueMapDecorator) Resource(org.apache.sling.api.resource.Resource) PropertyModelWithDefaults(org.apache.sling.models.testmodels.interfaces.PropertyModelWithDefaults) Test(org.junit.Test)

Example 39 with ValueMap

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

the class DefaultTest method testDefaultPrimitivesConstructor.

@Test
public void testDefaultPrimitivesConstructor() {
    ValueMap vm = new ValueMapDecorator(Collections.<String, Object>emptyMap());
    Resource res = mock(Resource.class);
    when(res.adaptTo(ValueMap.class)).thenReturn(vm);
    org.apache.sling.models.testmodels.classes.constructorinjection.DefaultPrimitivesModel model = factory.getAdapter(res, org.apache.sling.models.testmodels.classes.constructorinjection.DefaultPrimitivesModel.class);
    assertNotNull(model);
    assertEquals(true, model.getBooleanProperty());
    // we need to wait for JUnit 4.12 for this assertArrayEquals to be working on primitive boolean arrays, https://github.com/junit-team/junit/issues/86!
    assertTrue(Arrays.equals(new boolean[] { true, true }, model.getBooleanArrayProperty()));
    assertEquals(1L, model.getLongProperty());
    assertArrayEquals(new long[] { 1L, 1L }, model.getLongArrayProperty());
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) ValueMapDecorator(org.apache.sling.api.wrappers.ValueMapDecorator) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 40 with ValueMap

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

the class ImplementsExtendsTest method getMockResourceWithProps.

private Resource getMockResourceWithProps() {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("first", "first-value");
    map.put("third", "third-value");
    ValueMap vm = new ValueMapDecorator(map);
    Resource res = mock(Resource.class);
    when(res.adaptTo(ValueMap.class)).thenReturn(vm);
    return res;
}
Also used : HashMap(java.util.HashMap) ValueMap(org.apache.sling.api.resource.ValueMap) ValueMapDecorator(org.apache.sling.api.wrappers.ValueMapDecorator) Resource(org.apache.sling.api.resource.Resource) Matchers.anyObject(org.mockito.Matchers.anyObject) Matchers.anyString(org.mockito.Matchers.anyString)

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