Search in sources :

Example 1 with MySPI

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);
}
Also used : Bundle(org.osgi.framework.Bundle) Hashtable(java.util.Hashtable) MySPI2(org.apache.aries.mytest.MySPI2) ServiceReference(org.osgi.framework.ServiceReference) MySPIImpl4c(org.apache.aries.spifly.impl4.MySPIImpl4c) MySPI(org.apache.aries.mytest.MySPI) MySPIImpl4a(org.apache.aries.spifly.impl4.MySPIImpl4a) BundleContext(org.osgi.framework.BundleContext) ServiceRegistration(org.osgi.framework.ServiceRegistration) Test(org.junit.Test)

Example 2 with MySPI

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;
}
Also used : MySPI(org.apache.aries.mytest.MySPI) HashSet(java.util.HashSet)

Example 3 with MySPI

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();
}
Also used : MySPI(org.apache.aries.mytest.MySPI)

Aggregations

MySPI (org.apache.aries.mytest.MySPI)3 HashSet (java.util.HashSet)1 Hashtable (java.util.Hashtable)1 MySPI2 (org.apache.aries.mytest.MySPI2)1 MySPIImpl4a (org.apache.aries.spifly.impl4.MySPIImpl4a)1 MySPIImpl4c (org.apache.aries.spifly.impl4.MySPIImpl4c)1 Test (org.junit.Test)1 Bundle (org.osgi.framework.Bundle)1 BundleContext (org.osgi.framework.BundleContext)1 ServiceReference (org.osgi.framework.ServiceReference)1 ServiceRegistration (org.osgi.framework.ServiceRegistration)1