(no commit message)
[utils] / system / general / src / test / java / org / wamblee / system / container / ContainerTest.java
index c4f64ba88eee53a6651bb1b7b0ee46c2cfa31e65..cc18db2e50bac0a1c11fe3886fc10583db8e393c 100644 (file)
@@ -527,4 +527,76 @@ public class ContainerTest extends TestCase {
                 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()));
+    }
 }