return;
}
fail();
-
}
public void testDuplicateComponent() {
fail();
}
+
public void testInconsistentHierarchy() {
try {
Component comp = new Application();
.getProvidedInterfaces()[0]);
container.getRequiredInterfaces()[1].setProvider(env
.getProvidedInterfaces()[1]);
- container.start();
- assertSame(env.getProvidedInterfaces()[0], container
- .getRequiredInterfaces()[0].getProvider());
- assertSame(env.getProvidedInterfaces()[1], container
- .getRequiredInterfaces()[1].getProvider());
- assertSame(env.getProvidedInterfaces()[0], application
- .getRequiredInterfaces()[0].getProvider());
- assertSame(env.getProvidedInterfaces()[1], application
- .getRequiredInterfaces()[1].getProvider());
+ try {
+ container.start();
+ } catch (SystemAssemblyException e) {
+ return;
+ }
+ fail();
}
public void testSealed() {
AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
@Override
public void run() throws Exception {
- container.addRestriction(new InterfaceRestriction() {
- @Override
- public boolean isViolated(Component aClient,
- RequiredInterface aRequired, Component aServer,
- ProvidedInterface aProvided) {
- return false;
- }
- });
+ container.connectRequiredProvided("x", "y", "a", "b");
+ }
+ }, SystemAssemblyException.class);
+ AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
+ @Override
+ public void run() throws Exception {
+ container.connectExternalRequired("x", "y", "a");
+ }
+ }, SystemAssemblyException.class);
+ AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
+ @Override
+ public void run() throws Exception {
+ container.connectExternalProvided("x", "y", "z");
}
}, SystemAssemblyException.class);
AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
Application app = new Application("app");
Container container = new Container("top").addComponent(env1)
.addComponent(env2).addComponent(app);
- container.addRestriction(new DefaultInterfaceRestriction("app", null,
- "env1", null));
+ container.connectRequiredProvided("app", null, "env1", null);
container.start();
assertEquals(env1.getString(), app.getString());
assertFalse(env2.getString().equals(app.getString()));
top.addComponent(envcontainer).addComponent(appcontainer);
top.start();
- AssertionUtils.assertEquals(new String[] { "start.environment", "start.application" },
- _tracker.getEvents(Thread.currentThread()).toArray(
- new String[0]));
+ AssertionUtils.assertEquals(new String[] { "start.environment",
+ "start.application" }, _tracker.getEvents(
+ Thread.currentThread()).toArray(new String[0]));
+
+ }
+
+ public void testNonUniqueRequiredInterface() {
+ final Container container = new Container("top");
+ container.addRequiredInterface(new DefaultRequiredInterface("i",
+ Integer.class));
+ container.addRequiredInterface(new DefaultRequiredInterface("x",
+ String.class));
+ container.addRequiredInterface(new DefaultRequiredInterface("y",
+ String.class));
+
+ Application app = new Application("1");
+ container.addComponent(app);
+
+ AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
+ @Override
+ public void run() throws Exception {
+ container.start();
+ }
+ }, SystemAssemblyException.class);
+
+ container.connectExternalRequired("1", app.getRequiredInterfaces()[0]
+ .getName(), "y");
+
+ ProvidedInterface i = new DefaultProvidedInterface("i", Integer.class);
+ ProvidedInterface x = new DefaultProvidedInterface("x", String.class);
+ ProvidedInterface y = new DefaultProvidedInterface("y", String.class);
+
+ Scope externalScope = new DefaultScope(new ProvidedInterface[0]);
+
+ externalScope.publishInterface(i, 100);
+ externalScope.publishInterface(x, "x-value");
+ externalScope.publishInterface(y, "y-value");
+
+ container.getRequiredInterfaces()[0].setProvider(i);
+ container.getRequiredInterfaces()[1].setProvider(x);
+ container.getRequiredInterfaces()[2].setProvider(y);
+
+ Scope runtime = container.start(externalScope);
+
+ assertEquals("y-value", app.getString());
+
+ }
+
+ public void testNonUniqueProvidedInterface() {
+
+ final Container container = new Container("top")
+ .addProvidedInterface(new DefaultProvidedInterface("external",
+ String.class));
+ Environment env1 = new Environment("env1");
+ Environment env2 = new Environment("env2");
+
+ container.addComponent(env1);
+ container.addComponent(env2);
+
+ AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
+ @Override
+ public void run() throws Exception {
+ container.start();
+ }
+ }, SystemAssemblyException.class);
+
+ // now choose env2
+
+ container.connectExternalProvided(container.getProvidedInterfaces()[0]
+ .getName(), env2.getName(), env2.getProvidedInterfaces()[0]
+ .getName());
+
+ Scope scope = container.start();
+
+ // check the value of the provided interface of the container
+ String value = scope.getInterfaceImplementation(container
+ .getProvidedInterfaces()[0], String.class);
+ assertNotNull(value);
+ assertEquals(value, env2.getString());
+ assertFalse(value.equals(env1.getString()));
}
}