use of org.apache.aries.mytest.MySPI2 in project aries by apache.
the class ProviderBundleTrackerCustomizerGenericCapabilityTest method testMultipleServiceInstancesAndTypes.
@Test
public void testMultipleServiceInstancesAndTypes() throws Exception {
Bundle mediatorBundle = EasyMock.createMock(Bundle.class);
EasyMock.expect(mediatorBundle.getBundleId()).andReturn(42l).anyTimes();
EasyMock.replay(mediatorBundle);
BaseActivator activator = new BaseActivator() {
@Override
public void start(BundleContext context) throws Exception {
}
};
ProviderBundleTrackerCustomizer customizer = new ProviderBundleTrackerCustomizer(activator, mediatorBundle);
BundleContext implBC = mockSPIBundleContext4();
Dictionary<String, String> headers = new Hashtable<String, String>();
headers.put(SpiFlyConstants.REQUIRE_CAPABILITY, SpiFlyConstants.PROVIDER_REQUIREMENT);
headers.put(SpiFlyConstants.PROVIDE_CAPABILITY, SpiFlyConstants.SERVICELOADER_CAPABILITY_NAMESPACE + "; " + SpiFlyConstants.SERVICELOADER_CAPABILITY_NAMESPACE + "=org.apache.aries.mytest.MySPI," + SpiFlyConstants.SERVICELOADER_CAPABILITY_NAMESPACE + "; " + SpiFlyConstants.SERVICELOADER_CAPABILITY_NAMESPACE + "=org.apache.aries.mytest.MySPI2");
Bundle implBundle = mockSPIBundle4(implBC, headers);
List<ServiceRegistration> registrations = customizer.addingBundle(implBundle, null);
assertEquals(3, registrations.size());
boolean foundA = false, foundB = false, foundC = false;
for (ServiceRegistration sreg : registrations) {
ServiceReference sref = sreg.getReference();
String objectClassName = ((String[]) sref.getProperty(Constants.OBJECTCLASS))[0];
String serviceImplClassName = (String) sref.getProperty(SpiFlyConstants.PROVIDER_IMPLCLASS_PROPERTY);
if (MySPIImpl4a.class.getName().equals(serviceImplClassName)) {
assertEquals("org.apache.aries.mytest.MySPI", objectClassName);
MySPI svc = (MySPI) implBC.getService(sreg.getReference());
assertEquals("impl4a", svc.someMethod(""));
foundA = true;
} else if (MySPIImpl4b.class.getName().equals(serviceImplClassName)) {
assertEquals("org.apache.aries.mytest.MySPI2", objectClassName);
MySPI2 svc = (MySPI2) implBC.getService(sreg.getReference());
assertEquals("impl4b", svc.someMethod(""));
foundB = true;
} else if (MySPIImpl4c.class.getName().equals(serviceImplClassName)) {
assertEquals("org.apache.aries.mytest.MySPI2", objectClassName);
MySPI2 svc = (MySPI2) implBC.getService(sreg.getReference());
assertEquals("impl4c", svc.someMethod(""));
foundC = true;
}
}
assertTrue(foundA);
assertTrue(foundB);
assertTrue(foundC);
}
Aggregations