use of org.apache.felix.dm.Component in project felix by apache.
the class AutoConfigTest method testField.
public void testField() throws Exception {
final DependencyManager dm = getDM();
// Create a consumer, depending on some providers (autoconfig field).
ConsumeWithProviderField consumer = new ConsumeWithProviderField();
Component c = createConsumer(dm, consumer);
// Create two providers
Component p1 = createProvider(dm, 10, new Provider() {
public String toString() {
return "provider1";
}
public void run() {
m_ensure.step();
}
});
Component p2 = createProvider(dm, 20, new Provider() {
public String toString() {
return "provider2";
}
public void run() {
m_ensure.step();
}
});
// add the two providers
dm.add(p2);
dm.add(p1);
// add the consumer, which should have been injected with provider2 (highest rank)
dm.add(c);
m_ensure.waitForStep(1, 5000);
// remove the provider2, the consumer should now be injected with provider1
dm.remove(p2);
Assert.assertNotNull(consumer.getProvider());
Assert.assertEquals("provider1", consumer.getProvider().toString());
// remove the provider1, the consumer should have been stopped
dm.remove(p1);
m_ensure.waitForStep(2, 5000);
dm.clear();
}
use of org.apache.felix.dm.Component in project felix by apache.
the class BundleAdapterTest method testBundleAdapter.
public void testBundleAdapter() {
DependencyManager m = getDM();
// create a bundle adapter service (one is created for each bundle)
Component adapter = m.createBundleAdapterService(Bundle.INSTALLED | Bundle.RESOLVED | Bundle.ACTIVE, null, false).setImplementation(BundleAdapter.class).setInterface(BundleAdapter.class.getName(), null);
// create a service provider and consumer
Consumer c = new Consumer();
Component consumer = m.createComponent().setImplementation(c).add(m.createServiceDependency().setService(BundleAdapter.class).setCallbacks("add", "remove"));
// add the bundle adapter
m.add(adapter);
// add the service consumer
m.add(consumer);
// check if at least one bundle was found
c.check();
// remove the consumer again
m.remove(consumer);
// check if all bundles were removed correctly
c.doubleCheck();
// remove the bundle adapter
m.remove(adapter);
}
use of org.apache.felix.dm.Component in project felix by apache.
the class BundleAdapterTest method testBundleAdapterWithCallbackInstance.
public void testBundleAdapterWithCallbackInstance() {
DependencyManager m = getDM();
// create a bundle adapter service (one is created for each bundle)
BundleAdapterWithCallback baWithCb = new BundleAdapterWithCallback();
BundleAdapterCallbackInstance cbInstance = new BundleAdapterCallbackInstance(baWithCb);
Component adapter = m.createBundleAdapterService(Bundle.INSTALLED | Bundle.RESOLVED | Bundle.ACTIVE, null, false, cbInstance, "add", null, "remove").setImplementation(baWithCb).setInterface(BundleAdapter.class.getName(), null);
// create a service provider and consumer
Consumer c = new Consumer();
Component consumer = m.createComponent().setImplementation(c).add(m.createServiceDependency().setService(BundleAdapter.class).setCallbacks("add", "remove"));
// add the bundle adapter
m.add(adapter);
// add the service consumer
m.add(consumer);
// check if at least one bundle was found
c.check();
// remove the consumer again
m.remove(consumer);
// check if all bundles were removed correctly
c.doubleCheck();
// remove the bundle adapter
m.remove(adapter);
}
use of org.apache.felix.dm.Component in project felix by apache.
the class BundleAdapterWithCallbacksNotAutoConfiguredTest method testBundleAdapterWithCallbacksNotAutoConfigured.
public void testBundleAdapterWithCallbacksNotAutoConfigured() {
DependencyManager m = getDM();
// create a bundle adapter service (one is created for each bundle)
BundleAdapterWithCallback baWithCb = new BundleAdapterWithCallback();
String bsn = "org.apache.felix.dependencymanager";
String filter = "(Bundle-SymbolicName=" + bsn + ")";
Component adapter = m.createBundleAdapterService(Bundle.ACTIVE, filter, false, null, "add", null, null).setImplementation(baWithCb);
// add the bundle adapter
m.add(adapter);
// Check if adapter has not been auto configured (because it has callbacks defined).
m_e.waitForStep(1, 3000);
Assert.assertNull("bundle adapter must not be auto configured", baWithCb.getBundle());
// remove the bundle adapters
m.remove(adapter);
}
use of org.apache.felix.dm.Component in project felix by apache.
the class BundleDependencyTest method testRequiredBundleDependency.
public void testRequiredBundleDependency() {
DependencyManager m = getDM();
// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
Component consumerWithFilter = m.createComponent().setImplementation(new FilteredConsumerRequired(e)).add(m.createBundleDependency().setRequired(true).setFilter("(Bundle-SymbolicName=" + BSN + ")").setCallbacks("add", "remove"));
// add a consumer with a filter
m.add(consumerWithFilter);
e.waitForStep(1, 5000);
// remove the consumer again
m.remove(consumerWithFilter);
e.waitForStep(2, 5000);
}
Aggregations