*/
package org.wamblee.system.container;
-import static org.mockito.Matchers.*;
-import static org.mockito.Mockito.*;
-
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
public class ContainerTest extends TestCase {
- private EventTracker<String> _tracker;
+ private EventTracker<String> tracker;
@Override
protected void setUp() throws Exception {
super.setUp();
- _tracker = new EventTracker<String>();
+ tracker = new EventTracker<String>();
}
private static class MyMultiple implements Serializable, Runnable {
}
public void testEnvironmentApplication() {
- Environment environment = new Environment(_tracker);
- Application application = new Application(_tracker);
+ Environment environment = new Environment(tracker);
+ Application application = new Application(tracker);
Container container = new Container("root", new Component[] {
environment, application }, new ProvidedInterface[0],
new RequiredInterface[0]);
Scope scope = container.start();
assertTrue(container.isSealed());
AssertionUtils.assertEquals(new String[] { "start.environment",
- "start.application" }, _tracker.getEvents(
+ "start.application" }, tracker.getEvents(
Thread.currentThread()).toArray(new String[0]));
assertEquals(0, scope.getProvidedInterfaces().size());
}
public void testEnvironmentApplicationSimpleConstructor() {
- Environment environment = new Environment(_tracker);
- Application application = new Application(_tracker);
+ Environment environment = new Environment(tracker);
+ Application application = new Application(tracker);
Container container = new Container("root").addComponent(environment)
.addComponent(application);
Scope scope = container.start();
AssertionUtils.assertEquals(new String[] { "start.environment",
- "start.application" }, _tracker.getEvents(
+ "start.application" }, tracker.getEvents(
Thread.currentThread()).toArray(new String[0]));
assertEquals(0, scope.getProvidedInterfaces().size());
}
public void testComposite() {
- Component<?> environment = new Environment(_tracker);
- Component<?> application = new Application(_tracker);
- assertEquals(0, _tracker.getEventCount());
+ Component<?> environment = new Environment(tracker);
+ Component<?> application = new Application(tracker);
+ assertEquals(0, tracker.getEventCount());
Container system = new Container("all", new Component[] { environment,
application }, new ProvidedInterface[0],
assertEquals(0, provided.size());
AssertionUtils.assertEquals(new String[] { "start.environment",
- "start.application" }, _tracker.getEvents(
+ "start.application" }, tracker.getEvents(
Thread.currentThread()).toArray(new String[0]));
- _tracker.clear();
+ tracker.clear();
system.stop(runtime);
AssertionUtils.assertEquals(new String[] { "stop.application",
- "stop.environment" }, _tracker
+ "stop.environment" }, tracker
.getEvents(Thread.currentThread()).toArray(new String[0]));
}
public void testEnvironmentApplicationRollbackOnException()
throws Exception {
- Environment environment = new Environment(_tracker);
+ Environment environment = new Environment(tracker);
Application application = new Application() {
@Override
public Object doStart(Scope aScope) {
container.start();
} catch (RuntimeException e) {
AssertionUtils.assertEquals(new String[] { "start.environment",
- "stop.environment" }, _tracker.getEvents(
+ "stop.environment" }, tracker.getEvents(
Thread.currentThread()).toArray(new String[0]));
return;
}
public void testEnvironmentApplicationRollbackOnExceptionWithExceptionOnStop()
throws Exception {
- Environment environment = new Environment(_tracker);
+ Environment environment = new Environment(tracker);
// Application 1 will throw an exception while stopping.
Application application1 = new Application("app1") {
@Override
container.start();
} catch (RuntimeException e) {
AssertionUtils.assertEquals(new String[] { "start.environment",
- "stop.environment" }, _tracker.getEvents(
+ "stop.environment" }, tracker.getEvents(
Thread.currentThread()).toArray(new String[0]));
return;
}
}
public void testProvidedInterfaces() {
- Environment env = new Environment(_tracker);
+ Environment env = new Environment(tracker);
Container envcontainer = new Container("0").addComponent(env)
.addProvidedInterface(
new DefaultProvidedInterface("string", String.class))
Scope scope = envcontainer.start();
AssertionUtils.assertEquals(new String[] { "start.environment" },
- _tracker.getEvents(Thread.currentThread()).toArray(
+ tracker.getEvents(Thread.currentThread()).toArray(
new String[0]));
envcontainer.stop(scope);
}
public void testCoupleTwoContainers() {
- Environment env = new Environment(_tracker);
+ Environment env = new Environment(tracker);
Container envcontainer = new Container("0").addComponent(env)
.addProvidedInterface(
new DefaultProvidedInterface("string", String.class))
.addProvidedInterface(
new DefaultProvidedInterface("integer", Integer.class));
- Application app = new Application(_tracker);
+ Application app = new Application(tracker);
Container appcontainer = new Container("1").addComponent(app)
.addRequiredInterface(
new DefaultRequiredInterface("string", String.class))
top.start();
AssertionUtils.assertEquals(new String[] { "start.environment",
- "start.application" }, _tracker.getEvents(
+ "start.application" }, tracker.getEvents(
Thread.currentThread()).toArray(new String[0]));
}