eb4deaffab297993e555608e85691ba4cafb11a7
[utils] /
1 /*
2  * Copyright 2008 the original author or authors.
3  * 
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
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
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.
15  */
16 package org.wamblee.system.graph.component;
17
18 import junit.framework.TestCase;
19
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;
28
29 public class ConnectExternalProvidedProvidedEdgeFilterTest extends TestCase {
30
31     private Container container;
32     private Component<Object> internal;
33     private String externalInterfaceName;
34     private String internalComponentName;
35     private String internalInterfaceName;
36     private Edge edge;
37
38     @Override
39     protected void setUp() throws Exception {
40         container = new Container("container")
41                 .addProvidedInterface(new DefaultProvidedInterface("string",
42                         String.class));
43         internal = new Environment("env1");
44
45         externalInterfaceName = container.getProvidedInterfaces().get(0)
46                 .getName();
47         internalComponentName = internal.getName();
48         internalInterfaceName = internal.getProvidedInterfaces().get(0).getName();
49
50         edge = new DefaultEdge(new ExternalProvidedInterfaceNode(container,
51                 container.getProvidedInterfaces().get(0)),
52                 new ProvidedInterfaceNode(internal, internal
53                         .getProvidedInterfaces().get(0)));
54     }
55
56     public void testWrongExternal() {
57         EdgeFilter filter = new ConnectExternalProvidedProvidedFilter(
58                 externalInterfaceName + "x", internalComponentName,
59                 internalInterfaceName);
60         assertFalse(filter.isViolated(edge));
61     }
62
63     public void testRightExternalWrongComponent() {
64         EdgeFilter filter = new ConnectExternalProvidedProvidedFilter(
65                 externalInterfaceName, internalComponentName + "x",
66                 internalInterfaceName);
67         assertTrue(filter.isViolated(edge));
68     }
69
70     public void testRightExternalWrongInternal() {
71         EdgeFilter filter = new ConnectExternalProvidedProvidedFilter(
72                 externalInterfaceName, internalComponentName,
73                 internalInterfaceName + "x");
74         assertTrue(filter.isViolated(edge));
75     }
76     
77     public void testEverythingRight() { 
78         EdgeFilter filter = new ConnectExternalProvidedProvidedFilter(
79                 externalInterfaceName, internalComponentName,
80                 internalInterfaceName);
81         assertFalse(filter.isViolated(edge));
82     }
83
84
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));
92     }
93
94 }