use of org.apache.sling.models.testmodels.classes.ResourceModelWithRequiredFieldOptionalStrategy 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.models.testmodels.classes.ResourceModelWithRequiredFieldOptionalStrategy 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);
}
Aggregations