Search in sources :

Example 86 with ComponentInstance

use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.

the class TestInheritedClasses method testIP2.

@Test
public void testIP2() {
    ComponentInstance ci = ipojoHelper.createComponentInstance(pi2.getName(), "ci");
    ServiceReference ref1 = ipojoHelper.getServiceReferenceByName(ChildInterface.class.getName(), "ci");
    assertNotNull("Check Child", ref1);
    ServiceReference ref2 = ipojoHelper.getServiceReferenceByName(ParentInterface1.class.getName(), "ci");
    assertNotNull("Check Parent1", ref2);
    ServiceReference ref3 = ipojoHelper.getServiceReferenceByName(ParentInterface2.class.getName(), "ci");
    assertNotNull("Check Parent2", ref3);
    ServiceReference ref4 = ipojoHelper.getServiceReferenceByName(ParentParentInterface.class.getName(), "ci");
    assertNotNull("Check PP", ref4);
    ci.dispose();
}
Also used : ComponentInstance(org.apache.felix.ipojo.ComponentInstance) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 87 with ComponentInstance

use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.

the class TestInheritedClasses method testIP1.

@Test
public void testIP1() {
    ComponentInstance ci = ipojoHelper.createComponentInstance(pi1.getName(), "ci");
    ServiceReference ref1 = ipojoHelper.getServiceReferenceByName(ChildInterface.class.getName(), "ci");
    assertNotNull("Check Child", ref1);
    ServiceReference ref2 = ipojoHelper.getServiceReferenceByName(ParentInterface1.class.getName(), "ci");
    assertNotNull("Check Parent1", ref2);
    ServiceReference ref3 = ipojoHelper.getServiceReferenceByName(ParentInterface2.class.getName(), "ci");
    assertNotNull("Check Parent2", ref3);
    ServiceReference ref4 = ipojoHelper.getServiceReferenceByName(ParentParentInterface.class.getName(), "ci");
    assertNotNull("Check PP", ref4);
    ci.dispose();
}
Also used : ComponentInstance(org.apache.felix.ipojo.ComponentInstance) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 88 with ComponentInstance

use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.

the class TestListeners method testRemoveNonexistentProvidedServiceListener.

@Test(expected = NoSuchElementException.class)
public void testRemoveNonexistentProvidedServiceListener() {
    ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Controller-1-default");
    ProvidedServiceHandlerDescription pshd = (ProvidedServiceHandlerDescription) ci.getInstanceDescription().getHandlerDescription("org.apache.felix.ipojo:provides");
    ProvidedServiceDescription ps = getPS(FooService.class.getName(), pshd.getProvidedServices());
    // Should fail!
    ps.removeListener(new ThrowingListener());
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) ProvidedServiceDescription(org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceDescription) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) ProvidedServiceHandlerDescription(org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandlerDescription) Test(org.junit.Test)

Example 89 with ComponentInstance

use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.

the class TestServiceController method testComponentWithTwoControllersUsingBothSpecificationsTrueFalse.

@Test
public void testComponentWithTwoControllersUsingBothSpecificationsTrueFalse() {
    ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Controller-2-spec1");
    osgiHelper.waitForService(CheckService.class.getName(), null, 5000);
    assertFalse(osgiHelper.isServiceAvailable(FooService.class.getName()));
    CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
    assertNotNull(check);
    check.getProps();
    assertFalse(osgiHelper.isServiceAvailable(CheckService.class.getName()));
    assertTrue(osgiHelper.isServiceAvailable(FooService.class.getName()));
    FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), null);
    fs.fooProps();
    assertTrue(osgiHelper.isServiceAvailable(CheckService.class.getName()));
    assertTrue(osgiHelper.isServiceAvailable(FooService.class.getName()));
    ci.dispose();
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) CheckService(org.apache.felix.ipojo.runtime.core.services.CheckService) Test(org.junit.Test)

Example 90 with ComponentInstance

use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.

the class TestServiceController method testComponentWithTwoControllersUsingBothSpecificationsTrueTrue.

@Test
public void testComponentWithTwoControllersUsingBothSpecificationsTrueTrue() {
    ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Controller-2-spec2");
    osgiHelper.waitForService(CheckService.class.getName(), null, 5000);
    osgiHelper.waitForService(FooService.class.getName(), null, 5000);
    CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
    assertNotNull(check);
    check.check();
    // CheckService not available
    assertNull(osgiHelper.getServiceReference(CheckService.class.getName()));
    assertNotNull(osgiHelper.getServiceReference(FooService.class.getName()));
    FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), null);
    fs.foo();
    assertNull(osgiHelper.getServiceReference(CheckService.class.getName()));
    assertNull(osgiHelper.getServiceReference(FooService.class.getName()));
    ci.dispose();
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) CheckService(org.apache.felix.ipojo.runtime.core.services.CheckService) Test(org.junit.Test)

Aggregations

ComponentInstance (org.apache.felix.ipojo.ComponentInstance)373 Test (org.junit.Test)360 ServiceReference (org.osgi.framework.ServiceReference)215 Properties (java.util.Properties)142 CheckService (org.apache.felix.ipojo.handler.temporal.services.CheckService)70 FooService (org.apache.felix.ipojo.handler.temporal.services.FooService)70 CheckService (org.apache.felix.ipojo.handler.transaction.services.CheckService)65 Factory (org.apache.felix.ipojo.Factory)53 CheckService (org.apache.felix.ipojo.runtime.core.services.CheckService)50 ServiceContext (org.apache.felix.ipojo.ServiceContext)47 FooService (org.apache.felix.ipojo.runtime.core.services.FooService)39 IOException (java.io.IOException)29 CheckService (org.apache.felix.ipojo.runtime.core.test.services.CheckService)22 BundleContext (org.osgi.framework.BundleContext)19 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)17 ComponentFactory (org.apache.felix.ipojo.ComponentFactory)14 Dictionary (java.util.Dictionary)12 Hashtable (java.util.Hashtable)12 BarService (org.apache.felix.ipojo.runtime.core.services.BarService)10 DependencyDescription (org.apache.felix.ipojo.handlers.dependency.DependencyDescription)9