Search in sources :

Example 1 with InjectorSpecificAnnotationModel

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());
}
Also used : InjectorSpecificAnnotationModel(org.apache.sling.models.testmodels.classes.InjectorSpecificAnnotationModel) SlingBindings(org.apache.sling.api.scripting.SlingBindings) SlingScriptHelper(org.apache.sling.api.scripting.SlingScriptHelper) Test(org.junit.Test)

Example 2 with InjectorSpecificAnnotationModel

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());
}
Also used : InjectorSpecificAnnotationModel(org.apache.sling.models.testmodels.classes.InjectorSpecificAnnotationModel) Logger(org.slf4j.Logger) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 3 with InjectorSpecificAnnotationModel

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());
}
Also used : InjectorSpecificAnnotationModel(org.apache.sling.models.testmodels.classes.InjectorSpecificAnnotationModel) Test(org.junit.Test)

Example 4 with InjectorSpecificAnnotationModel

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());
}
Also used : InjectorSpecificAnnotationModel(org.apache.sling.models.testmodels.classes.InjectorSpecificAnnotationModel) 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) Logger(org.slf4j.Logger) Test(org.junit.Test)

Example 5 with InjectorSpecificAnnotationModel

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());
}
Also used : InjectorSpecificAnnotationModel(org.apache.sling.models.testmodels.classes.InjectorSpecificAnnotationModel) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Aggregations

InjectorSpecificAnnotationModel (org.apache.sling.models.testmodels.classes.InjectorSpecificAnnotationModel)6 Test (org.junit.Test)6 Resource (org.apache.sling.api.resource.Resource)3 HashMap (java.util.HashMap)2 ValueMap (org.apache.sling.api.resource.ValueMap)2 ValueMapDecorator (org.apache.sling.api.wrappers.ValueMapDecorator)2 Logger (org.slf4j.Logger)2 SlingBindings (org.apache.sling.api.scripting.SlingBindings)1 SlingScriptHelper (org.apache.sling.api.scripting.SlingScriptHelper)1 ServiceReference (org.osgi.framework.ServiceReference)1