Search in sources :

Example 86 with CheckService

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();
}
Also used : 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 87 with CheckService

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();
}
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 88 with CheckService

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);
}
Also used : 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 89 with CheckService

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();
}
Also used : 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 90 with CheckService

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();
}
Also used : Dictionary(java.util.Dictionary) Hashtable(java.util.Hashtable) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) Properties(java.util.Properties) CheckService(org.apache.felix.ipojo.runtime.core.test.services.CheckService) Test(org.junit.Test)

Aggregations

CheckService (org.apache.felix.ipojo.runtime.core.test.services.CheckService)245 Test (org.junit.Test)243 ServiceReference (org.osgi.framework.ServiceReference)233 Architecture (org.apache.felix.ipojo.architecture.Architecture)218 InstanceDescription (org.apache.felix.ipojo.architecture.InstanceDescription)213 Properties (java.util.Properties)208 ComponentInstance (org.apache.felix.ipojo.ComponentInstance)20 FooService (org.apache.felix.ipojo.runtime.core.test.services.FooService)20 Map (java.util.Map)5 PrimitiveInstanceDescription (org.apache.felix.ipojo.PrimitiveInstanceDescription)5 DependencyHandlerDescription (org.apache.felix.ipojo.handlers.dependency.DependencyHandlerDescription)5 ProvidedServiceHandlerDescription (org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandlerDescription)5 Setter (org.apache.felix.ipojo.runtime.core.test.services.Setter)3 Dictionary (java.util.Dictionary)1 Hashtable (java.util.Hashtable)1 DependencyDescription (org.apache.felix.ipojo.handlers.dependency.DependencyDescription)1