use of org.apache.felix.dm.Component in project felix by apache.
the class AdapterWithoutPropagationTest method testAdapterNoPropagate.
public void testAdapterNoPropagate() {
DependencyManager m = getDM();
// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
// The provider has a "foo=bar" property
Hashtable<String, String> props = new Hashtable<>();
props.put("foo", "bar");
ServiceProvider serviceProvider = new ServiceProvider(e);
Component provider = m.createComponent().setInterface(OriginalService.class.getName(), props).setImplementation(serviceProvider);
// The Adapter will see the "foo=bar" property from the adaptee
Component adapter = m.createAdapterService(OriginalService.class, null, null, null, "set", "change", null, null, false).setInterface(AdaptedService.class.getName(), null).setImplementation(new ServiceAdapter(e));
// The consumer depends on the AdaptedService, but won't see foo=bar property from the adaptee
Component consumer = m.createComponent().setImplementation(new ServiceConsumer(e)).add(m.createServiceDependency().setService(AdaptedService.class).setRequired(true).setCallbacks("set", "change", null));
// add the provider and the adapter
m.add(provider);
m.add(adapter);
// Checks if the adapter has been started and has seen the adaptee properties
e.waitForStep(1, 5000);
// add a consumer that must not see the adaptee service properties
m.add(consumer);
e.waitForStep(2, 5000);
// change the service properties of the provider, and check that the adapter callback instance is caled.
serviceProvider.changeServiceProperties();
e.waitForStep(3, 5000);
// cleanup
m.clear();
}
use of org.apache.felix.dm.Component in project felix by apache.
the class AspectBaseTest method testSingleAspectThatAlreadyExisted.
@SuppressWarnings("serial")
public void testSingleAspectThatAlreadyExisted() {
DependencyManager m = new DependencyManager(context);
// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
// create a service provider and consumer
ServiceProvider p = new ServiceProvider(e, "a");
ServiceConsumer c = new ServiceConsumer(e);
Component sp = m.createComponent().setImplementation(p).setInterface(ServiceInterface.class.getName(), new Hashtable() {
{
put("name", "a");
}
});
Component sc = m.createComponent().setImplementation(c).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true).setCallbacks("add", "remove").setAutoConfig("m_service"));
Component sa = m.createAspectService(ServiceInterface.class, null, 20, null).setImplementation(ServiceAspect.class);
// we first add the aspect
m.add(sa);
// then the service provider
m.add(sp);
// finally the consumer
m.add(sc);
Assert.assertEquals("aa", c.invoke());
// now the consumer's added should be invoked once, as the aspect is already available and should
// directly hide the original service
e.waitForStep(1, 2000);
e.step(2);
m.remove(sa);
// after removing the aspect, the consumer should get the original service back, so
// remove and add will be invoked
e.waitForStep(4, 2000);
Assert.assertEquals("a", c.invoke());
m.remove(sp);
// after removing the original service, the consumer's remove should be called once
e.waitForStep(5, 2000);
m.remove(sc);
e.step(6);
}
use of org.apache.felix.dm.Component in project felix by apache.
the class AspectBaseTest method testMultipleAspects.
@SuppressWarnings("serial")
public void testMultipleAspects() {
DependencyManager m = new DependencyManager(context);
// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
// create service providers and consumers
ServiceConsumer c = new ServiceConsumer(e);
Component sp = m.createComponent().setImplementation(new ServiceProvider(e, "a")).setInterface(ServiceInterface.class.getName(), new Hashtable() {
{
put("name", "a");
}
});
Component sp2 = m.createComponent().setImplementation(new ServiceProvider(e, "b")).setInterface(ServiceInterface.class.getName(), new Hashtable() {
{
put("name", "b");
}
});
Component sc = m.createComponent().setImplementation(c).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true).setCallbacks("add", "remove"));
Component sa = m.createAspectService(ServiceInterface.class, null, 20, null).setImplementation(ServiceAspect.class);
Component sa2 = m.createAspectService(ServiceInterface.class, null, 10, null).setImplementation(ServiceAspect.class);
m.add(sp);
m.add(sp2);
m.add(sa);
m.add(sa2);
m.add(sc);
// the consumer will monitor progress, it should get it's add invoked twice, once for every
// (highest) aspect
e.waitForStep(2, 2000);
e.step(3);
// now invoke all services the consumer collected
List<String> list = c.invokeAll();
// and make sure both of them are correctly invoked
Assert.assertTrue(list.size() == 2);
Assert.assertTrue(list.contains("aaa"));
Assert.assertTrue(list.contains("bbb"));
m.remove(sc);
// removing the consumer now should get its removed method invoked twice
e.waitForStep(5, 2000);
e.step(6);
m.remove(sa2);
m.remove(sa);
m.remove(sp2);
m.remove(sp);
e.step(7);
}
use of org.apache.felix.dm.Component in project felix by apache.
the class AspectChainTest method testBuildAspectChain.
public void testBuildAspectChain() {
DependencyManager m = getDM();
// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
// create a service provider and consumer
Component sp = m.createComponent().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(), null);
Component sc = m.createComponent().setImplementation(new ServiceConsumer(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true));
Component sa2 = m.createAspectService(ServiceInterface.class, null, 20, null).setImplementation(new ServiceAspect(e, 3));
Component sa3 = m.createAspectService(ServiceInterface.class, null, 30, null).setImplementation(new ServiceAspect(e, 2));
Component sa1 = m.createAspectService(ServiceInterface.class, null, 10, null).setImplementation(new ServiceAspect(e, 4));
m.add(sc);
m.add(sp);
m.add(sa2);
m.add(sa3);
m.add(sa1);
e.step();
e.waitForStep(5, 5000);
m.remove(sa3);
m.remove(sa2);
m.remove(sa1);
m.remove(sp);
m.remove(sc);
}
use of org.apache.felix.dm.Component in project felix by apache.
the class AspectServiceDependencyTest method testServiceRegistrationAndConsumption.
public void testServiceRegistrationAndConsumption() {
DependencyManager m = getDM();
// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
// create a service provider and consumer
Component sp = m.createComponent().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(), null);
Component sc = m.createComponent().setImplementation(new ServiceConsumer(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setCallbacks("add", "remove").setRequired(true));
Component asp = m.createAspectService(ServiceInterface.class, null, 100).setImplementation(ServiceProviderAspect.class);
m.add(sp);
m.add(sc);
m.add(asp);
m.remove(asp);
m.remove(sc);
m.remove(sp);
// ensure we executed all steps inside the component instance
e.step(8);
}
Aggregations