connectExternalRequired no validates.
authorErik Brakkee <erik@brakkee.org>
Sun, 8 Jun 2008 11:48:08 +0000 (11:48 +0000)
committerErik Brakkee <erik@brakkee.org>
Sun, 8 Jun 2008 11:48:08 +0000 (11:48 +0000)
support/general/src/test/java/org/wamblee/test/AssertionUtils.java
system/general/src/main/java/org/wamblee/system/container/Container.java
system/general/src/test/java/org/wamblee/system/container/ContainerTest.java

index 86585f29ed711d7be6488aab78b4cd2882afd72f..07caaa93d8d806a999d4a18749620ef1371cbe41 100644 (file)
@@ -22,6 +22,9 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 import junit.framework.TestCase;
 
 /**
@@ -30,6 +33,8 @@ import junit.framework.TestCase;
  * @author Erik Brakkee
  */
 public final class AssertionUtils {
+       
+       private static final Log LOG = LogFactory.getLog(AssertionUtils.class);
 
     /**
      * Disabled constructor.
@@ -142,6 +147,7 @@ public final class AssertionUtils {
                throw new RuntimeException("No exception occurred");
        } catch (Throwable t) { 
                if ( aType.isInstance(t)) { 
+                       LOG.info("Expected exception occured " + t.getMessage());
                        return; // ok 
                }
                else { 
index 9ef2ae18d817a0e35f8fda0c20c525a29d08775e..e4466d4a3f5b972f6aab3d96c2e6bd510faf0013 100644 (file)
@@ -160,7 +160,24 @@ public class Container extends AbstractComponent<Scope> {
     public void connectExternalRequired(String aComponent, String aRequiredInterface, 
             String aExternalRequiredInterface) {
         checkSealed();
-        // TODO validate
+        Component client = findComponent(aComponent);
+        if ( client == null ) { 
+               throw new SystemAssemblyException(getQualifiedName() + ": No component '" + aComponent + "' in the container");
+        }
+        if ( aRequiredInterface != null ) { 
+               if ( findInterface(client.getRequiredInterfaces(), aRequiredInterface) == null ) { 
+                       throw new SystemAssemblyException(
+                                       getQualifiedName() + ": Component '" + aComponent + "' does not have a required interface named '" 
+                                       + aRequiredInterface + "'");
+               }
+        }
+        if ( aExternalRequiredInterface != null) { 
+               if ( findInterface(getRequiredInterfaces(), aExternalRequiredInterface) == null ) { 
+                       throw new SystemAssemblyException(
+                                       getQualifiedName() + ": container does not have a required interface named '" 
+                                       + aExternalRequiredInterface + "'");
+               }
+        }
         _edgeFilter.add(new ConnectRequiredExternallyRequiredEdgeFilter(
                 aComponent, aRequiredInterface, aExternalRequiredInterface));
     }
index 41ccede4f6cb5c72efcb1cacaf5a1567b0215dd8..f678638843fbacc8e41421bfe54600dd3a5b555b 100644 (file)
@@ -631,6 +631,45 @@ public class ContainerTest extends TestCase {
         assertEquals("y-value", app.getString());
 
     }
+    
+    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() {