use of org.apache.sling.models.testmodels.interfaces.ServiceInterface 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);
}
use of org.apache.sling.models.testmodels.interfaces.ServiceInterface in project sling by apache.
the class OSGiInjectionTest method testListOSGiModelConstructor.
@Test
public void testListOSGiModelConstructor() throws Exception {
ServiceReference ref1 = mock(ServiceReference.class);
ServiceInterface service1 = mock(ServiceInterface.class);
when(bundleContext.getService(ref1)).thenReturn(service1);
ServiceReference ref2 = mock(ServiceReference.class);
ServiceInterface service2 = mock(ServiceInterface.class);
when(bundleContext.getService(ref2)).thenReturn(service2);
when(bundleContext.getServiceReferences(ServiceInterface.class.getName(), null)).thenReturn(new ServiceReference[] { ref1, ref2 });
Resource res = mock(Resource.class);
org.apache.sling.models.testmodels.classes.constructorinjection.ListOSGiModel model = factory.getAdapter(res, org.apache.sling.models.testmodels.classes.constructorinjection.ListOSGiModel.class);
assertNotNull(model);
assertNotNull(model.getServices());
// the order on those is non deterministic as the ServiceReference.compareTo() is always returning 0
// the real order is tested in the IT
assertThat(model.getServices(), Matchers.containsInAnyOrder(service1, service2));
verifyNoMoreInteractions(res);
}
Aggregations