2 * Copyright 2005-2010 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;
38 public class ConnectRequiredProvidedEdgeFilterTest extends TestCase {
39 private Application app1 = new Application("app1", "pf1.");
41 private Application app2 = new Application("app2", "pf2.");
43 private Environment env1 = new Environment("env1", "pf3.");
45 private Environment env2 = new Environment("env2", "pf4.");
47 private void compare(Boolean[] aExpected, EdgeFilter aRestriction) {
48 List<Boolean> result = new ArrayList<Boolean>();
55 for (Environment env : new Environment[] { env1, env2 }) {
56 for (Application app : new Application[] { app1, app2 }) {
57 Node from = new RequiredInterfaceNode(app, app
58 .getRequiredInterfaces().get(0));
59 Node to = new ProvidedInterfaceNode(env, env
60 .getProvidedInterfaces().get(0));
61 Edge edge = new DefaultEdge(from, to);
62 result.add(aRestriction.isViolated(edge));
66 assertEquals(Arrays.asList(aExpected), result);
69 public void testNoRestriction() {
70 AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
72 public void run() throws Exception {
73 EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter(
74 null, null, null, null);
75 ignoredVariable(restriction);
77 }, IllegalArgumentException.class);
78 AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
80 public void run() throws Exception {
81 EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter(
82 null, null, "x", "y");
83 ignoredVariable(restriction);
85 }, IllegalArgumentException.class);
88 private static final void ignoredVariable(Object aObject) {
92 public void testClientServer() {
93 EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter("app1",
95 compare(new Boolean[] { false, false, true, false }, restriction);
98 public void testNoConnectionsAtAll() {
99 EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter("app1",
101 compare(new Boolean[] { true, false, true, false }, restriction);
104 public void testExplicitConfig() {
105 app1 = new Application("app1");
106 app2 = new Application("app2");
107 env1 = new Environment("env1");
108 env2 = new Environment("env2");
110 EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter("app2",
111 "string", "env1", "datasource");
112 compare(new Boolean[] { false, false, false, true }, restriction);