Search in sources :

Example 1 with BarService

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

the class TestExposition method testItfsExposition3.

@Test
public void testItfsExposition3() {
    ServiceReference refFoo = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), fooBarProvider3.getInstanceName());
    assertNotNull("Check the availability of the FS from " + fooBarProvider3.getInstanceName(), refFoo);
    ServiceReference refBar = ipojoHelper.getServiceReferenceByName(BarService.class.getName(), fooBarProvider3.getInstanceName());
    assertNotNull("Check the availability of the BS from " + fooBarProvider3.getInstanceName(), refBar);
    assertNotSame("Check service reference inequality", refFoo, refBar);
    FooService fs = (FooService) osgiHelper.getRawServiceObject(refFoo);
    assertTrue("Check fs invocation", fs.foo());
    BarService bs = (BarService) osgiHelper.getRawServiceObject(refBar);
    assertTrue("Check bs invocation", bs.bar());
    // Check properties
    String baz1 = (String) refFoo.getProperty("baz");
    String baz2 = (String) refBar.getProperty("baz");
    assertEquals("Check Baz Property 1", baz1, "foo");
    assertEquals("Check Baz Property 2", baz2, "bar");
    fooBarProvider3.stop();
    assertFalse("Check the absence of the FS from " + fooBarProvider3.getInstanceName(), ipojoHelper.isServiceAvailableByName(FooService.class.getName(), fooBarProvider3.getInstanceName()));
    assertFalse("Check the absence of the BS from " + fooBarProvider3.getInstanceName(), ipojoHelper.isServiceAvailableByName(BarService.class.getName(), fooBarProvider3.getInstanceName()));
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) BarService(org.apache.felix.ipojo.runtime.core.services.BarService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 2 with BarService

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

the class TestExposition method testItfsExposition2.

@Test
public void testItfsExposition2() {
    ServiceReference refFoo = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), fooBarProvider2.getInstanceName());
    assertNotNull("Check the availability of the FS from " + fooBarProvider2.getInstanceName(), refFoo);
    ServiceReference refBar = ipojoHelper.getServiceReferenceByName(BarService.class.getName(), fooBarProvider2.getInstanceName());
    assertNotNull("Check the availability of the BS from " + fooBarProvider2.getInstanceName(), refBar);
    assertSame("Check service reference equality", refFoo, refBar);
    FooService fs = (FooService) osgiHelper.getRawServiceObject(refFoo);
    assertTrue("Check fs invocation", fs.foo());
    BarService bs = (BarService) osgiHelper.getRawServiceObject(refBar);
    assertTrue("Check bs invocation", bs.bar());
    fooBarProvider2.stop();
    assertFalse("Check the absence of the FS from " + fooBarProvider2.getInstanceName(), ipojoHelper.isServiceAvailableByName(FooService.class.getName(), fooBarProvider2.getInstanceName()));
    assertFalse("Check the absence of the BS from " + fooBarProvider2.getInstanceName(), ipojoHelper.isServiceAvailableByName(BarService.class.getName(), fooBarProvider2.getInstanceName()));
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) BarService(org.apache.felix.ipojo.runtime.core.services.BarService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 3 with BarService

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

the class ServiceRegistryTest method testGetService.

@Test
public void testGetService() {
    ComponentInstance im = new FakeComponent();
    ComponentInstance im2 = new FakeComponent();
    ServiceRegistry registry = new ServiceRegistry(getContext());
    try {
        assertNull("Check that there is no available service", registry.getServiceReferences(null, null));
    } catch (InvalidSyntaxException e) {
        fail("Cannot query the registry : " + e.getMessage());
    }
    Properties props = new Properties();
    props.put("foo", "bar");
    ServiceRegistration reg1 = registry.registerService(im, BarService.class.getName(), new barProvider(), props);
    ServiceReference ref = registry.getServiceReference(BarService.class.getName());
    assertNotNull("Check ref not null", ref);
    assertEquals("Test property", ref.getProperty("foo"), "bar");
    BarService bar = (BarService) registry.getService(im2, ref);
    assertTrue("Test invocation", bar.bar());
    reg1.unregister();
    ref = registry.getServiceReference(BarService.class.getName());
    assertNull("Check ref null", ref);
}
Also used : ComponentInstance(org.apache.felix.ipojo.ComponentInstance) ServiceRegistry(org.apache.felix.ipojo.context.ServiceRegistry) Properties(java.util.Properties) BarService(org.apache.felix.ipojo.runtime.core.services.BarService) Test(org.junit.Test)

Example 4 with BarService

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

the class TestExposition method testItfsExposition.

@Test
public void testItfsExposition() {
    ServiceReference refFoo = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), fooBarProvider.getInstanceName());
    assertNotNull("Check the availability of the FS from " + fooBarProvider.getInstanceName(), refFoo);
    ServiceReference refBar = ipojoHelper.getServiceReferenceByName(BarService.class.getName(), fooBarProvider.getInstanceName());
    assertNotNull("Check the availability of the BS from " + fooBarProvider.getInstanceName(), refBar);
    assertSame("Check service reference equality", refFoo, refBar);
    FooService fs = (FooService) osgiHelper.getRawServiceObject(refFoo);
    assertTrue("Check fs invocation", fs.foo());
    BarService bs = (BarService) osgiHelper.getRawServiceObject(refBar);
    assertTrue("Check bs invocation", bs.bar());
    fooBarProvider.stop();
    assertFalse("Check the absence of the FS from " + fooBarProvider.getInstanceName(), ipojoHelper.isServiceAvailableByName(FooService.class.getName(), fooBarProvider.getInstanceName()));
    assertFalse("Check the absence of the BS from " + fooBarProvider.getInstanceName(), ipojoHelper.isServiceAvailableByName(BarService.class.getName(), fooBarProvider.getInstanceName()));
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) BarService(org.apache.felix.ipojo.runtime.core.services.BarService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 5 with BarService

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

the class ServiceRegistryTest method testGetFilteredService.

@Test
public void testGetFilteredService() {
    ComponentInstance im = new FakeComponent();
    ComponentInstance im2 = new FakeComponent();
    ServiceRegistry registry = new ServiceRegistry(getContext());
    try {
        assertNull("Check that there is no available service", registry.getServiceReferences(null, null));
    } catch (InvalidSyntaxException e) {
        fail("Cannot query the registry : " + e.getMessage());
    }
    Properties props = new Properties();
    props.put("foo", "bar");
    ServiceRegistration reg1 = registry.registerService(im, BarService.class.getName(), new barProvider(), props);
    ServiceRegistration reg2 = registry.registerService(im2, BarService.class.getName(), new barProvider(), null);
    ServiceReference[] ref = null;
    try {
        ref = registry.getServiceReferences(BarService.class.getName(), "(foo=bar)");
    } catch (InvalidSyntaxException e) {
        fail("Registry query fail : " + e.getMessage());
    }
    assertNotNull("Check ref not null", ref);
    assertEquals("Check ref count", ref.length, 1);
    assertEquals("Test property", ref[0].getProperty("foo"), "bar");
    BarService bar = (BarService) registry.getService(im2, ref[0]);
    assertTrue("Test invocation", bar.bar());
    ref = null;
    reg1.unregister();
    try {
        ref = registry.getServiceReferences(BarService.class.getName(), "(bar=foo)");
    } catch (InvalidSyntaxException e) {
        fail("Registry query fail : " + e.getMessage());
    }
    assertNull("Check ref null", ref);
    reg2.unregister();
}
Also used : ComponentInstance(org.apache.felix.ipojo.ComponentInstance) ServiceRegistry(org.apache.felix.ipojo.context.ServiceRegistry) Properties(java.util.Properties) BarService(org.apache.felix.ipojo.runtime.core.services.BarService) Test(org.junit.Test)

Aggregations

BarService (org.apache.felix.ipojo.runtime.core.services.BarService)5 Test (org.junit.Test)5 FooService (org.apache.felix.ipojo.runtime.core.services.FooService)3 ServiceReference (org.osgi.framework.ServiceReference)3 Properties (java.util.Properties)2 ComponentInstance (org.apache.felix.ipojo.ComponentInstance)2 ServiceRegistry (org.apache.felix.ipojo.context.ServiceRegistry)2