the Container and filtering edges at the graph level. Filtering at graph level is more generic since it allows filtering of any edge (also required -> external required and external provided -> provided).
+++ /dev/null
-/*
- * Copyright 2008 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.wamblee.system.container;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.wamblee.system.core.Component;
-import org.wamblee.system.core.ProvidedInterface;
-import org.wamblee.system.core.RequiredInterface;
-
-
-/**
- * Composite restriction that wraps a number of other restrictions. The restriction is
- * violated if one of the contained restrictions is violated.
- *
- * @author Erik Brakkee
- *
- */
-public class CompositeInterfaceRestriction implements InterfaceRestriction {
-
- private List<InterfaceRestriction> _restrictions;
-
- /**
- * Constructs the restriction.
- */
- public CompositeInterfaceRestriction() {
- _restrictions = new ArrayList<InterfaceRestriction>();
- }
-
- /**
- * Constructs the restriction.
- * @param aRestrictions List of contained restrictions.
- */
- public CompositeInterfaceRestriction(Collection<InterfaceRestriction> aRestrictions) {
- this();
- _restrictions.addAll(aRestrictions);
- }
-
- /**
- * Adds a restriction.
- * @param aRestriction Restriction.
- * @return Reference to this composite restriction to allow call chaining.
- */
- public CompositeInterfaceRestriction add(InterfaceRestriction aRestriction) {
- _restrictions.add(aRestriction);
- return this;
- }
-
- @Override
- public boolean isViolated(Component aClient, RequiredInterface aRequired,
- Component aServer, ProvidedInterface aProvided) {
- for (InterfaceRestriction restriction: _restrictions) {
- if ( restriction.isViolated(aClient, aRequired, aServer, aProvided)) {
- return true;
- }
- }
- return false;
- }
-
-}
import org.wamblee.system.core.RequiredInterface;
import org.wamblee.system.core.Scope;
import org.wamblee.system.core.SystemAssemblyException;
+import org.wamblee.system.graph.CompositeEdgeFilter;
+import org.wamblee.system.graph.EdgeFilter;
import org.wamblee.system.graph.component.ComponentGraph;
+import org.wamblee.system.graph.component.ConnectRequiredProvidedEdgeFilter;
+import org.wamblee.system.graph.component.RequiredProvidedEdgeFactory;
/**
* Container consisting of multiple components.
private List<Component> _components;
private Set<String> _componentNames;
- private CompositeInterfaceRestriction _restriction;
+ private CompositeEdgeFilter _edgeFilter;
private boolean _sealed;
/**
_components = new ArrayList<Component>();
_componentNames = new HashSet<String>();
- _restriction = new CompositeInterfaceRestriction();
+ _edgeFilter = new CompositeEdgeFilter();
_sealed = false;
for (Component component : aComponents) {
addComponent(component);
aComponent.addContext(getQualifiedName());
return this;
}
-
+
/**
- * Adds an interface restriction for explicitly configuring the relations
- * between components.
- *
- * @param aRestriction
- * Restriction to add.
- * @return Reference to this to allow call chaining.
+ * Explictly connects required and provided interfaces.
+ * @param aClientComponent Client component, may not be null.
+ * @param aRequiredInterface Required interface. If null it means all required interfaces.
+ * @param aServerComponent Server component to connect to. If null, it means that no server components
+ * may be connected to and the provider of the required interface will be null.
+ * @param aProvidedInterface Provided interface. If null, it means that there is no restriction on the
+ * name of the provided interface and that it is automatically selected.
*/
- public Container addRestriction(InterfaceRestriction aRestriction) {
+ public void connectRequiredProvided(String aClientComponent, String aRequiredInterface,
+ String aServerComponent, String aProvidedInterface) {
checkSealed();
- _restriction.add(aRestriction);
- return this;
+ _edgeFilter.add(new ConnectRequiredProvidedEdgeFilter(aClientComponent, aRequiredInterface, aServerComponent, aProvidedInterface));
+ }
+
+ public void connectExternalRequired(String aComponent, String aRequiredInterface,
+ String aExternalRequiredInterface) {
+ checkSealed();
+ // TODO implement.
+ throw new RuntimeException("not implemented");
+ }
+
+ public void connectExternalProvided(String aExternalProvided, String aComponent, String aProvidedInterface) {
+ checkSealed();
+ // TODO implement.
+ throw new RuntimeException("not implemented");
}
+
@Override
public Container addProvidedInterface(ProvidedInterface aProvided) {
checkSealed();
graph.addProvidedInterface(this, prov);
}
- graph.addRestriction(_restriction);
+ graph.addEdgeFilter(_edgeFilter);
return graph;
}
+++ /dev/null
-/*
- * Copyright 2008 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.wamblee.system.container;
-
-import org.wamblee.system.core.Component;
-import org.wamblee.system.core.ProvidedInterface;
-import org.wamblee.system.core.RequiredInterface;
-
-/**
- * An interface restriction on the required interface of a component.
- *
- * @author Erik Brakkee
- *
- */
-public class DefaultInterfaceRestriction implements InterfaceRestriction {
-
- private String _client;
- private String _required;
- private String _server;
- private String _provided;
-
- /**
- * Constructs the restriction. If the client name and required interface
- * name match, then the server name and interface name must also match.
- * Otherwise the restriction is violated.
- *
- * This can be used to explicitly connect required and provided interfaces
- * of components.
- *
- * @param aClient
- * Client or null if no restriction on the client.
- * @param aRequired
- * Required interface name or null if no restriction on the
- * required interface.
- * @param aServer
- * Server or null if no restriction on the server.
- * @param aProvided
- * Provided interface name or null if no restriction on the
- * provided interface.
- */
- public DefaultInterfaceRestriction(String aClient, String aRequired,
- String aServer, String aProvided) {
-
- if ( aClient == null && aRequired == null ) {
- throw new IllegalArgumentException("No restriction on the required interface");
- }
- if ( aServer == null && aProvided == null ) {
- throw new IllegalArgumentException("No restriction on the provided interface");
- }
- _client = aClient;
- _required = aRequired;
- _server = aServer;
- _provided = aProvided;
- }
-
- @Override
- public boolean isViolated(Component aClient, RequiredInterface aRequired,
- Component aServer, ProvidedInterface aProvided) {
-
- if ( _client != null && !aClient.getName().equals(_client)) {
- return false;
- }
- if ( _required != null && !aRequired.getName().equals(_required)) {
- return false;
- }
-
- // The required interface matches
-
- if ( _server != null && !aServer.getName().equals(_server)) {
- // Server was specified and does not match.
- return true;
- }
- if ( _provided != null && !aProvided.getName().equals(_provided)) {
- // provided interface was specified and doe not match.
- return true;
- }
-
- // The required and provided interfaces match so this is not a violation.
-
- return false;
- }
-
-}
+++ /dev/null
-/*
- * Copyright 2008 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.wamblee.system.container;
-
-import org.wamblee.system.core.Component;
-import org.wamblee.system.core.ProvidedInterface;
-import org.wamblee.system.core.RequiredInterface;
-
-/**
- * Interface restriction for restricting the linking of provided and required
- * interfaces.
- *
- * @author Erik Brakkee
- *
- */
-public interface InterfaceRestriction {
-
- /**
- * Checks if connecting the given provided and required interface would violate
- * the restriction.
- *
- * @param aClient Client component requiring an interface.
- * @param aRequired Required interface.
- * @param aServer Server component providing an interface.
- * @param aProvided Provided interface.
- */
- boolean isViolated(Component aClient, RequiredInterface aRequired,
- Component aServer, ProvidedInterface aProvided);
-}
public String toString() {
return getQualifiedName();
}
+
+ public ProvidedInterface findProvidedInterface(String aName) {
+ for (ProvidedInterface provided: getProvidedInterfaces()) {
+ if ( provided.getName().equals(aName)) {
+ return provided;
+ }
+ }
+ return null;
+ }
+
+ public RequiredInterface findRequiredInterface(String aName) {
+ for (RequiredInterface required: getRequiredInterfaces()) {
+ if ( required.getName().equals(aName)) {
+ return required;
+ }
+ }
+ return null;
+ }
}
--- /dev/null
+/*
+ * Copyright 2008 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.system.graph;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class CompositeEdgeFilter implements EdgeFilter {
+
+ private List<EdgeFilter> _filters;
+
+ public CompositeEdgeFilter() {
+ _filters = new ArrayList<EdgeFilter>();
+ }
+
+ public void add(EdgeFilter aFilter) {
+ _filters.add(aFilter);
+ }
+
+ @Override
+ public boolean isViolated(Edge aEdge) {
+ for (EdgeFilter filter: _filters) {
+ if ( filter.isViolated(aEdge) ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright 2008 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.system.graph;
+
+public interface EdgeFilter {
+
+ boolean isViolated(Edge aEdge);
+}
--- /dev/null
+/*
+ * Copyright 2008 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.system.graph;
+
+public class EdgeSelector<FromType extends Node, ToType extends Node> {
+
+ public static interface Selector<FromType extends Node, ToType extends Node> {
+ void execute(FromType aFrom, ToType aTo);
+ }
+
+ private Class<FromType> _fromType;
+ private Class<ToType> _toType;
+
+ public EdgeSelector(Class<FromType> aFrom, Class<ToType> aTo) {
+ _fromType = aFrom;
+ _toType = aTo;
+ }
+
+ public void execute(Selector<FromType,ToType> aSelector, Edge aEdge) {
+ if ( _fromType.isInstance(aEdge.getFrom()) && _toType.isInstance(aEdge.getTo())) {
+ aSelector.execute((FromType)aEdge.getFrom(), (ToType)aEdge.getTo());
+ }
+ }
+}
package org.wamblee.system.graph;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
/**
}
}
}
+
+ /**
+ * Applies a filter to the graph for removing elements.
+ * @param aFilter Filter to apply.
+ */
+ public void applyFilter(EdgeFilter aFilter) {
+ for (Iterator<Edge> edge = _edges.iterator(); edge.hasNext(); ) {
+ if (aFilter.isViolated(edge.next())) {
+ edge.remove();
+ }
+ }
+ }
/**
* Finds all outgoing edges of a node. More specifically, finds
+++ /dev/null
-/*
- * Copyright 2008 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.wamblee.system.graph.component;
-
-import java.util.List;
-
-import org.wamblee.system.container.InterfaceRestriction;
-import org.wamblee.system.core.Component;
-import org.wamblee.system.graph.Edge;
-import org.wamblee.system.graph.Graph;
-import org.wamblee.system.graph.Node;
-import org.wamblee.system.graph.Visitor;
-
-/**
- * Applies restrictions on a graph by removing all edges that violate the restriction.
- *
- * @author Erik Brakkee.
- *
- */
-public class ApplyRestrictionsVisitor implements Visitor {
-
- private Graph _graph;
- private InterfaceRestriction _restriction;
-
- /**
- * Constructs the visitor.
- * @param aGraph Graph.
- * @param aRestriction Restriction.
- */
- public ApplyRestrictionsVisitor(Graph aGraph, InterfaceRestriction aRestriction) {
- _graph = aGraph;
- _restriction = aRestriction;
- }
-
- @Override
- public void visitEdge(Edge aEdge) {
- if ( aEdge.getFrom() instanceof RequiredInterfaceNode &&
- aEdge.getTo() instanceof ProvidedInterfaceNode) {
- RequiredInterfaceNode from = (RequiredInterfaceNode)aEdge.getFrom();
- ProvidedInterfaceNode to = (ProvidedInterfaceNode) aEdge.getTo();
-
- if ( _restriction.isViolated(from.getComponent(), from.getRequired(), to.getComponent(), to.getProvided())) {
- _graph.removeEdge(aEdge);
- }
- }
- }
-
- @Override
- public void visitNode(Node aNode) {
- // Empty
- }
-
-}
import java.util.List;
import org.wamblee.general.Pair;
-import org.wamblee.system.container.CompositeInterfaceRestriction;
-import org.wamblee.system.container.InterfaceRestriction;
import org.wamblee.system.core.Component;
import org.wamblee.system.core.ProvidedInterface;
import org.wamblee.system.core.RequiredInterface;
+import org.wamblee.system.graph.CompositeEdgeFilter;
import org.wamblee.system.graph.DefaultEdge;
import org.wamblee.system.graph.Edge;
import org.wamblee.system.graph.Graph;
*/
public class ComponentGraph extends Graph {
- private CompositeInterfaceRestriction _restriction;
+ private CompositeEdgeFilter _edgeFilter;
/**
* Constructs an empty component graph.
*/
public ComponentGraph() {
- _restriction = new CompositeInterfaceRestriction();
- }
-
- /**
- * Adds a restriction that must be satisfied by the component model.
- * @param aRestriction Restriction.
- */
- public void addRestriction(InterfaceRestriction aRestriction) {
- _restriction.add(aRestriction);
+ _edgeFilter = new CompositeEdgeFilter();
}
/**
*/
public void validate() {
extend(new RequiredProvidedEdgeFactory());
- accept(new ApplyRestrictionsVisitor(this, _restriction));
+ applyFilter(_edgeFilter);
accept(new CheckRequiredProvidedMultiplicityVisitor(this));
accept(new CheckExternallyRequiredVisitor(this));
accept(new CheckExternallyProvidedVisitor(this));
addEdge(new DefaultEdge(provNode, compNode));
}
}
+
+ public void addEdgeFilter(CompositeEdgeFilter aEdgeFilter) {
+ _edgeFilter.add(aEdgeFilter);
+ }
}
--- /dev/null
+/*
+ * Copyright 2008 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.system.graph.component;
+
+import org.wamblee.system.graph.Edge;
+import org.wamblee.system.graph.EdgeFilter;
+import org.wamblee.system.graph.EdgeSelector;
+import org.wamblee.system.graph.Node;
+
+/**
+ * Filter used to explicitly connect required and provided interfaces within a
+ * container.
+ *
+ * @author Erik Brakkee
+ *
+ */
+public class ConnectRequiredProvidedEdgeFilter implements EdgeFilter {
+
+ private String _client;
+ private String _required;
+ private String _server;
+ private String _provided;
+
+ public ConnectRequiredProvidedEdgeFilter(String aClient, String aRequired,
+ String aServer, String aProvided) {
+ _client = aClient;
+ _required = aRequired;
+ _server = aServer;
+ _provided = aProvided;
+ if ( _client == null ) {
+ throw new IllegalArgumentException("Client component must be specified");
+ }
+ }
+
+ @Override
+ public boolean isViolated(Edge aEdge) {
+ if (aEdge.getFrom() instanceof RequiredInterfaceNode
+ && aEdge.getTo() instanceof ProvidedInterfaceNode) {
+ return isViolated((RequiredInterfaceNode) aEdge.getFrom(),
+ (ProvidedInterfaceNode) aEdge.getTo());
+ }
+ return false;
+ }
+
+ private boolean isViolated(RequiredInterfaceNode aFrom,
+ ProvidedInterfaceNode aTo) {
+ if (_client.equals(aFrom.getComponent().getName())
+ && (_required == null || _required.equals(aFrom.getRequired()
+ .getName()))) {
+ // From part matches.
+ if ( _server == null ) {
+ return true; // all connections are eliminated
+ }
+ if (_server.equals(aTo.getComponent().getName())
+ && (_provided == null || _provided.equals(aTo.getProvided()
+ .getName()))) {
+ // to part matches also
+ return false;
+ }
+ else {
+ // From matches and to doesn't so edgefilter is violated.
+ return true;
+ }
+ } else {
+ // From part does not match, restriction does not apply.
+ return false;
+ }
+ }
+}
AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
@Override
public void run() throws Exception {
- container.addRestriction(new InterfaceRestriction() {
- @Override
- public boolean isViolated(Component aClient,
- RequiredInterface aRequired, Component aServer,
- ProvidedInterface aProvided) {
- return false;
- }
- });
+ container.connectRequiredProvided("x", "y", "a", "b");
+ }
+ }, SystemAssemblyException.class);
+ AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
+ @Override
+ public void run() throws Exception {
+ container.connectExternalRequired("x", "y", "a");
+ }
+ }, SystemAssemblyException.class);
+ AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
+ @Override
+ public void run() throws Exception {
+ container.connectExternalProvided("x", "y", "z");
}
}, SystemAssemblyException.class);
AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
Application app = new Application("app");
Container container = new Container("top").addComponent(env1)
.addComponent(env2).addComponent(app);
- container.addRestriction(new DefaultInterfaceRestriction("app", null,
- "env1", null));
+ container.connectRequiredProvided("app", null, "env1", null);
container.start();
assertEquals(env1.getString(), app.getString());
assertFalse(env2.getString().equals(app.getString()));
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.wamblee.system.container;
-
-import static org.easymock.EasyMock.anyObject;
+package org.wamblee.system.graph;
import java.util.Arrays;
import org.easymock.classextension.EasyMock;
import org.easymock.classextension.IMocksControl;
+import static org.easymock.classextension.EasyMock.*;
+import org.wamblee.system.container.Application;
import org.wamblee.system.core.Component;
import org.wamblee.system.core.Environment;
import org.wamblee.system.core.ProvidedInterface;
import org.wamblee.system.core.RequiredInterface;
+import org.wamblee.system.graph.component.ProvidedInterfaceNode;
+import org.wamblee.system.graph.component.RequiredInterfaceNode;
-public class CompositeInterfaceRestrictionTest extends TestCase {
-
+public class CompositeEdgeFilterTest extends TestCase {
private Application _app = new Application();
- private Environment _env = new Environment();
+ private Environment _env = new Environment();
+
+ private Edge createEdge(Component aClient, RequiredInterface aRequired,
+ Component aServer, ProvidedInterface aProvided) {
+ Node from = new RequiredInterfaceNode(aClient, aRequired);
+ Node to = new ProvidedInterfaceNode(aServer, aProvided);
+ return new DefaultEdge(from, to);
+ }
public void testEmpty() {
- InterfaceRestriction restriction = new CompositeInterfaceRestriction();
- assertFalse(restriction.isViolated(_app, _app.getRequiredInterfaces()[0],
- _env, _env.getProvidedInterfaces()[0]));
+ EdgeFilter restriction = new CompositeEdgeFilter();
+ assertFalse(restriction.isViolated(createEdge(_app, _app.getRequiredInterfaces()[0],
+ _env, _env.getProvidedInterfaces()[0])));
}
- private void configureRestriction(InterfaceRestriction base, boolean aResult) {
- base.isViolated(
- (Component)anyObject(),
- (RequiredInterface)anyObject(),
- (Component)anyObject(),
- (ProvidedInterface)anyObject());
+ private void configureRestriction(EdgeFilter base, boolean aResult) {
+ base.isViolated( (Edge)EasyMock.anyObject());
EasyMock.expectLastCall().andReturn(aResult);
}
public void testOneRestriction() {
IMocksControl control = EasyMock.createStrictControl();
- InterfaceRestriction base = control.createMock(InterfaceRestriction.class);
- InterfaceRestriction composite = new CompositeInterfaceRestriction(
- Arrays.asList(new InterfaceRestriction[] { base } ));
+ EdgeFilter base = control.createMock(EdgeFilter.class);
+ CompositeEdgeFilter composite = new CompositeEdgeFilter();
+ composite.add(base);
// First let the base return false and verify the result.
configureRestriction(base, false);
control.replay();
- assertFalse(composite.isViolated(_app, _app.getRequiredInterfaces()[0],
- _env, _env.getProvidedInterfaces()[0]));
+ assertFalse(composite.isViolated(createEdge(_app, _app.getRequiredInterfaces()[0],
+ _env, _env.getProvidedInterfaces()[0])));
control.verify();
// Second let the base return true and verify the result.
configureRestriction(base, true);
control.replay();
- assertTrue(composite.isViolated(_app, _app.getRequiredInterfaces()[0],
- _env, _env.getProvidedInterfaces()[0]));
+ assertTrue(composite.isViolated(createEdge(_app, _app.getRequiredInterfaces()[0],
+ _env, _env.getProvidedInterfaces()[0])));
control.verify();
}
public void testTwoRestrictions() {
IMocksControl control = EasyMock.createStrictControl();
- InterfaceRestriction base1 = control.createMock(InterfaceRestriction.class);
- CompositeInterfaceRestriction composite = new CompositeInterfaceRestriction(
- Arrays.asList(new InterfaceRestriction[] { base1 } ));
- InterfaceRestriction base2 = control.createMock(InterfaceRestriction.class);
+ EdgeFilter base1 = control.createMock(EdgeFilter.class);
+ CompositeEdgeFilter composite = new CompositeEdgeFilter();
+ composite.add(base1);
+ EdgeFilter base2 = control.createMock(EdgeFilter.class);
composite.add(base2);
// 1. base1 not violated and base 2 not violated -> not violated.
configureRestriction(base1, false);
configureRestriction(base2, false);
control.replay();
- assertFalse(composite.isViolated(_app, _app.getRequiredInterfaces()[0],
- _env, _env.getProvidedInterfaces()[0]));
+ assertFalse(composite.isViolated(createEdge(_app, _app.getRequiredInterfaces()[0],
+ _env, _env.getProvidedInterfaces()[0])));
control.verify();
control.reset();
configureRestriction(base1, false);
configureRestriction(base2, true);
control.replay();
- assertTrue(composite.isViolated(_app, _app.getRequiredInterfaces()[0],
- _env, _env.getProvidedInterfaces()[0]));
+ assertTrue(composite.isViolated(createEdge(_app, _app.getRequiredInterfaces()[0],
+ _env, _env.getProvidedInterfaces()[0])));
control.verify();
control.reset();
configureRestriction(base1, true);
// base 2 should not be called.
control.replay();
- assertTrue(composite.isViolated(_app, _app.getRequiredInterfaces()[0],
- _env, _env.getProvidedInterfaces()[0]));
+ assertTrue(composite.isViolated(createEdge(_app, _app.getRequiredInterfaces()[0],
+ _env, _env.getProvidedInterfaces()[0])));
control.verify();
control.reset();
}
+
}
assertEquals(12, edges.size()); // 2 outgoing and 2 incoming nodes.
}
+ public void testApplyFilter() {
+ Graph graph = new Graph();
+ graph.addNode(new DefaultNode("x"));
+ graph.addNode(new DefaultNode("y"));
+ graph.addNode(new DefaultNode("z"));
+ graph.addEdge(new DefaultEdge(graph.findNode("x"), graph.findNode("y")));
+ graph.addEdge(new DefaultEdge(graph.findNode("y"), graph.findNode("z")));
+ graph.addEdge(new DefaultEdge(graph.findNode("z"), graph.findNode("x")));
+
+ assertEquals(3, graph.getEdges().size());
+
+ graph.applyFilter(new EdgeFilter() {
+ @Override
+ public boolean isViolated(Edge aEdge) {
+ if (aEdge.getFrom().getName().equals("x")) {
+ return false;
+ }
+ return true;
+ }
+ });
+
+ assertEquals(1, graph.getEdges().size());
+ assertEquals("x", graph.getEdges().get(0).getFrom().getName());
+
+ }
+
public void testFindIncomingOutgoing() {
Graph graph = new Graph();
Node x = new DefaultNode("x");
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.wamblee.system.container;
+package org.wamblee.system.graph.component;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import junit.framework.TestCase;
-
+import org.wamblee.system.container.Application;
import org.wamblee.system.core.Environment;
+import org.wamblee.system.graph.DefaultEdge;
+import org.wamblee.system.graph.Edge;
+import org.wamblee.system.graph.EdgeFilter;
+import org.wamblee.system.graph.Node;
import org.wamblee.test.AssertionUtils;
-public class DefaultInterfaceRestrictionTest extends TestCase {
+import junit.framework.TestCase;
+
+public class ConnectRequiredProvidedEdgeFilterTest extends TestCase {
+
private Application _app1 = new Application("app1", "pf1.");
private Application _app2 = new Application("app2", "pf2.");
private Environment _env2 = new Environment("env2", "pf4.");
- private void compare(Boolean[] aExpected, InterfaceRestriction aRestriction) {
+ private void compare(Boolean[] aExpected, EdgeFilter aRestriction) {
List<Boolean> result = new ArrayList<Boolean>();
// order will be:
// env2, app1
// env2, app2
for (Environment env: new Environment[] { _env1, _env2} ) {
- for (Application app: new Application[] { _app1, _app2} ) {
- result.add(aRestriction.isViolated(
- app, app.getRequiredInterfaces()[0],
- env,
- env.getProvidedInterfaces()[0]
- ));
+ for (Application app: new Application[] { _app1, _app2} ) {
+ Node from = new RequiredInterfaceNode(
+ app, app.getRequiredInterfaces()[0]);
+ Node to = new ProvidedInterfaceNode(
+ env, env.getProvidedInterfaces()[0]);
+ Edge edge = new DefaultEdge(from, to);
+ result.add(aRestriction.isViolated(edge));
}
}
AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
@Override
public void run() throws Exception {
- InterfaceRestriction restriction = new DefaultInterfaceRestriction(null, null, null, null);
+ EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter(null, null, null, null);
}
}, IllegalArgumentException.class);
AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
@Override
public void run() throws Exception {
- InterfaceRestriction restriction = new DefaultInterfaceRestriction(null, null, "x", "y");
-
- }
- }, IllegalArgumentException.class);
- AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
- @Override
- public void run() throws Exception {
- InterfaceRestriction restriction = new DefaultInterfaceRestriction("x", "y", null, null);
-
+ EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter(null, null, "x", "y");
}
}, IllegalArgumentException.class);
}
public void testClientServer() {
- InterfaceRestriction restriction = new DefaultInterfaceRestriction("app1", null, "env1", null);
- compare(new Boolean[] { false, false, true, false}, restriction);
- }
-
- public void testRequiredServer() {
- InterfaceRestriction restriction = new DefaultInterfaceRestriction(null, "pf1.string", "env1", null);
+ EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter("app1", null, "env1", null);
compare(new Boolean[] { false, false, true, false}, restriction);
}
- public void testClientProvided() {
- InterfaceRestriction restriction = new DefaultInterfaceRestriction("app1", null, null, "pf4.datasource");
- compare(new Boolean[] { true, false, false, false}, restriction);
- }
-
- public void testRequiredProvide() {
- InterfaceRestriction restriction = new DefaultInterfaceRestriction(null, "pf1.string", null, "pf4.datasource");
- compare(new Boolean[] { true, false, false, false}, restriction);
+ public void testNoConnectionsAtAll() {
+ EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter("app1", null, null, null);
+ compare(new Boolean[] { true, false, true, false}, restriction);
}
public void testExplicitConfig() {
_env1 = new Environment("env1");
_env2 = new Environment("env2");
- InterfaceRestriction restriction = new DefaultInterfaceRestriction(
+ EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter(
"app2", "string", "env1", "datasource");
compare(new Boolean[] { false, false, false, true}, restriction);