use of org.apache.sling.api.wrappers.ValueMapDecorator in project sling by apache.
the class ResourceModelClassesTest method testRequiredPropertyMissingModelOptionalStrategy.
@Test
public void testRequiredPropertyMissingModelOptionalStrategy() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("first", "first-value");
ValueMap vm = spy(new ValueMapDecorator(map));
Resource res = mock(Resource.class);
when(res.adaptTo(ValueMap.class)).thenReturn(vm);
ResourceModelWithRequiredFieldOptionalStrategy model = factory.getAdapter(res, ResourceModelWithRequiredFieldOptionalStrategy.class);
assertNull(model);
verify(vm).get("optional1", String.class);
verify(vm).get("required1", String.class);
}
use of org.apache.sling.api.wrappers.ValueMapDecorator in project sling by apache.
the class ResourceModelClassesTest method testRequiredPropertyModel.
@Test
public void testRequiredPropertyModel() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("first", "first-value");
map.put("third", "third-value");
ValueMap vm = spy(new ValueMapDecorator(map));
Resource res = mock(Resource.class);
when(res.adaptTo(ValueMap.class)).thenReturn(vm);
ResourceModelWithRequiredField model = factory.getAdapter(res, ResourceModelWithRequiredField.class);
assertNull(model);
verify(vm).get("required", String.class);
}
use of org.apache.sling.api.wrappers.ValueMapDecorator in project sling by apache.
the class ResourceModelClassesTest method testRequiredPropertyModelWithException.
@Test
public void testRequiredPropertyModelWithException() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("first", "first-value");
map.put("third", "third-value");
ValueMap vm = spy(new ValueMapDecorator(map));
Resource res = mock(Resource.class);
when(res.adaptTo(ValueMap.class)).thenReturn(vm);
boolean thrown = false;
try {
factory.createModel(res, ResourceModelWithRequiredField.class);
} catch (MissingElementsException e) {
assertEquals("required", ((Field) e.getMissingElements().iterator().next().getElement()).getName());
thrown = true;
}
assertTrue(thrown);
verify(vm).get("required", String.class);
}
use of org.apache.sling.api.wrappers.ValueMapDecorator in project sling by apache.
the class ViaTest method testProjectionToChildResource.
@Test
public void testProjectionToChildResource() {
String value = RandomStringUtils.randomAlphanumeric(10);
ValueMap map = new ValueMapDecorator(Collections.<String, Object>singletonMap("firstProperty", value));
when(childResource.adaptTo(ValueMap.class)).thenReturn(map);
ChildResourceViaModel model = factory.getAdapter(resource, ChildResourceViaModel.class);
assertNotNull(model);
assertEquals(value, model.getFirstProperty());
}
use of org.apache.sling.api.wrappers.ValueMapDecorator in project sling by apache.
the class ViaTest method testProjectionToResource.
@Test
public void testProjectionToResource() {
String value = RandomStringUtils.randomAlphanumeric(10);
ValueMap map = new ValueMapDecorator(Collections.<String, Object>singletonMap("firstProperty", value));
when(resource.adaptTo(ValueMap.class)).thenReturn(map);
ViaModel model = factory.getAdapter(request, ViaModel.class);
assertNotNull(model);
assertEquals(value, model.getFirstProperty());
}
Aggregations