@RunWith(PaxExam.class)
public class AdapterAndConsumerTest extends TestBase {
@Test
public void testServiceWithAdapterAndConsumer() {
DependencyManager m = new DependencyManager(context);
// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
Component provider = m.createComponent()
.setInterface(OriginalService.class.getName(), null)
.setImplementation(new ServiceProvider(e));
Component consumer = m.createComponent()
.setImplementation(new ServiceConsumer(e))
.add(m.createServiceDependency()
.setService(AdaptedService.class)
.setRequired(true)
);
Component adapter = m.createAdapterService(OriginalService.class, null)
.setInterface(AdaptedService.class.getName(), null)
.setImplementation(ServiceAdapter.class);
// add the provider and the adapter
m.add(provider);
m.add(adapter);
// add a consumer that will invoke the adapter
// which will in turn invoke the original provider
m.add(consumer);
// now validate that both have been invoked in the right order
e.waitForStep(2, 5000);
// remove the provider again
m.remove(provider);
// ensure that the consumer is stopped
e.waitForStep(3, 5000);
// remove adapter and consumer
m.remove(adapter);
m.remove(consumer);
}