+ }
+
+ public void testNonUniqueRequiredInterfaceWrongNames() {
+ 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));
+
+ final Application app = new Application("1");
+ container.addComponent(app);
+
+ // wrong component name.
+ AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
+ @Override
+ public void run() throws Exception {
+ container.connectExternalRequired("2", "x", "y");
+ }
+ }, SystemAssemblyException.class);
+
+ // Wrong interface name of component.
+ AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
+ @Override
+ public void run() throws Exception {
+ container.connectExternalRequired("1", app
+ .getRequiredInterfaces().get(0).getName() +
+ "xxx", "y");
+ }
+ }, SystemAssemblyException.class);
+
+ // Wrong external interface name of container
+ AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
+ @Override
+ public void run() throws Exception {
+ container.connectExternalRequired("1", app
+ .getRequiredInterfaces().get(0).getName(), "z");
+ }
+ }, SystemAssemblyException.class);
+ }
+
+ 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()
+ .get(0).getName(), env2.getName(), env2.getProvidedInterfaces()
+ .get(0).getName());
+
+ Scope scope = container.start();
+
+ // check the value of the provided interface of the container
+ String value = scope.getInterfaceImplementation(container
+ .getProvidedInterfaces().get(0), String.class);
+ assertNotNull(value);
+ assertEquals(value, env2.getString());
+ assertFalse(value.equals(env1.getString()));
+ }
+
+ public void testNonUniqueProvidedInterfaceWrongNames() {
+ final Container container = new Container("top")
+ .addProvidedInterface(new DefaultProvidedInterface("external",
+ String.class));
+ final Environment env1 = new Environment("env1");
+ final Environment env2 = new Environment("env2");
+
+ container.addComponent(env1);
+ container.addComponent(env2);
+
+ // Wrong external provided interface name
+ AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
+ @Override
+ public void run() throws Exception {
+ container
+ .connectExternalProvided(container.getProvidedInterfaces()
+ .get(0).getName() +
+ "xx", "env1", env1.getProvidedInterfaces().get(0)
+ .getName());
+ }
+ }, SystemAssemblyException.class);
+
+ // Wrong provided interface name.
+ AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
+ @Override
+ public void run() throws Exception {
+ container.connectExternalProvided(container
+ .getProvidedInterfaces().get(0).getName(), "env1", env1
+ .getProvidedInterfaces().get(0).getName() +
+ "xx");
+ }
+ }, SystemAssemblyException.class);
+
+ // Wrong provided component
+ AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
+ @Override
+ public void run() throws Exception {
+ container.connectExternalProvided(container
+ .getProvidedInterfaces().get(0).getName(), "env3", env1
+ .getProvidedInterfaces().get(0).getName());
+ }
+ }, SystemAssemblyException.class);
+ }
+
+ private static class MyMultiple implements Serializable, Runnable {
+ @Override
+ public void run() {
+ // Empty
+ }