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.component;
18 import junit.framework.TestCase;
20 import org.wamblee.system.container.Application;
21 import org.wamblee.system.core.Environment;
22 import org.wamblee.system.graph.DefaultEdge;
23 import org.wamblee.system.graph.Edge;
24 import org.wamblee.system.graph.EdgeFilter;
25 import org.wamblee.system.graph.Node;
27 import org.wamblee.test.AssertionUtils;
29 import java.util.ArrayList;
30 import java.util.Arrays;
31 import java.util.List;
40 public class ConnectRequiredProvidedEdgeFilterTest extends TestCase {
44 private Application app1 = new Application("app1", "pf1.");
49 private Application app2 = new Application("app2", "pf2.");
54 private Environment env1 = new Environment("env1", "pf3.");
59 private Environment env2 = new Environment("env2", "pf4.");
64 * @param aExpected DOCUMENT ME!
65 * @param aRestriction DOCUMENT ME!
67 private void compare(Boolean[] aExpected, EdgeFilter aRestriction) {
68 List<Boolean> result = new ArrayList<Boolean>();
75 for (Environment env : new Environment[] { env1, env2 }) {
76 for (Application app : new Application[] { app1, app2 }) {
77 Node from = new RequiredInterfaceNode(app,
78 app.getRequiredInterfaces().get(0));
79 Node to = new ProvidedInterfaceNode(env,
80 env.getProvidedInterfaces().get(0));
81 Edge edge = new DefaultEdge(from, to);
82 result.add(aRestriction.isViolated(edge));
86 assertEquals(Arrays.asList(aExpected), result);
92 public void testNoRestriction() {
93 AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
95 public void run() throws Exception {
96 EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter(null,
99 }, IllegalArgumentException.class);
100 AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
102 public void run() throws Exception {
103 EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter(null,
106 }, IllegalArgumentException.class);
112 public void testClientServer() {
113 EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter("app1",
115 compare(new Boolean[] { false, false, true, false }, restriction);
121 public void testNoConnectionsAtAll() {
122 EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter("app1",
124 compare(new Boolean[] { true, false, true, false }, restriction);
130 public void testExplicitConfig() {
131 app1 = new Application("app1");
132 app2 = new Application("app2");
133 env1 = new Environment("env1");
134 env2 = new Environment("env2");
136 EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter("app2",
137 "string", "env1", "datasource");
138 compare(new Boolean[] { false, false, false, true }, restriction);