import junit.framework.TestCase;
-import org.easymock.classextension.ConstructorArgs;
-import org.easymock.classextension.EasyMock;
-import org.easymock.classextension.IMocksControl;
import org.wamblee.general.Pair;
import org.wamblee.system.core.Component;
import org.wamblee.system.core.DefaultProvidedInterface;
import org.wamblee.system.core.StringComponent;
import org.wamblee.system.core.SystemAssemblyException;
import org.wamblee.test.AssertionUtils;
-import org.wamblee.test.EasyMockMatchers;
import org.wamblee.test.EventTracker;
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 {
- IMocksControl control = EasyMock.createStrictControl();
-
- Environment environment = new Environment(_tracker);
- Application application = control.createMock(Application.class,
- new ConstructorArgs(Application.class.getConstructor()),
- Application.class.getDeclaredMethod("doStart", Scope.class));
-
- application.doStart(EasyMockMatchers.anyObject(Scope.class));
- EasyMock.expectLastCall().andThrow(new RuntimeException());
- control.replay();
-
+ Environment environment = new Environment(tracker);
+ Application application = new Application() {
+ @Override
+ public Object doStart(Scope aScope) {
+ throw new RuntimeException();
+ }
+ };
+
try {
Container container = new Container("root", new Component[] {
environment, application }, new ProvidedInterface[0],
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 {
- IMocksControl control = EasyMock.createControl();
- Environment environment = new Environment(_tracker);
+ Environment environment = new Environment(tracker);
// Application 1 will throw an exception while stopping.
- Application application1 = control.createMock(Application.class,
- new ConstructorArgs(Application.class.getConstructor()),
- Application.class.getDeclaredMethod("doStop", Object.class));
-
- application1.doStop(EasyMock.anyObject());
- EasyMock.expectLastCall().andThrow(new RuntimeException());
+ Application application1 = new Application("app1") {
+ @Override
+ public void doStop(Object aRuntime) {
+ throw new RuntimeException();
+ }
+ };
// application 2 will throw an exception while starting
- Application application2 = control.createMock(Application.class,
- new ConstructorArgs(Application.class
- .getConstructor(String.class), "application2"),
- Application.class.getDeclaredMethod("doStart", Scope.class));
-
- application2.doStart(EasyMockMatchers.anyObject(Scope.class));
- EasyMock.expectLastCall().andThrow(new RuntimeException());
-
- control.replay();
+ Application application2 = new Application("app2") {
+ public Object doStart(Scope aScope) {
+ throw new RuntimeException();
+ }
+ };
try {
Container container = new Container("root", new Component[] {
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]));
}