bf92e0931e874b96f5e4db0a0b0734c7320ee862
[utils] /
1 /*
2  * Copyright 2005-2010 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.Application;
21 import org.wamblee.system.container.Container;
22 import org.wamblee.system.core.Component;
23 import org.wamblee.system.core.DefaultRequiredInterface;
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 import org.wamblee.system.graph.Node;
29
30 /**
31  * 
32  * @author $author$
33  * @version $Revision$
34  */
35 public class ConnectRequiredExternallyRequiredEdgeFilterTest extends TestCase {
36     private Component<?> comp;
37
38     private Container container;
39
40     private Edge edge;
41
42     @Override
43     protected void setUp() throws Exception {
44         comp = new Application();
45         container = new Container("container")
46             .addRequiredInterface(new DefaultRequiredInterface("x",
47                 String.class));
48
49         Node req = new RequiredInterfaceNode(comp, comp.getRequiredInterfaces()
50             .get(0));
51         Node external = new ExternalRequiredInterfaceNode(container, container
52             .getRequiredInterfaces().get(0));
53         edge = new DefaultEdge(req, external);
54     }
55
56     public void testRightComponentRightInterface() {
57         EdgeFilter filter = new ConnectRequiredExternallyRequiredEdgeFilter(
58             comp.getName(), comp.getRequiredInterfaces().get(0).getName(),
59             container.getRequiredInterfaces().get(0).getName());
60         assertFalse(filter.isViolated(edge));
61     }
62
63     public void testWrongInterface() {
64         EdgeFilter filter = new ConnectRequiredExternallyRequiredEdgeFilter(
65             comp.getName(), comp.getRequiredInterfaces().get(0).getName() +
66                 "xx", container.getRequiredInterfaces().get(0).getName());
67         assertFalse(filter.isViolated(edge));
68     }
69
70     public void testWrongComponent() {
71         EdgeFilter filter = new ConnectRequiredExternallyRequiredEdgeFilter(
72             comp.getName() + "xx", comp.getRequiredInterfaces().get(0)
73                 .getName(), container.getRequiredInterfaces().get(0).getName());
74         assertFalse(filter.isViolated(edge));
75     }
76
77     public void testWrongExternalInterface() {
78         EdgeFilter filter = new ConnectRequiredExternallyRequiredEdgeFilter(
79             comp.getName(), comp.getRequiredInterfaces().get(0).getName(),
80             container.getRequiredInterfaces().get(0).getName() + "xx");
81         assertTrue(filter.isViolated(edge));
82     }
83
84     public void testWrongEdgeType() {
85         DefaultEdge edge1 = new DefaultEdge(new DefaultNode("x"),
86             new DefaultNode("y"));
87         EdgeFilter filter = new ConnectRequiredExternallyRequiredEdgeFilter(
88             comp.getName(), comp.getRequiredInterfaces().get(0).getName(),
89             container.getRequiredInterfaces().get(0).getName());
90         assertFalse(filter.isViolated(edge1));
91     }
92 }