use of org.apache.sling.api.resource.ValueMap 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());
}
use of org.apache.sling.api.resource.ValueMap 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.resource.ValueMap in project sling by apache.
the class OptionalPrimitivesTest method testFieldInjectionInterface.
@Test
public void testFieldInjectionInterface() {
ValueMap vm = ValueMap.EMPTY;
Resource res = mock(Resource.class);
when(res.adaptTo(ValueMap.class)).thenReturn(vm);
org.apache.sling.models.testmodels.interfaces.OptionalPrimitivesModel model = factory.getAdapter(res, org.apache.sling.models.testmodels.interfaces.OptionalPrimitivesModel.class);
assertNotNull(model);
// make sure primitives are initialized with initial value
assertEquals(0, model.getByteValue());
assertEquals(0, model.getShortValue());
assertEquals(0, model.getIntValue());
assertEquals(0L, model.getLongValue());
assertEquals(0.0f, model.getFloatValue(), 0.00001d);
assertEquals(0.0d, model.getDoubleValue(), 0.00001d);
assertEquals('