4204b1417b85e3780a9a5aefa38f42a2b59a396f
[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.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  * DOCUMENT ME!
33  *
34  * @author $author$
35  * @version $Revision$
36   */
37 public class ConnectRequiredExternallyRequiredEdgeFilterTest extends TestCase {
38     /**
39      * DOCUMENT ME!
40      */
41     private Component<?> comp;
42
43     /**
44      * DOCUMENT ME!
45      */
46     private Container container;
47
48     /**
49      * DOCUMENT ME!
50      */
51     private Edge edge;
52
53     /**
54      * DOCUMENT ME!
55      *
56      * @throws Exception DOCUMENT ME!
57      */
58     @Override
59     protected void setUp() throws Exception {
60         comp          = new Application();
61         container     = new Container("container").addRequiredInterface(new DefaultRequiredInterface(
62                     "x", String.class));
63
64         Node req      = new RequiredInterfaceNode(comp,
65                 comp.getRequiredInterfaces().get(0));
66         Node external = new ExternalRequiredInterfaceNode(container,
67                 container.getRequiredInterfaces().get(0));
68         edge          = new DefaultEdge(req, external);
69     }
70
71     /**
72      * DOCUMENT ME!
73      */
74     public void testRightComponentRightInterface() {
75         EdgeFilter filter = new ConnectRequiredExternallyRequiredEdgeFilter(comp
76                 .getName(), comp.getRequiredInterfaces().get(0).getName(),
77                 container.getRequiredInterfaces().get(0).getName());
78         assertFalse(filter.isViolated(edge));
79     }
80
81     /**
82      * DOCUMENT ME!
83      */
84     public void testWrongInterface() {
85         EdgeFilter filter = new ConnectRequiredExternallyRequiredEdgeFilter(comp
86                 .getName(),
87                 comp.getRequiredInterfaces().get(0).getName() + "xx",
88                 container.getRequiredInterfaces().get(0).getName());
89         assertFalse(filter.isViolated(edge));
90     }
91
92     /**
93      * DOCUMENT ME!
94      */
95     public void testWrongComponent() {
96         EdgeFilter filter = new ConnectRequiredExternallyRequiredEdgeFilter(comp
97                 .getName() + "xx",
98                 comp.getRequiredInterfaces().get(0).getName(),
99                 container.getRequiredInterfaces().get(0).getName());
100         assertFalse(filter.isViolated(edge));
101     }
102
103     /**
104      * DOCUMENT ME!
105      */
106     public void testWrongExternalInterface() {
107         EdgeFilter filter = new ConnectRequiredExternallyRequiredEdgeFilter(comp
108                 .getName(), comp.getRequiredInterfaces().get(0).getName(),
109                 container.getRequiredInterfaces().get(0).getName() + "xx");
110         assertTrue(filter.isViolated(edge));
111     }
112
113     /**
114      * DOCUMENT ME!
115      */
116     public void testWrongEdgeType() {
117         DefaultEdge edge   = new DefaultEdge(new DefaultNode("x"),
118                 new DefaultNode("y"));
119         EdgeFilter  filter = new ConnectRequiredExternallyRequiredEdgeFilter(comp
120                 .getName(), comp.getRequiredInterfaces().get(0).getName(),
121                 container.getRequiredInterfaces().get(0).getName());
122         assertFalse(filter.isViolated(edge));
123     }
124 }