use of org.apache.sling.models.testmodels.classes.InjectorSpecificAnnotationModel in project sling by apache.
the class InjectorSpecificAnnotationTest method testScriptVariableField.
@Test
public void testScriptVariableField() throws InvalidSyntaxException {
SlingBindings bindings = new SlingBindings();
SlingScriptHelper helper = mock(SlingScriptHelper.class);
bindings.setSling(helper);
when(request.getAttribute(SlingBindings.class.getName())).thenReturn(bindings);
InjectorSpecificAnnotationModel model = factory.getAdapter(request, InjectorSpecificAnnotationModel.class);
assertNotNull("Could not instanciate model", model);
assertEquals(helper, model.getHelper());
}
use of org.apache.sling.models.testmodels.classes.InjectorSpecificAnnotationModel in project sling by apache.
the class InjectorSpecificAnnotationTest method testOSGiServiceField.
@Test
public void testOSGiServiceField() throws InvalidSyntaxException {
ServiceReference ref = mock(ServiceReference.class);
Logger log = mock(Logger.class);
when(bundleContext.getServiceReferences(Logger.class.getName(), null)).thenReturn(new ServiceReference[] { ref });
when(bundleContext.getService(ref)).thenReturn(log);
InjectorSpecificAnnotationModel model = factory.getAdapter(request, InjectorSpecificAnnotationModel.class);
assertNotNull("Could not instanciate model", model);
assertEquals(log, model.getService());
}
use of org.apache.sling.models.testmodels.classes.InjectorSpecificAnnotationModel in project sling by apache.
the class InjectorSpecificAnnotationTest method testRequestAttributeField.
@Test
public void testRequestAttributeField() throws InvalidSyntaxException {
Object attribute = new Object();
when(request.getAttribute("attribute")).thenReturn(attribute);
InjectorSpecificAnnotationModel model = factory.getAdapter(request, InjectorSpecificAnnotationModel.class);
assertNotNull("Could not instanciate model", model);
assertEquals(attribute, model.getRequestAttribute());
}
use of org.apache.sling.models.testmodels.classes.InjectorSpecificAnnotationModel 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.models.testmodels.classes.InjectorSpecificAnnotationModel in project sling by apache.
the class InjectorSpecificAnnotationTest method testChildResourceField.
@Test
public void testChildResourceField() {
Resource res = mock(Resource.class);
Resource child = mock(Resource.class);
when(res.getChild("child1")).thenReturn(child);
when(request.getResource()).thenReturn(res);
InjectorSpecificAnnotationModel model = factory.getAdapter(request, InjectorSpecificAnnotationModel.class);
assertNotNull("Could not instanciate model", model);
assertEquals(child, model.getChildResource());
}
Aggregations