Search in sources :

Example 11 with FooService

use of org.apache.felix.ipojo.runtime.core.test.services.FooService in project felix by apache.

the class TestProxyTest method testImmediate.

@Test
public void testImmediate() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
    Properties prov = new Properties();
    prov.put("instance.name", "FooProvider1-Proxy");
    ComponentInstance fooProvider1 = ipojoHelper.getFactory("FooProviderType-1").createComponentInstance(prov);
    Properties i1 = new Properties();
    i1.put("instance.name", "Delegator");
    ComponentInstance instance1 = ipojoHelper.getFactory("org.apache.felix.ipojo.runtime.core.test.components.proxy.CheckServiceNoDelegate").createComponentInstance(i1);
    osgiHelper.waitForService(CheckService.class, "(service.pid=Helper)", 10000);
    ServiceReference ref = osgiHelper.getServiceReference(CheckService.class.getName(), "(service.pid=Helper)");
    assertNotNull(ref);
    CheckService cs = (CheckService) osgiHelper.getRawServiceObject(ref);
    Properties props = cs.getProps();
    FooService helper = (FooService) props.get("helper.fs");
    assertNotNull(helper);
    // This is the suffix.
    assertTrue(helper.toString().contains("$$Proxy"));
    assertTrue(cs.check());
    fooProvider1.dispose();
    instance1.dispose();
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.test.services.FooService) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) Properties(java.util.Properties) CheckService(org.apache.felix.ipojo.runtime.core.test.services.CheckService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 12 with FooService

use of org.apache.felix.ipojo.runtime.core.test.services.FooService in project felix by apache.

the class TestProxyTest method testDynamicProxy.

@Test
public void testDynamicProxy() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
    // Dynamic proxy
    System.setProperty(DependencyHandler.PROXY_TYPE_PROPERTY, DependencyHandler.DYNAMIC_PROXY);
    Properties prov = new Properties();
    prov.put("instance.name", "FooProvider1-Proxy");
    ComponentInstance fooProvider1 = ipojoHelper.getFactory("FooProviderType-1").createComponentInstance(prov);
    Properties i1 = new Properties();
    i1.put("instance.name", "Delegator");
    ComponentInstance instance1 = ipojoHelper.getFactory("org.apache.felix.ipojo.runtime.core.test.components.proxy.CheckServiceDelegator").createComponentInstance(i1);
    ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance1.getInstanceName());
    assertNotNull(ref);
    CheckService cs = (CheckService) osgiHelper.getRawServiceObject(ref);
    Properties props = cs.getProps();
    FooService helper = (FooService) props.get("helper.fs");
    assertNotNull(helper);
    // Dynamic proxy.
    assertFalse(helper.toString().contains("$$Proxy"));
    assertTrue(helper.toString().contains("DynamicProxyFactory"));
    assertTrue(helper.hashCode() > 0);
    assertTrue(helper.equals(helper));
    // This is a quite stupid test...
    assertFalse(helper.equals(i1));
    assertTrue(cs.check());
    fooProvider1.dispose();
    instance1.dispose();
    System.setProperty(DependencyHandler.PROXY_TYPE_PROPERTY, DependencyHandler.SMART_PROXY);
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.test.services.FooService) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) Properties(java.util.Properties) CheckService(org.apache.felix.ipojo.runtime.core.test.services.CheckService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 13 with FooService

use of org.apache.felix.ipojo.runtime.core.test.services.FooService in project felix by apache.

the class TestProxyTest method testProxyDisabled.

@Test
public void testProxyDisabled() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
    // Disable proxy
    System.setProperty(DependencyHandler.PROXY_SETTINGS_PROPERTY, DependencyHandler.PROXY_DISABLED);
    System.out.println("Bundle context prop : " + bc.getProperty(DependencyHandler.PROXY_SETTINGS_PROPERTY));
    Properties prov = new Properties();
    prov.put("instance.name", "FooProvider1-Proxy");
    ComponentInstance fooProvider1 = ipojoHelper.getFactory("FooProviderType-1").createComponentInstance(prov);
    Properties i1 = new Properties();
    i1.put("instance.name", "Delegator");
    ComponentInstance instance1 = ipojoHelper.getFactory("org.apache.felix.ipojo.runtime.core.test.components.proxy.CheckServiceDelegator").createComponentInstance(i1);
    osgiHelper.waitForService(CheckService.class, "(instance.name=Delegator)", 10000);
    ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance1.getInstanceName());
    assertNotNull(ref);
    CheckService cs = (CheckService) osgiHelper.getRawServiceObject(ref);
    Properties props = cs.getProps();
    FooService helper = (FooService) props.get("helper.fs");
    System.out.println("helper : " + helper.toString());
    assertNotNull(helper);
    // Not a proxy.
    assertFalse(helper.toString().contains("$$Proxy"));
    assertTrue(cs.check());
    fooProvider1.dispose();
    instance1.dispose();
    System.setProperty(DependencyHandler.PROXY_SETTINGS_PROPERTY, DependencyHandler.PROXY_ENABLED);
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.test.services.FooService) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) Properties(java.util.Properties) CheckService(org.apache.felix.ipojo.runtime.core.test.services.CheckService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 14 with FooService

use of org.apache.felix.ipojo.runtime.core.test.services.FooService in project felix by apache.

the class TestProxyTest method testDelegationOnNullable.

@Test
public void testDelegationOnNullable() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
    Properties i1 = new Properties();
    i1.put("instance.name", "DelegatorNullable");
    ComponentInstance instance1 = ipojoHelper.getFactory("org.apache.felix.ipojo.runtime.core.test.components.proxy.CheckServiceDelegator").createComponentInstance(i1);
    ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance1.getInstanceName());
    assertNotNull(ref);
    CheckService cs = (CheckService) osgiHelper.getRawServiceObject(ref);
    Properties props = cs.getProps();
    FooService helper = (FooService) props.get("helper.fs");
    assertNotNull(helper);
    // This is the suffix.
    assertTrue(helper.toString().contains("$$Proxy"));
    // Nullable.
    assertFalse(cs.check());
    instance1.dispose();
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.test.services.FooService) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) Properties(java.util.Properties) CheckService(org.apache.felix.ipojo.runtime.core.test.services.CheckService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 15 with FooService

use of org.apache.felix.ipojo.runtime.core.test.services.FooService in project felix by apache.

the class SetCheckService method getDouble.

private double getDouble() {
    double r = 0.0;
    Iterator it = fs.iterator();
    while (it.hasNext()) {
        r = r + ((FooService) it.next()).getLong();
    }
    return r;
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.test.services.FooService) Iterator(java.util.Iterator)

Aggregations

FooService (org.apache.felix.ipojo.runtime.core.test.services.FooService)19 CheckService (org.apache.felix.ipojo.runtime.core.test.services.CheckService)15 Test (org.junit.Test)15 ServiceReference (org.osgi.framework.ServiceReference)15 Properties (java.util.Properties)13 Architecture (org.apache.felix.ipojo.architecture.Architecture)8 ComponentInstance (org.apache.felix.ipojo.ComponentInstance)7 InstanceDescription (org.apache.felix.ipojo.architecture.InstanceDescription)7 Iterator (java.util.Iterator)4 PrimitiveInstanceDescription (org.apache.felix.ipojo.PrimitiveInstanceDescription)1 DependencyHandlerDescription (org.apache.felix.ipojo.handlers.dependency.DependencyHandlerDescription)1 ProvidedServiceHandlerDescription (org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandlerDescription)1