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();
}
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);
}
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);
}
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();
}
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;
}
Aggregations