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.Application;
21 import org.wamblee.system.container.Container;
22 import org.wamblee.system.core.Component;
23 import org.wamblee.system.core.DefaultProvidedInterface;
24 import org.wamblee.system.core.DefaultRequiredInterface;
25 import org.wamblee.system.core.Environment;
26 import org.wamblee.system.graph.DefaultEdge;
27 import org.wamblee.system.graph.DefaultNode;
28 import org.wamblee.system.graph.Edge;
29 import org.wamblee.system.graph.EdgeFilter;
30 import org.wamblee.system.graph.Node;
32 public class ConnectExternalProvidedProvidedEdgeFilterTest extends TestCase {
34 private Container _container;
35 private Component _internal;
36 private String _externalInterfaceName;
37 private String _internalComponentName;
38 private String _internalInterfaceName;
42 protected void setUp() throws Exception {
43 _container = new Container("container")
44 .addProvidedInterface(new DefaultProvidedInterface("string",
46 _internal = new Environment("env1");
48 _externalInterfaceName = _container.getProvidedInterfaces().get(0)
50 _internalComponentName = _internal.getName();
51 _internalInterfaceName = _internal.getProvidedInterfaces().get(0).getName();
53 _edge = new DefaultEdge(new ExternalProvidedInterfaceNode(_container,
54 _container.getProvidedInterfaces().get(0)),
55 new ProvidedInterfaceNode(_internal, _internal
56 .getProvidedInterfaces().get(0)));
59 public void testWrongExternal() {
60 EdgeFilter filter = new ConnectExternalProvidedProvidedFilter(
61 _externalInterfaceName + "x", _internalComponentName,
62 _internalInterfaceName);
63 assertFalse(filter.isViolated(_edge));
66 public void testRightExternalWrongComponent() {
67 EdgeFilter filter = new ConnectExternalProvidedProvidedFilter(
68 _externalInterfaceName, _internalComponentName + "x",
69 _internalInterfaceName);
70 assertTrue(filter.isViolated(_edge));
73 public void testRightExternalWrongInternal() {
74 EdgeFilter filter = new ConnectExternalProvidedProvidedFilter(
75 _externalInterfaceName, _internalComponentName,
76 _internalInterfaceName + "x");
77 assertTrue(filter.isViolated(_edge));
80 public void testEverythingRight() {
81 EdgeFilter filter = new ConnectExternalProvidedProvidedFilter(
82 _externalInterfaceName, _internalComponentName,
83 _internalInterfaceName);
84 assertFalse(filter.isViolated(_edge));
88 public void testWrongEdgeType() {
89 EdgeFilter filter = new ConnectExternalProvidedProvidedFilter(
90 _externalInterfaceName, _internalComponentName,
91 _internalInterfaceName);
92 DefaultEdge edge = new DefaultEdge(new DefaultNode("x"),
93 new DefaultNode("y"));
94 assertFalse(filter.isViolated(edge));