use of org.apache.aries.mytest.MySPI 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);
}
use of org.apache.aries.mytest.MySPI in project aries by apache.
the class TestClient method test.
public Set<String> test(String input) {
Set<String> results = new HashSet<String>();
ServiceLoader<MySPI> loader = ServiceLoader.load(MySPI.class);
for (MySPI mySPI : loader) {
results.add(mySPI.someMethod(input));
}
return results;
}
use of org.apache.aries.mytest.MySPI in project aries by apache.
the class UnaffectedTestClient method test.
public String test(String input) {
StringBuilder sb = new StringBuilder();
ServiceLoader<MySPI> loader = ServiceLoader.load(MySPI.class, new ClientWeavingHookTest.TestProviderBundleClassLoader("impl4", "META-INF/services/org.apache.aries.mytest.MySPI"));
for (MySPI mySPI : loader) {
sb.append(mySPI.someMethod(input));
}
return sb.toString();
}
Aggregations