Search in sources :

Example 1 with SimpleOSGiModel

use of org.apache.sling.models.testmodels.classes.SimpleOSGiModel in project sling by apache.

the class OSGiInjectionTest method testSimpleOSGiModelField.

@Test
public void testSimpleOSGiModelField() throws Exception {
    ServiceReference ref = mock(ServiceReference.class);
    ServiceInterface service = mock(ServiceInterface.class);
    when(bundleContext.getServiceReferences(ServiceInterface.class.getName(), null)).thenReturn(new ServiceReference[] { ref });
    when(bundleContext.getService(ref)).thenReturn(service);
    Resource res = mock(Resource.class);
    SimpleOSGiModel model = factory.getAdapter(res, SimpleOSGiModel.class);
    assertNotNull(model);
    assertNotNull(model.getService());
    assertEquals(service, model.getService());
    verifyNoMoreInteractions(res);
}
Also used : ServiceInterface(org.apache.sling.models.testmodels.interfaces.ServiceInterface) Resource(org.apache.sling.api.resource.Resource) SimpleOSGiModel(org.apache.sling.models.testmodels.classes.SimpleOSGiModel) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Aggregations

Resource (org.apache.sling.api.resource.Resource)1 SimpleOSGiModel (org.apache.sling.models.testmodels.classes.SimpleOSGiModel)1 ServiceInterface (org.apache.sling.models.testmodels.interfaces.ServiceInterface)1 Test (org.junit.Test)1 ServiceReference (org.osgi.framework.ServiceReference)1