Search in sources :

Example 1 with SimplePropertyModel

use of org.apache.sling.models.testmodels.classes.SimplePropertyModel 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);
}
Also used : SimplePropertyModel(org.apache.sling.models.testmodels.classes.SimplePropertyModel) HashMap(java.util.HashMap) 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)1 Resource (org.apache.sling.api.resource.Resource)1 ValueMap (org.apache.sling.api.resource.ValueMap)1 ValueMapDecorator (org.apache.sling.api.wrappers.ValueMapDecorator)1 SimplePropertyModel (org.apache.sling.models.testmodels.classes.SimplePropertyModel)1 Test (org.junit.Test)1