--- /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.Arrays;
+
+import junit.framework.TestCase;
+
+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 CompositeEdgeFilterTest extends TestCase {
+ private Application _app = new Application();
+ 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() {
+ EdgeFilter restriction = new CompositeEdgeFilter();
+ assertFalse(restriction.isViolated(createEdge(_app, _app.getRequiredInterfaces()[0],
+ _env, _env.getProvidedInterfaces()[0])));
+ }
+
+ private void configureRestriction(EdgeFilter base, boolean aResult) {
+ base.isViolated( (Edge)EasyMock.anyObject());
+ EasyMock.expectLastCall().andReturn(aResult);
+ }
+
+ public void testOneRestriction() {
+ IMocksControl control = EasyMock.createStrictControl();
+
+ 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(createEdge(_app, _app.getRequiredInterfaces()[0],
+ _env, _env.getProvidedInterfaces()[0])));
+ control.verify();
+
+ // Second let the base return true and verify the result.
+ control.reset();
+ configureRestriction(base, true);
+
+ control.replay();
+ assertTrue(composite.isViolated(createEdge(_app, _app.getRequiredInterfaces()[0],
+ _env, _env.getProvidedInterfaces()[0])));
+ control.verify();
+ }
+
+
+
+ public void testTwoRestrictions() {
+ IMocksControl control = EasyMock.createStrictControl();
+
+ 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(createEdge(_app, _app.getRequiredInterfaces()[0],
+ _env, _env.getProvidedInterfaces()[0])));
+ control.verify();
+ control.reset();
+
+ // 2. base 1 not violated but base 2 violated -> violated
+ configureRestriction(base1, false);
+ configureRestriction(base2, true);
+ control.replay();
+ assertTrue(composite.isViolated(createEdge(_app, _app.getRequiredInterfaces()[0],
+ _env, _env.getProvidedInterfaces()[0])));
+ control.verify();
+ control.reset();
+
+ // 3. base 1 violated -> violated and base 2 not called.
+ configureRestriction(base1, true);
+ // base 2 should not be called.
+ control.replay();
+ assertTrue(composite.isViolated(createEdge(_app, _app.getRequiredInterfaces()[0],
+ _env, _env.getProvidedInterfaces()[0])));
+ control.verify();
+ control.reset();
+ }
+
+}