use of org.apache.felix.dm.impl.ComponentImpl in project felix by apache.
the class ComponentTest method createComponentAddTwoDependenciesMakeBothAvailableAndUnavailableWithCallbacks.
@Test
public void createComponentAddTwoDependenciesMakeBothAvailableAndUnavailableWithCallbacks() {
final Ensure e = new Ensure();
ComponentImpl c = new ComponentImpl();
c.setImplementation(new Object() {
public void add() {
e.step();
}
public void remove() {
e.step();
}
});
SimpleServiceDependency d1 = new SimpleServiceDependency();
d1.setCallbacks("add", "remove");
d1.setRequired(true);
SimpleServiceDependency d2 = new SimpleServiceDependency();
d2.setCallbacks("add", "remove");
d2.setRequired(true);
// start the component, which should become active because there are no
// dependencies yet
c.start();
// now add the dependencies, making the ComponentImpl unavailable
c.add(d1);
c.add(d2);
// make the first dependency available, should have no effect on the
// component
d1.add(new EventImpl());
e.step(1);
// second dependency available, now all the add callbacks should be
// invoked
d2.add(new EventImpl());
e.step(4);
// remove the first dependency, triggering the remove callbacks
d1.remove(new EventImpl());
e.step(7);
// remove the second dependency, should not trigger more callbacks
d2.remove(new EventImpl());
e.step(8);
c.remove(d2);
c.remove(d1);
c.stop();
// still, no more callbacks should have been invoked
e.step(9);
Assert.assertEquals("Component stopped, should be unavailable again", false, c.isAvailable());
}
use of org.apache.felix.dm.impl.ComponentImpl in project felix by apache.
the class ComponentTest method createComponentAddDependencyMakeAvailableAndUnavailableWithCallbacks.
@Test
public void createComponentAddDependencyMakeAvailableAndUnavailableWithCallbacks() {
final Ensure e = new Ensure();
ComponentImpl c = new ComponentImpl();
c.setImplementation(new Object() {
public void add() {
e.step(1);
}
public void remove() {
e.step(3);
}
});
SimpleServiceDependency d1 = new SimpleServiceDependency();
d1.setCallbacks("add", "remove");
d1.setRequired(true);
// add the dependency to the component
c.add(d1);
// start the component
c.start();
// make the dependency available, we expect the add callback
// to be invoked here
d1.add(new EventImpl());
e.step(2);
// remove the dependency, should trigger the remove callback
d1.remove(new EventImpl());
e.step(4);
c.stop();
c.remove(d1);
Assert.assertEquals("Component stopped, should be unavailable again", false, c.isAvailable());
}
use of org.apache.felix.dm.impl.ComponentImpl in project felix by apache.
the class ComponentTest method testAddDependencyFromInitCallback.
@Test
public void testAddDependencyFromInitCallback() {
final Ensure e = new Ensure();
final SimpleServiceDependency d = new SimpleServiceDependency();
d.setRequired(true);
ComponentImpl c = new ComponentImpl();
c.setImplementation(new Object() {
void init(Component c) {
e.step(2);
c.add(d);
}
void start() {
e.step(4);
}
void stop() {
e.step(6);
}
void destroy() {
e.step(7);
}
});
e.step(1);
c.start();
e.step(3);
// NPE?!
d.add(new EventImpl());
e.step(5);
d.remove(new EventImpl());
c.stop();
e.step(8);
}
use of org.apache.felix.dm.impl.ComponentImpl in project felix by apache.
the class ComponentTest method createComponentAddDependencyAndStartComponent.
@Test
public void createComponentAddDependencyAndStartComponent() {
ComponentImpl c = new ComponentImpl();
c.setImplementation(MyComponent.class);
SimpleServiceDependency d = new SimpleServiceDependency();
d.setRequired(true);
c.add(d);
c.start();
Assert.assertEquals("should not be available when started because of missing dependency", false, c.isAvailable());
c.stop();
c.remove(d);
}
use of org.apache.felix.dm.impl.ComponentImpl in project felix by apache.
the class ComponentTest method createComponentStartItAddDependencyAndMakeDependencyAvailable.
@Test
public void createComponentStartItAddDependencyAndMakeDependencyAvailable() {
ComponentImpl c = new ComponentImpl();
c.setImplementation(MyComponent.class);
SimpleServiceDependency d = new SimpleServiceDependency();
d.setRequired(true);
c.start();
c.add(d);
Assert.assertEquals("Component should not be available: it is started but the dependency is not available", false, c.isAvailable());
d.add(new EventImpl());
Assert.assertEquals("dependency is available, component should be too", true, c.isAvailable());
d.remove(new EventImpl());
Assert.assertEquals("dependency is no longer available, component should not be either", false, c.isAvailable());
c.remove(d);
Assert.assertEquals("dependency is removed, component should be available again", true, c.isAvailable());
c.stop();
Assert.assertEquals("Component is stopped, should be unavailable now", false, c.isAvailable());
}
Aggregations