2 * Copyright 2008 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.wamblee.system.graph;
18 import junit.framework.TestCase;
19 import static org.mockito.Matchers.*;
20 import static org.mockito.Mockito.*;
22 import org.wamblee.system.container.Application;
23 import org.wamblee.system.core.Component;
24 import org.wamblee.system.core.Environment;
25 import org.wamblee.system.core.ProvidedInterface;
26 import org.wamblee.system.core.RequiredInterface;
27 import org.wamblee.system.graph.component.ProvidedInterfaceNode;
28 import org.wamblee.system.graph.component.RequiredInterfaceNode;
35 public class CompositeEdgeFilterTest extends TestCase {
36 private Application app = new Application();
38 private Environment env = new Environment();
40 private Edge createEdge(Component aClient, RequiredInterface aRequired,
41 Component aServer, ProvidedInterface aProvided) {
42 Node from = new RequiredInterfaceNode(aClient, aRequired);
43 Node to = new ProvidedInterfaceNode(aServer, aProvided);
45 return new DefaultEdge(from, to);
48 public void testEmpty() {
49 EdgeFilter restriction = new CompositeEdgeFilter();
50 assertFalse(restriction.isViolated(createEdge(app, app
51 .getRequiredInterfaces().get(0), env, env.getProvidedInterfaces()
55 private void configureRestriction(EdgeFilter base, boolean aResult) {
56 stub(base.isViolated((Edge) anyObject())).toReturn(aResult);
59 public void testOneRestriction() {
60 EdgeFilter base = mock(EdgeFilter.class);
61 CompositeEdgeFilter composite = new CompositeEdgeFilter();
64 // First let the base return false and verify the result.
65 configureRestriction(base, false);
67 assertFalse(composite.isViolated(createEdge(app, app
68 .getRequiredInterfaces().get(0), env, env.getProvidedInterfaces()
71 // Second let the base return true and verify the result.
72 configureRestriction(base, true);
74 assertTrue(composite.isViolated(createEdge(app, app
75 .getRequiredInterfaces().get(0), env, env.getProvidedInterfaces()
79 public void testTwoRestrictions() {
80 EdgeFilter base1 = mock(EdgeFilter.class);
81 CompositeEdgeFilter composite = new CompositeEdgeFilter();
84 EdgeFilter base2 = mock(EdgeFilter.class);
87 // 1. base1 not violated and base 2 not violated -> not violated.
88 configureRestriction(base1, false);
89 configureRestriction(base2, false);
90 assertFalse(composite.isViolated(createEdge(app, app
91 .getRequiredInterfaces().get(0), env, env.getProvidedInterfaces()
94 // 2. base 1 not violated but base 2 violated -> violated
95 configureRestriction(base1, false);
96 configureRestriction(base2, true);
98 assertTrue(composite.isViolated(createEdge(app, app
99 .getRequiredInterfaces().get(0), env, env.getProvidedInterfaces()
102 // 3. base 1 violated -> violated and base 2 not called.
103 configureRestriction(base1, true);
104 // base 2 should not be called.
105 assertTrue(composite.isViolated(createEdge(app, app
106 .getRequiredInterfaces().get(0), env, env.getProvidedInterfaces()