use of org.apache.felix.ipojo.runtime.core.test.services.CheckService in project felix by apache.
the class TestProxyTest method testImmediateNoService.
@Test
public void testImmediateNoService() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
Properties i1 = new Properties();
i1.put("instance.name", "Delegator-with-no-service");
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);
try {
cs.getProps();
fail("Exception expected");
} catch (RuntimeException e) {
// OK
}
instance1.dispose();
}
use of org.apache.felix.ipojo.runtime.core.test.services.CheckService in project felix by apache.
the class TestProxyTest method testGetAndDelegation.
@Test
public void testGetAndDelegation() 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.CheckServiceGetAndDelegate").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"));
assertTrue(cs.check());
fooProvider1.dispose();
instance1.dispose();
}
use of org.apache.felix.ipojo.runtime.core.test.services.CheckService in project felix by apache.
the class TestBindingInterceptors method testProxyBindingInterceptorBeforeInstanceCreation.
@Test
public void testProxyBindingInterceptorBeforeInstanceCreation() {
// Create the interceptor
Properties configuration = new Properties();
configuration.put("target", "(dependency.id=foo)");
ipojoHelper.createComponentInstance("org.apache.felix.ipojo.runtime.core.test.interceptors" + ".ProxyBindingInterceptor", configuration);
// Create the FooConsumer
ComponentInstance instance = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.runtime.core.test" + ".components" + ".FooConsumer");
ServiceReference ref = osgiHelper.waitForService(CheckService.class.getName(), "(instance.name=" + instance.getInstanceName() + ")", 1000, true);
CheckService check = (CheckService) osgiHelper.getRawServiceObject(ref);
assertThat(check.check());
// Extract monitored data
CheckService checkService = osgiHelper.getServiceObject(CheckService.class, "(factory.name=org.apache.felix.ipojo.runtime.core.test.interceptors.ProxyBindingInterceptor)");
assertThat(checkService).isNotNull();
assertThat(checkService.getProps().get("bound")).isEqualTo(1);
assertThat(checkService.getProps().get("foo")).isEqualTo(1);
provider.dispose();
assertThat(checkService.getProps().get("bound")).isEqualTo(1);
assertThat(checkService.getProps().get("unbound")).isEqualTo(1);
}
use of org.apache.felix.ipojo.runtime.core.test.services.CheckService in project felix by apache.
the class TestBindingInterceptors method testWithTwoInterceptors.
/**
* Checks that two interceptors are called sequentially.
*/
@Test
public void testWithTwoInterceptors() {
// First, only one interceptor.
// Create the interceptor
Properties configuration = new Properties();
configuration.put("target", "(dependency.id=foo)");
ipojoHelper.createComponentInstance("org.apache.felix.ipojo.runtime.core.test.interceptors" + ".ProxyBindingInterceptor", configuration);
// Create the FooConsumer
ComponentInstance instance = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.runtime.core.test" + ".components" + ".FooConsumer");
ServiceReference ref = osgiHelper.waitForService(CheckService.class.getName(), "(instance.name=" + instance.getInstanceName() + ")", 1000, true);
CheckService check = (CheckService) osgiHelper.getRawServiceObject(ref);
assertThat(check.check());
// Create the second interceptor, but it's too late to modify the first binding.
configuration = new Properties();
configuration.put("target", "(dependency.id=foo)");
ipojoHelper.createComponentInstance("org.apache.felix.ipojo.runtime.core.test.interceptors" + ".EnhancingBindingInterceptor", configuration);
assertThat(check.getProps().get("enhanced")).isNull();
// Extract monitored data
CheckService checkService = osgiHelper.getServiceObject(CheckService.class, "(factory.name=org.apache.felix.ipojo.runtime.core.test.interceptors.ProxyBindingInterceptor)");
assertThat(checkService).isNotNull();
assertThat(checkService.getProps().get("bound")).isEqualTo(1);
assertThat(checkService.getProps().get("foo")).isEqualTo(1);
// Force re-binding.
provider.stop();
provider.start();
assertThat(check.getProps().get("enhanced")).isNotNull();
}
use of org.apache.felix.ipojo.runtime.core.test.services.CheckService in project felix by apache.
the class TestCombinationOfInterceptors method testAdvanced.
@Test
public void testAdvanced() {
provider1 = provider(0);
provider2 = provider(0);
provider3 = provider(1);
provider4 = provider(1);
provider5 = provider(2);
provider6 = provider(2);
// Create the interceptor
Properties configuration = new Properties();
configuration.put("target", "(dependency.id=foo)");
ipojoHelper.createComponentInstance("org.apache.felix.ipojo.runtime.core.test.interceptors" + ".AdvancedTrackerAndRankerInterceptor", configuration);
// Create the FooConsumer
ComponentInstance instance = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.runtime.core.test" + ".components.AdvancedFooConsumer");
// Check we are using provider 0
osgiHelper.waitForService(CheckService.class.getName(), null, 1000, true);
CheckService check = osgiHelper.getServiceObject(CheckService.class);
assertThat(check.getProps().get("grade")).isEqualTo(0);
Dictionary conf = new Hashtable();
conf.put("grade", "1");
instance.reconfigure(conf);
assertThat(check.getProps().get("grade")).isEqualTo(1);
conf.put("grade", "2");
instance.reconfigure(conf);
assertThat(check.getProps().get("grade")).isEqualTo(2);
conf.put("grade", "3");
instance.reconfigure(conf);
assertThat(check.getProps().get("grade")).isNull();
}
Aggregations