From: erik Date: Sun, 8 Jun 2008 11:48:08 +0000 (+0000) Subject: connectExternalRequired no validates. X-Git-Tag: wamblee-utils-0.2@603~78 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=050ff03da91723fd8ca8bfbd3cf260ac9fdde807;p=utils connectExternalRequired no validates. --- diff --git a/trunk/support/general/src/test/java/org/wamblee/test/AssertionUtils.java b/trunk/support/general/src/test/java/org/wamblee/test/AssertionUtils.java index 86585f29..07caaa93 100644 --- a/trunk/support/general/src/test/java/org/wamblee/test/AssertionUtils.java +++ b/trunk/support/general/src/test/java/org/wamblee/test/AssertionUtils.java @@ -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 { diff --git a/trunk/system/general/src/main/java/org/wamblee/system/container/Container.java b/trunk/system/general/src/main/java/org/wamblee/system/container/Container.java index 9ef2ae18..e4466d4a 100644 --- a/trunk/system/general/src/main/java/org/wamblee/system/container/Container.java +++ b/trunk/system/general/src/main/java/org/wamblee/system/container/Container.java @@ -160,7 +160,24 @@ public class Container extends AbstractComponent { 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)); } diff --git a/trunk/system/general/src/test/java/org/wamblee/system/container/ContainerTest.java b/trunk/system/general/src/test/java/org/wamblee/system/container/ContainerTest.java index 41ccede4..f6786388 100644 --- a/trunk/system/general/src/test/java/org/wamblee/system/container/ContainerTest.java +++ b/trunk/system/general/src/test/java/org/wamblee/system/container/ContainerTest.java @@ -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() {