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.Container;
21 import org.wamblee.system.core.Component;
22 import org.wamblee.system.core.DefaultProvidedInterface;
23 import org.wamblee.system.core.Environment;
24 import org.wamblee.system.graph.DefaultEdge;
25 import org.wamblee.system.graph.DefaultNode;
26 import org.wamblee.system.graph.Edge;
27 import org.wamblee.system.graph.EdgeFilter;
29 public class ConnectExternalProvidedProvidedEdgeFilterTest extends TestCase {
31 private Container container;
32 private Component<Object> internal;
33 private String externalInterfaceName;
34 private String internalComponentName;
35 private String internalInterfaceName;
39 protected void setUp() throws Exception {
40 container = new Container("container")
41 .addProvidedInterface(new DefaultProvidedInterface("string",
43 internal = new Environment("env1");
45 externalInterfaceName = container.getProvidedInterfaces().get(0)
47 internalComponentName = internal.getName();
48 internalInterfaceName = internal.getProvidedInterfaces().get(0).getName();
50 edge = new DefaultEdge(new ExternalProvidedInterfaceNode(container,
51 container.getProvidedInterfaces().get(0)),
52 new ProvidedInterfaceNode(internal, internal
53 .getProvidedInterfaces().get(0)));
56 public void testWrongExternal() {
57 EdgeFilter filter = new ConnectExternalProvidedProvidedFilter(
58 externalInterfaceName + "x", internalComponentName,
59 internalInterfaceName);
60 assertFalse(filter.isViolated(edge));
63 public void testRightExternalWrongComponent() {
64 EdgeFilter filter = new ConnectExternalProvidedProvidedFilter(
65 externalInterfaceName, internalComponentName + "x",
66 internalInterfaceName);
67 assertTrue(filter.isViolated(edge));
70 public void testRightExternalWrongInternal() {
71 EdgeFilter filter = new ConnectExternalProvidedProvidedFilter(
72 externalInterfaceName, internalComponentName,
73 internalInterfaceName + "x");
74 assertTrue(filter.isViolated(edge));
77 public void testEverythingRight() {
78 EdgeFilter filter = new ConnectExternalProvidedProvidedFilter(
79 externalInterfaceName, internalComponentName,
80 internalInterfaceName);
81 assertFalse(filter.isViolated(edge));
85 public void testWrongEdgeType() {
86 EdgeFilter filter = new ConnectExternalProvidedProvidedFilter(
87 externalInterfaceName, internalComponentName,
88 internalInterfaceName);
89 DefaultEdge edge = new DefaultEdge(new DefaultNode("x"),
90 new DefaultNode("y"));
91 assertFalse(filter.isViolated(edge));