4f30b538d59c6bbf7f5ef28eef73eb05bf7787a9
[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 org.wamblee.system.container.Application;
19 import org.wamblee.system.container.Container;
20 import org.wamblee.system.core.Component;
21 import org.wamblee.system.core.DefaultRequiredInterface;
22 import org.wamblee.system.core.RequiredInterface;
23 import org.wamblee.system.graph.DefaultEdge;
24 import org.wamblee.system.graph.DefaultNode;
25 import org.wamblee.system.graph.Edge;
26 import org.wamblee.system.graph.EdgeFilter;
27 import org.wamblee.system.graph.Node;
28
29 import junit.framework.TestCase;
30
31 public class ConnectRequiredExternallyRequiredEdgeFilterTest extends TestCase {
32
33     private Component<?> _comp;
34     private Container _container;
35     private Edge _edge;
36
37     @Override
38     protected void setUp() throws Exception {
39         _comp = new Application();
40         _container = new Container("container")
41                 .addRequiredInterface(new DefaultRequiredInterface("x",
42                         String.class));
43         Node req = new RequiredInterfaceNode(_comp, _comp
44                 .getRequiredInterfaces().get(0));
45         Node external = new ExternalRequiredInterfaceNode(_container,
46                 _container.getRequiredInterfaces().get(0));
47         _edge = new DefaultEdge(req, external);
48     }
49
50     public void testRightComponentRightInterface() {
51         EdgeFilter filter = new ConnectRequiredExternallyRequiredEdgeFilter(
52                 _comp.getName(), _comp.getRequiredInterfaces().get(0).getName(),
53                 _container.getRequiredInterfaces().get(0).getName());
54         assertFalse(filter.isViolated(_edge));
55     }
56
57     public void testWrongInterface() {
58         EdgeFilter filter = new ConnectRequiredExternallyRequiredEdgeFilter(
59                 _comp.getName(), _comp.getRequiredInterfaces().get(0).getName()
60                         + "xx", _container.getRequiredInterfaces().get(0).getName());
61         assertFalse(filter.isViolated(_edge));
62     }
63
64     public void testWrongComponent() {
65         EdgeFilter filter = new ConnectRequiredExternallyRequiredEdgeFilter(
66                 _comp.getName() + "xx", _comp.getRequiredInterfaces().get(0)
67                         .getName(), _container.getRequiredInterfaces().get(0)
68                         .getName());
69         assertFalse(filter.isViolated(_edge));
70     }
71
72     public void testWrongExternalInterface() {
73         EdgeFilter filter = new ConnectRequiredExternallyRequiredEdgeFilter(
74                 _comp.getName(), _comp.getRequiredInterfaces().get(0).getName(),
75                 _container.getRequiredInterfaces().get(0).getName() + "xx");
76         assertTrue(filter.isViolated(_edge));
77     }
78
79     public void testWrongEdgeType() {
80         DefaultEdge edge = new DefaultEdge(new DefaultNode("x"),
81                 new DefaultNode("y"));
82         EdgeFilter filter = new ConnectRequiredExternallyRequiredEdgeFilter(
83                 _comp.getName(), _comp.getRequiredInterfaces().get(0).getName(),
84                 _container.getRequiredInterfaces().get(0).getName());
85         assertFalse(filter.isViolated(edge));
86     }
87 }