Search in sources :

Example 46 with Factory

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

the class TestOptionalImport method setUp.

@Before
public void setUp() {
    osgiHelper.waitForService(Factory.class, "(factory.name=COMPO-FooProviderType-1)", 1000);
    fooProvider = ipojoHelper.getFactory("COMPO-FooProviderType-1");
    assertNotNull("Check fooProvider availability", fooProvider);
    Properties p = new Properties();
    p.put("instance.name", "importer");
    Factory compFact = ipojoHelper.getFactory("composite.requires.3");
    try {
        import3 = compFact.createComponentInstance(p);
    } catch (Exception e) {
        fail("Cannot instantiate the component : " + e.getMessage());
    }
}
Also used : Factory(org.apache.felix.ipojo.Factory) Properties(java.util.Properties) Before(org.junit.Before)

Example 47 with Factory

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

the class TestOptionalMultipleImport method setUp.

@Before
public void setUp() {
    osgiHelper.waitForService(Factory.class, "(factory.name=COMPO-FooProviderType-1)", 1000);
    fooProvider = ipojoHelper.getFactory("COMPO-FooProviderType-1");
    assertNotNull("Check fooProvider availability", fooProvider);
    Properties p = new Properties();
    p.put("instance.name", "importer");
    Factory compFact = ipojoHelper.getFactory("composite.requires.4");
    try {
        import2 = compFact.createComponentInstance(p);
    } catch (Exception e) {
        fail("Cannot instantiate the component : " + e.getMessage());
    }
}
Also used : Factory(org.apache.felix.ipojo.Factory) Properties(java.util.Properties) Before(org.junit.Before)

Example 48 with Factory

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

the class TestMultipleInstantiation method setUp.

@Before
public void setUp() {
    bar2Factory = (ComponentFactory) ipojoHelper.getFactory("composite.bar.2");
    Factory fact = ipojoHelper.getFactory("composite.empty");
    Properties props = new Properties();
    props.put("instance.name", "empty");
    try {
        empty = fact.createComponentInstance(props);
    } catch (Exception e) {
        fail("Cannot create the empty composite : " + e.getMessage());
    }
}
Also used : Factory(org.apache.felix.ipojo.Factory) ComponentFactory(org.apache.felix.ipojo.ComponentFactory) Properties(java.util.Properties) Before(org.junit.Before)

Example 49 with Factory

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

the class TestOptionalMultipleInstantiation method setUp.

@Before
public void setUp() {
    bar2Factory = (ComponentFactory) ipojoHelper.getFactory("composite.bar.4");
    assertNotNull("Check bar2factory availability", bar2Factory);
    Factory fact = ipojoHelper.getFactory("composite.empty");
    Properties props = new Properties();
    props.put("instance.name", "empty");
    try {
        empty = fact.createComponentInstance(props);
    } catch (Exception e) {
        fail("Cannot create the empty composite : " + e.getMessage());
    }
}
Also used : ComponentFactory(org.apache.felix.ipojo.ComponentFactory) Factory(org.apache.felix.ipojo.Factory) Properties(java.util.Properties) Before(org.junit.Before)

Example 50 with Factory

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

the class EmptyCompositeTest method testEmptyCompositeCreation.

@Test
public void testEmptyCompositeCreation() {
    Factory factory = ipojoHelper.getFactory("composite.empty");
    Properties props = new Properties();
    props.put("instance.name", "empty");
    ComponentInstance ci = null;
    try {
        ci = factory.createComponentInstance(props);
    } catch (Exception e) {
        e.printStackTrace();
        fail("Unacceptable configuration : " + e.getMessage());
    }
    ComponentTypeDescription cd = ci.getFactory().getComponentDescription();
    assertEquals("Check component type name", cd.getName(), "composite.empty");
    // assertEquals("Check class name (" + cd.getClassName() + ")", cd.getClassName(), "composite");
    assertEquals("Check offered service", cd.getprovidedServiceSpecification().length, 0);
    assertEquals("Check configurable properties", cd.getProperties().length, 0);
    CompositeInstanceDescription id = (CompositeInstanceDescription) ci.getInstanceDescription();
    assertEquals("Check composite instance name", id.getName(), "empty");
    assertEquals("Check composite instance state (" + id.getState() + ")", id.getState(), ComponentInstance.VALID);
    assertEquals("Check contained instance", id.getContainedInstances().length, 0);
    assertTrue("Check composite manager", ci instanceof CompositeManager);
    CompositeManager cm = (CompositeManager) ci;
    ServiceContext sc = cm.getServiceContext();
    try {
        assertEquals("Check number of factories imported", sc.getServiceReferences(Factory.class.getName(), null).length, getContext().getServiceReferences(Factory.class.getName(), null).length);
    } catch (InvalidSyntaxException e) {
        fail("Invalid filter : " + e.getMessage());
    }
    ci.dispose();
}
Also used : ComponentTypeDescription(org.apache.felix.ipojo.architecture.ComponentTypeDescription) ServiceContext(org.apache.felix.ipojo.ServiceContext) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) CompositeManager(org.apache.felix.ipojo.composite.CompositeManager) Factory(org.apache.felix.ipojo.Factory) CompositeInstanceDescription(org.apache.felix.ipojo.composite.CompositeInstanceDescription) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) Properties(java.util.Properties) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) Test(org.junit.Test)

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