Search in sources :

Example 36 with Factory

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

the class TestStereotypeAnnotation method testMethodStereotype.

@Test
public void testMethodStereotype() {
    // verify component's factory is here
    // verify that the requires handler has been activated
    // verify that a created instance works
    Factory factory = ipojoHelper.getFactory(MB_FACTORY_NAME);
    Assert.assertNotNull(factory);
    assertEquals(Factory.VALID, factory.getState());
    assertTrue(factory.getRequiredHandlers().contains("org.apache.felix.ipojo:requires"));
    ComponentInstance instance = ipojoHelper.createComponentInstance(MB_FACTORY_NAME, "stereotype-multibind-instance");
    assertTrue(ipojoHelper.isInstanceValid(instance));
    ipojoHelper.dispose();
}
Also used : ComponentInstance(org.apache.felix.ipojo.ComponentInstance) Factory(org.apache.felix.ipojo.Factory) Test(org.junit.Test) BaseTest(org.ow2.chameleon.testing.helpers.BaseTest)

Example 37 with Factory

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

the class TestStereotypeAnnotation method testTypeStereotype.

@Test
public void testTypeStereotype() {
    // verify component's factory is here
    // verify BazService has been published
    // --> verify instance has been created
    Factory factory = ipojoHelper.getFactory(BAZ_FACTORY_NAME);
    Assert.assertNotNull(factory);
    assertEquals(Factory.VALID, factory.getState());
    List<BazService> services = osgiHelper.getServiceObjects(BazService.class);
    assertEquals(1, services.size());
    BazService baz = services.get(0);
    assertEquals("Hello Guillaume", baz.hello("Guillaume"));
    ipojoHelper.dispose();
}
Also used : BazService(org.apache.felix.ipojo.runtime.core.services.BazService) Factory(org.apache.felix.ipojo.Factory) Test(org.junit.Test) BaseTest(org.ow2.chameleon.testing.helpers.BaseTest)

Example 38 with Factory

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

the class TestFilteredExport method setUp.

@Before
public void setUp() {
    fooProvider = ipojoHelper.getFactory("BazProviderType");
    assertNotNull("Check fooProvider availability", fooProvider);
    Properties p1 = new Properties();
    p1.put("instance.name", "foo1");
    Properties p2 = new Properties();
    p2.put("instance.name", "foo2");
    try {
        foo1 = fooProvider.createComponentInstance(p1);
        foo2 = fooProvider.createComponentInstance(p2);
    } catch (Exception e) {
        fail("Fail to create foos : " + e.getMessage());
    }
    foo1.stop();
    foo2.stop();
    Factory factory = ipojoHelper.getFactory("composite.export.5");
    Properties props = new Properties();
    props.put("instance.name", "export");
    try {
        export1 = factory.createComponentInstance(props);
    } catch (Exception e) {
        fail("Fail to instantiate exporter " + e.getMessage());
    }
}
Also used : Factory(org.apache.felix.ipojo.Factory) Properties(java.util.Properties) Before(org.junit.Before)

Example 39 with Factory

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

the class TestMultipleExport method setUp.

@Before
public void setUp() {
    fooProvider = ipojoHelper.getFactory("BazProviderType");
    assertNotNull("Check fooProvider availability", fooProvider);
    Properties p1 = new Properties();
    p1.put("instance.name", "foo1");
    Properties p2 = new Properties();
    p2.put("instance.name", "foo2");
    try {
        foo1 = fooProvider.createComponentInstance(p1);
        foo2 = fooProvider.createComponentInstance(p2);
    } catch (Exception e) {
        fail("Fail to create foos : " + e.getMessage());
    }
    foo1.stop();
    foo2.stop();
    Factory factory = ipojoHelper.getFactory("composite.export.3");
    Properties props = new Properties();
    props.put("instance.name", "export");
    try {
        export3 = factory.createComponentInstance(props);
    } catch (Exception e) {
        fail("Fail to instantiate exporter " + e.getMessage());
    }
}
Also used : Factory(org.apache.felix.ipojo.Factory) Properties(java.util.Properties) Before(org.junit.Before)

Example 40 with Factory

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

the class TestOptionalMultipleExport method setUp.

@Before
public void setUp() {
    fooProvider = ipojoHelper.getFactory("BazProviderType");
    assertNotNull("Check fooProvider availability", fooProvider);
    Properties p1 = new Properties();
    p1.put("instance.name", "foo1");
    Properties p2 = new Properties();
    p2.put("instance.name", "foo2");
    try {
        foo1 = fooProvider.createComponentInstance(p1);
        foo2 = fooProvider.createComponentInstance(p2);
    } catch (Exception e) {
        fail("Fail to create foos : " + e.getMessage());
    }
    foo1.stop();
    foo2.stop();
    Factory factory = ipojoHelper.getFactory("composite.export.4");
    Properties props = new Properties();
    props.put("instance.name", "export");
    try {
        export3 = factory.createComponentInstance(props);
    } catch (Exception e) {
        fail("Fail to instantiate exporter " + e.getMessage());
    }
}
Also used : Factory(org.apache.felix.ipojo.Factory) Properties(java.util.Properties) Before(org.junit.Before)

Aggregations

Factory (org.apache.felix.ipojo.Factory)111 Properties (java.util.Properties)88 Test (org.junit.Test)71 ComponentInstance (org.apache.felix.ipojo.ComponentInstance)53 Before (org.junit.Before)33 ServiceReference (org.osgi.framework.ServiceReference)29 FooService (org.apache.felix.ipojo.runtime.core.services.FooService)17 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)17 ComponentFactory (org.apache.felix.ipojo.ComponentFactory)14 ServiceContext (org.apache.felix.ipojo.ServiceContext)13 CheckService (org.apache.felix.ipojo.runtime.core.services.CheckService)11 IOException (java.io.IOException)6 HandlerFactory (org.apache.felix.ipojo.HandlerFactory)6 Architecture (org.apache.felix.ipojo.architecture.Architecture)4 HandlerDescription (org.apache.felix.ipojo.architecture.HandlerDescription)4 InstanceDescription (org.apache.felix.ipojo.architecture.InstanceDescription)4 CompositeInstanceDescription (org.apache.felix.ipojo.composite.CompositeInstanceDescription)4 CompositeManager (org.apache.felix.ipojo.composite.CompositeManager)4 ProvidedServiceDescription (org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceDescription)4 ProvidedServiceHandlerDescription (org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandlerDescription)4