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));