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());
}
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());
}
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());
}
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());
}
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;
}
Aggregations