From af8438e4843b838b2c21aa2e46f5e2f8767efb62 Mon Sep 17 00:00:00 2001 From: erik Date: Sun, 8 Jun 2008 11:48:08 +0000 Subject: [PATCH] connectExternalRequired no validates. --- .../java/org/wamblee/test/AssertionUtils.java | 6 +++ .../wamblee/system/container/Container.java | 19 ++++++++- .../system/container/ContainerTest.java | 39 +++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/support/general/src/test/java/org/wamblee/test/AssertionUtils.java b/support/general/src/test/java/org/wamblee/test/AssertionUtils.java index 86585f29..07caaa93 100644 --- a/support/general/src/test/java/org/wamblee/test/AssertionUtils.java +++ b/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/system/general/src/main/java/org/wamblee/system/container/Container.java b/system/general/src/main/java/org/wamblee/system/container/Container.java index 9ef2ae18..e4466d4a 100644 --- a/system/general/src/main/java/org/wamblee/system/container/Container.java +++ b/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/system/general/src/test/java/org/wamblee/system/container/ContainerTest.java b/system/general/src/test/java/org/wamblee/system/container/ContainerTest.java index 41ccede4..f6786388 100644 --- a/system/general/src/test/java/org/wamblee/system/container/ContainerTest.java +++ b/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() { -- 2.31.1