use of org.apache.sling.api.wrappers.ValueMapDecorator in project sling by apache.
the class DefaultTest method testDefaultWrappersConstructor.
@Test
public void testDefaultWrappersConstructor() {
ValueMap vm = new ValueMapDecorator(Collections.<String, Object>emptyMap());
Resource res = mock(Resource.class);
when(res.adaptTo(ValueMap.class)).thenReturn(vm);
org.apache.sling.models.testmodels.classes.constructorinjection.DefaultWrappersModel model = factory.getAdapter(res, org.apache.sling.models.testmodels.classes.constructorinjection.DefaultWrappersModel.class);
assertNotNull(model);
assertEquals(Boolean.valueOf(true), model.getBooleanWrapperProperty());
// we need to wait for JUnit 4.12 for this assertArrayEquals to be working on primitive boolean arrays, https://github.com/junit-team/junit/issues/86!
assertTrue(Arrays.equals(new Boolean[] { Boolean.TRUE, Boolean.TRUE }, model.getBooleanWrapperArrayProperty()));
assertEquals(Long.valueOf(1L), model.getLongWrapperProperty());
assertArrayEquals(new Long[] { Long.valueOf(1L), Long.valueOf(1L) }, model.getLongWrapperArrayProperty());
}
use of org.apache.sling.api.wrappers.ValueMapDecorator in project sling by apache.
the class DefaultTest method testDefaultStringValueOnInterfaceField.
@Test
public void testDefaultStringValueOnInterfaceField() {
ValueMap vm = new ValueMapDecorator(Collections.<String, Object>singletonMap("first", "first value"));
Resource res = mock(Resource.class);
when(res.adaptTo(ValueMap.class)).thenReturn(vm);
PropertyModelWithDefaults model = factory.getAdapter(res, PropertyModelWithDefaults.class);
assertNotNull(model);
assertEquals("first value", model.getFirst());
assertEquals("second default", model.getSecond());
}
use of org.apache.sling.api.wrappers.ValueMapDecorator in project sling by apache.
the class DefaultTest method testDefaultPrimitivesConstructor.
@Test
public void testDefaultPrimitivesConstructor() {
ValueMap vm = new ValueMapDecorator(Collections.<String, Object>emptyMap());
Resource res = mock(Resource.class);
when(res.adaptTo(ValueMap.class)).thenReturn(vm);
org.apache.sling.models.testmodels.classes.constructorinjection.DefaultPrimitivesModel model = factory.getAdapter(res, org.apache.sling.models.testmodels.classes.constructorinjection.DefaultPrimitivesModel.class);
assertNotNull(model);
assertEquals(true, model.getBooleanProperty());
// we need to wait for JUnit 4.12 for this assertArrayEquals to be working on primitive boolean arrays, https://github.com/junit-team/junit/issues/86!
assertTrue(Arrays.equals(new boolean[] { true, true }, model.getBooleanArrayProperty()));
assertEquals(1L, model.getLongProperty());
assertArrayEquals(new long[] { 1L, 1L }, model.getLongArrayProperty());
}
use of org.apache.sling.api.wrappers.ValueMapDecorator in project sling by apache.
the class ImplementsExtendsTest method getMockResourceWithProps.
private Resource getMockResourceWithProps() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("first", "first-value");
map.put("third", "third-value");
ValueMap vm = new ValueMapDecorator(map);
Resource res = mock(Resource.class);
when(res.adaptTo(ValueMap.class)).thenReturn(vm);
return res;
}
use of org.apache.sling.api.wrappers.ValueMapDecorator in project sling by apache.
the class InjectorSpecificAnnotationTest method testOrderForValueAnnotationField.
@Test
public void testOrderForValueAnnotationField() {
// make sure that that the correct injection is used
// make sure that log is adapted from value map
// and not coming from request attribute
Logger logFromValueMap = LoggerFactory.getLogger(this.getClass());
Map<String, Object> map = new HashMap<String, Object>();
map.put("first", "first-value");
map.put("log", logFromValueMap);
ValueMap vm = new ValueMapDecorator(map);
Resource res = mock(Resource.class);
when(res.adaptTo(ValueMap.class)).thenReturn(vm);
when(request.getResource()).thenReturn(res);
InjectorSpecificAnnotationModel model = factory.getAdapter(request, InjectorSpecificAnnotationModel.class);
assertNotNull("Could not instanciate model", model);
assertEquals("first-value", model.getFirst());
assertEquals(logFromValueMap, model.getLog());
}
Aggregations