import java.util.Map;
import java.util.Set;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import junit.framework.TestCase;
/**
* @author Erik Brakkee
*/
public final class AssertionUtils {
+
+ private static final Log LOG = LogFactory.getLog(AssertionUtils.class);
/**
* Disabled constructor.
throw new RuntimeException("No exception occurred");
} catch (Throwable t) {
if ( aType.isInstance(t)) {
+ LOG.info("Expected exception occured " + t.getMessage());
return; // ok
}
else {
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));
}
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() {