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 java.util.ArrayList;
19 import java.util.Arrays;
20 import java.util.List;
22 import org.wamblee.system.container.Application;
23 import org.wamblee.system.core.Environment;
24 import org.wamblee.system.graph.DefaultEdge;
25 import org.wamblee.system.graph.Edge;
26 import org.wamblee.system.graph.EdgeFilter;
27 import org.wamblee.system.graph.Node;
28 import org.wamblee.test.AssertionUtils;
30 import junit.framework.TestCase;
32 public class ConnectRequiredProvidedEdgeFilterTest extends TestCase {
34 private Application _app1 = new Application("app1", "pf1.");
35 private Application _app2 = new Application("app2", "pf2.");
37 private Environment _env1 = new Environment("env1", "pf3.");
38 private Environment _env2 = new Environment("env2", "pf4.");
41 private void compare(Boolean[] aExpected, EdgeFilter aRestriction) {
42 List<Boolean> result = new ArrayList<Boolean>();
49 for (Environment env: new Environment[] { _env1, _env2} ) {
50 for (Application app: new Application[] { _app1, _app2} ) {
51 Node from = new RequiredInterfaceNode(
52 app, app.getRequiredInterfaces()[0]);
53 Node to = new ProvidedInterfaceNode(
54 env, env.getProvidedInterfaces()[0]);
55 Edge edge = new DefaultEdge(from, to);
56 result.add(aRestriction.isViolated(edge));
61 assertEquals(Arrays.asList(aExpected), result);
64 public void testNoRestriction() {
65 AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
67 public void run() throws Exception {
68 EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter(null, null, null, null);
71 }, IllegalArgumentException.class);
72 AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
74 public void run() throws Exception {
75 EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter(null, null, "x", "y");
77 }, IllegalArgumentException.class);
80 public void testClientServer() {
81 EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter("app1", null, "env1", null);
82 compare(new Boolean[] { false, false, true, false}, restriction);
85 public void testNoConnectionsAtAll() {
86 EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter("app1", null, null, null);
87 compare(new Boolean[] { true, false, true, false}, restriction);
90 public void testExplicitConfig() {
91 _app1 = new Application("app1");
92 _app2 = new Application("app2");
93 _env1 = new Environment("env1");
94 _env2 = new Environment("env2");
96 EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter(
97 "app2", "string", "env1", "datasource");
98 compare(new Boolean[] { false, false, false, true}, restriction);