Search in sources :

Example 1 with PrimitiveComponentType

use of org.apache.felix.ipojo.api.PrimitiveComponentType in project felix by apache.

the class CompositeTest method createACompositeWithAnInstantiatedService.

@Test
public void createACompositeWithAnInstantiatedService() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
    // Define the component types
    PrimitiveComponentType prov = createAProvider();
    prov.start();
    PrimitiveComponentType cons = createAConsumer();
    ServiceReference[] refs = osgiHelper.getServiceReferences(Factory.class.getName(), "(component.providedServiceSpecifications=" + Foo.class.getName() + ")");
    assertThat(refs.length, is(not(0)));
    Factory factory = (Factory) osgiHelper.getRawServiceObject(refs[0]);
    System.out.println(factory.getComponentDescription().getDescription());
    CompositeComponentType type = new CompositeComponentType().setBundleContext(context).setComponentTypeName("comp2").addSubService(new InstantiatedService().setSpecification(Foo.class.getName())).addInstance(new Instance(cons.getFactory().getName()));
    ComponentInstance ci = type.createInstance();
    System.out.println(ci.getInstanceDescription().getDescription());
    assertThat("ci is valid", ci.getState(), is(ComponentInstance.VALID));
    // Stop prov
    prov.stop();
    assertThat("ci is invalid", ci.getState(), is(ComponentInstance.INVALID));
    // Restart prov
    prov.start();
    assertThat("ci is valid - 2", ci.getState(), is(ComponentInstance.VALID));
}
Also used : Foo(org.apache.felix.ipojo.runtime.core.api.services.Foo) PrimitiveComponentType(org.apache.felix.ipojo.api.PrimitiveComponentType) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 2 with PrimitiveComponentType

use of org.apache.felix.ipojo.api.PrimitiveComponentType in project felix by apache.

the class CompositeTest method createACompositeWithAnOptionalInstantiatedService.

@Test
public void createACompositeWithAnOptionalInstantiatedService() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
    // Define the component types
    PrimitiveComponentType prov = createAProvider();
    prov.start();
    CompositeComponentType type = new CompositeComponentType().setBundleContext(context).setComponentTypeName("comp3").addSubService(new InstantiatedService().setSpecification(Foo.class.getName()).setOptional(true));
    ComponentInstance ci = type.createInstance();
    assertThat("ci is valid", ci.getState(), is(ComponentInstance.VALID));
    // Stop prov
    prov.stop();
    assertThat("ci is valid - 1", ci.getState(), is(ComponentInstance.VALID));
    // Restart prov
    prov.start();
    assertThat("ci is valid - 2", ci.getState(), is(ComponentInstance.VALID));
}
Also used : Foo(org.apache.felix.ipojo.runtime.core.api.services.Foo) PrimitiveComponentType(org.apache.felix.ipojo.api.PrimitiveComponentType) Test(org.junit.Test)

Example 3 with PrimitiveComponentType

use of org.apache.felix.ipojo.api.PrimitiveComponentType in project felix by apache.

the class CompositeTest method createACompositeWithAnOptionalImportedService.

@Test
public void createACompositeWithAnOptionalImportedService() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
    // Define the component types
    PrimitiveComponentType prov = createAProvider();
    prov.createInstance();
    CompositeComponentType type = new CompositeComponentType().setBundleContext(context).setComponentTypeName("comp3").addSubService(new ImportedService().setSpecification(Foo.class.getName()).setOptional(true));
    ComponentInstance ci = type.createInstance();
    assertThat("ci is valid", ci.getState(), is(ComponentInstance.VALID));
    // Stop prov
    prov.stop();
    assertThat("ci is valid - 1", ci.getState(), is(ComponentInstance.VALID));
    // Restart prov
    prov.start();
    prov.createInstance();
    assertThat("ci is valid - 2", ci.getState(), is(ComponentInstance.VALID));
}
Also used : Foo(org.apache.felix.ipojo.runtime.core.api.services.Foo) PrimitiveComponentType(org.apache.felix.ipojo.api.PrimitiveComponentType) Test(org.junit.Test)

Example 4 with PrimitiveComponentType

use of org.apache.felix.ipojo.api.PrimitiveComponentType in project felix by apache.

the class CompositeTest method createACompositeWithcontainedInstance.

@Test
public void createACompositeWithcontainedInstance() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
    // Define the component types
    PrimitiveComponentType prov = createAProvider();
    PrimitiveComponentType cons = createAConsumer();
    CompositeComponentType type = new CompositeComponentType().setBundleContext(context).setComponentTypeName("comp1").addInstance(new Instance(prov.getFactory().getName())).addInstance(new Instance(cons.getFactory().getName()));
    ComponentInstance ci = type.createInstance();
    assertThat("ci is valid", ci.getState(), is(ComponentInstance.VALID));
    // Stop cons
    cons.stop();
    assertThat("ci is invalid", ci.getState(), is(ComponentInstance.INVALID));
    // Restart cons
    cons.start();
    assertThat("ci is valid - 2", ci.getState(), is(ComponentInstance.VALID));
}
Also used : PrimitiveComponentType(org.apache.felix.ipojo.api.PrimitiveComponentType) Test(org.junit.Test)

Example 5 with PrimitiveComponentType

use of org.apache.felix.ipojo.api.PrimitiveComponentType in project felix by apache.

the class ExternalHandlerTest method createAHost.

@Test
public void createAHost() throws Exception {
    PrimitiveComponentType type = createAWhiteboardHost();
    ComponentInstance ci = type.createInstance();
    assertThat(ci.getState(), is(ComponentInstance.VALID));
    HandlerDescription hd = ci.getInstanceDescription().getHandlerDescription(Whiteboard.NAMESPACE + ":" + Whiteboard.NAME);
    assertThat(hd, is(notNullValue()));
}
Also used : HandlerDescription(org.apache.felix.ipojo.architecture.HandlerDescription) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) PrimitiveComponentType(org.apache.felix.ipojo.api.PrimitiveComponentType) Test(org.junit.Test)

Aggregations

PrimitiveComponentType (org.apache.felix.ipojo.api.PrimitiveComponentType)12 Test (org.junit.Test)12 Foo (org.apache.felix.ipojo.runtime.core.api.services.Foo)6 ServiceReference (org.osgi.framework.ServiceReference)3 ComponentInstance (org.apache.felix.ipojo.ComponentInstance)2 HandlerDescription (org.apache.felix.ipojo.architecture.HandlerDescription)2 PlainHelloImpl (org.apache.felix.ipojo.runtime.core.api.components.PlainHelloImpl)1