Search in sources :

Example 1 with CollectionOSGiModel

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

the class OSGiInjectionTest method testCollectionOSGiModelField.

@Test
public void testCollectionOSGiModelField() 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);
    CollectionOSGiModel model = factory.getAdapter(res, CollectionOSGiModel.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);
}
Also used : ServiceInterface(org.apache.sling.models.testmodels.interfaces.ServiceInterface) Resource(org.apache.sling.api.resource.Resource) CollectionOSGiModel(org.apache.sling.models.testmodels.classes.CollectionOSGiModel) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Aggregations

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