Search in sources :

Example 1 with SetOSGiModel

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

the class OSGiInjectionTest method testSetOSGiModelField.

@Test
public void testSetOSGiModelField() 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);
    SetOSGiModel model = factory.getAdapter(res, SetOSGiModel.class);
    assertNull(model);
    verify(bundleContext).registerService(eq(Runnable.class.getName()), eq(factory), any(Dictionary.class));
    verify(bundleContext).addBundleListener(any(BundleListener.class));
    verify(bundleContext).registerService(eq(Object.class.getName()), any(Object.class), any(Dictionary.class));
    verify(bundleContext).getBundles();
    verify(bundleContext).getBundle();
    verifyNoMoreInteractions(res, bundleContext);
}
Also used : Dictionary(java.util.Dictionary) SetOSGiModel(org.apache.sling.models.testmodels.classes.SetOSGiModel) ServiceInterface(org.apache.sling.models.testmodels.interfaces.ServiceInterface) Resource(org.apache.sling.api.resource.Resource) BundleListener(org.osgi.framework.BundleListener) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Aggregations

Dictionary (java.util.Dictionary)1 Resource (org.apache.sling.api.resource.Resource)1 SetOSGiModel (org.apache.sling.models.testmodels.classes.SetOSGiModel)1 ServiceInterface (org.apache.sling.models.testmodels.interfaces.ServiceInterface)1 Test (org.junit.Test)1 BundleListener (org.osgi.framework.BundleListener)1 ServiceReference (org.osgi.framework.ServiceReference)1