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));
}
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));
}
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));
}
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));
}
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()));
}
Aggregations