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.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;
34 public class ConnectExternalProvidedProvidedEdgeFilterTest extends TestCase {
35 private Container container;
37 private Component<Object> internal;
39 private String externalInterfaceName;
41 private String internalComponentName;
43 private String internalInterfaceName;
48 protected void setUp() throws Exception {
49 container = new Container("container")
50 .addProvidedInterface(new DefaultProvidedInterface("string",
52 internal = new Environment("env1");
54 externalInterfaceName = container.getProvidedInterfaces().get(0)
56 internalComponentName = internal.getName();
57 internalInterfaceName = internal.getProvidedInterfaces().get(0)
60 edge = new DefaultEdge(new ExternalProvidedInterfaceNode(container,
61 container.getProvidedInterfaces().get(0)),
62 new ProvidedInterfaceNode(internal, internal
63 .getProvidedInterfaces().get(0)));
66 public void testWrongExternal() {
67 EdgeFilter filter = new ConnectExternalProvidedProvidedFilter(
68 externalInterfaceName + "x", internalComponentName,
69 internalInterfaceName);
70 assertFalse(filter.isViolated(edge));
73 public void testRightExternalWrongComponent() {
74 EdgeFilter filter = new ConnectExternalProvidedProvidedFilter(
75 externalInterfaceName, internalComponentName + "x",
76 internalInterfaceName);
77 assertTrue(filter.isViolated(edge));
80 public void testRightExternalWrongInternal() {
81 EdgeFilter filter = new ConnectExternalProvidedProvidedFilter(
82 externalInterfaceName, internalComponentName,
83 internalInterfaceName + "x");
84 assertTrue(filter.isViolated(edge));
87 public void testEverythingRight() {
88 EdgeFilter filter = new ConnectExternalProvidedProvidedFilter(
89 externalInterfaceName, internalComponentName, internalInterfaceName);
90 assertFalse(filter.isViolated(edge));
93 public void testWrongEdgeType() {
94 EdgeFilter filter = new ConnectExternalProvidedProvidedFilter(
95 externalInterfaceName, internalComponentName, internalInterfaceName);
96 DefaultEdge edge = new DefaultEdge(new DefaultNode("x"),
97 new DefaultNode("y"));
98 assertFalse(filter.isViolated(edge));