Search in sources :

Example 1 with ResourceModelWithRequiredField

use of org.apache.sling.models.testmodels.classes.ResourceModelWithRequiredField in project sling by apache.

the class ResourceModelInterfacesTest 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);
}
Also used : HashMap(java.util.HashMap) ResourceModelWithRequiredField(org.apache.sling.models.testmodels.classes.ResourceModelWithRequiredField) 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 2 with ResourceModelWithRequiredField

use of org.apache.sling.models.testmodels.classes.ResourceModelWithRequiredField 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);
}
Also used : HashMap(java.util.HashMap) ResourceModelWithRequiredField(org.apache.sling.models.testmodels.classes.ResourceModelWithRequiredField) 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)

Aggregations

HashMap (java.util.HashMap)2 Resource (org.apache.sling.api.resource.Resource)2 ValueMap (org.apache.sling.api.resource.ValueMap)2 ValueMapDecorator (org.apache.sling.api.wrappers.ValueMapDecorator)2 ResourceModelWithRequiredField (org.apache.sling.models.testmodels.classes.ResourceModelWithRequiredField)2 Test (org.junit.Test)2