use of org.apache.sling.api.wrappers.ValueMapDecorator in project sling by apache.
the class InvalidAdaptationsTest method testWrongAdaptableClassException.
@Test(expected = InvalidAdaptableException.class)
public void testWrongAdaptableClassException() {
Map<String, Object> emptyMap = Collections.<String, Object>emptyMap();
Resource res = mock(Resource.class);
when(res.adaptTo(ValueMap.class)).thenReturn(new ValueMapDecorator(emptyMap));
assertNull(factory.createModel(res, RequestModel.class));
}
use of org.apache.sling.api.wrappers.ValueMapDecorator in project sling by apache.
the class InvalidAdaptationsTest method testNonModelClassException.
@Test(expected = ModelClassException.class)
public void testNonModelClassException() {
Map<String, Object> emptyMap = Collections.<String, Object>emptyMap();
Resource res = mock(Resource.class);
when(res.adaptTo(ValueMap.class)).thenReturn(new ValueMapDecorator(emptyMap));
assertNull(factory.createModel(res, NonModel.class));
}
use of org.apache.sling.api.wrappers.ValueMapDecorator in project sling by apache.
the class AdapterFactoryTest method testCreatedNestedModelWithMissingElements.
@Test(expected = MissingElementsException.class)
public void testCreatedNestedModelWithMissingElements() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("invalid", "required");
ValueMap vm = new ValueMapDecorator(map);
when(resource.adaptTo(ValueMap.class)).thenReturn(vm);
factory.createModel(resource, NestedModel.class);
}
use of org.apache.sling.api.wrappers.ValueMapDecorator in project sling by apache.
the class ResourceModelClassesTest method testRequiredPropertyModelOptionalStrategy.
@Test
public void testRequiredPropertyModelOptionalStrategy() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("required1", "required value");
map.put("required2", "required value");
map.put("required3", "required 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);
assertNotNull(model);
assertEquals("required value", model.getRequired1());
assertEquals("required value", model.getRequired2());
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 testSimplePropertyModel.
@Test
public void testSimplePropertyModel() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("first", "first-value");
map.put("third", "third-value");
map.put("intProperty", new Integer(3));
map.put("arrayProperty", new String[] { "three", "four" });
ValueMap vm = new ValueMapDecorator(map);
Resource res = mock(Resource.class);
when(res.adaptTo(ValueMap.class)).thenReturn(vm);
SimplePropertyModel model = factory.getAdapter(res, SimplePropertyModel.class);
assertNotNull(model);
assertEquals("first-value", model.getFirst());
assertNull(model.getSecond());
assertEquals("third-value", model.getThirdProperty());
assertEquals(3, model.getIntProperty());
String[] array = model.getArrayProperty();
assertEquals(2, array.length);
assertEquals("three", array[0]);
assertTrue(model.isPostConstructCalled());
verify(res, times(1)).adaptTo(ValueMap.class);
}
Aggregations