1   package com.macvu.tiles.xmlDefinition;
2   
3   
4   
5   import junit.framework.TestCase;
6   
7   import org.apache.struts.tiles.xmlDefinition.XmlAttribute;
8   
9   import org.apache.struts.tiles.NoSuchDefinitionException;
10  
11  
12  
13  /***
14  
15   * Created by IntelliJ IDEA.
16  
17   * User: MVu
18  
19   * Date: Mar 23, 2004
20  
21   * Time: 3:31:15 PM
22  
23   * To change this template use File | Settings | File Templates.
24  
25   */
26  
27  public class XmlCacheDefinitionTest extends TestCase {
28  
29      public XmlCacheDefinitionTest(String s) {
30  
31          super(s);
32  
33      }
34  
35  
36  
37      public void setUp() throws Exception {
38  
39      }
40  
41  
42  
43      public void testXmlCacheDefinitionAttributes() {
44  
45          XmlCacheInformation cacheInfo = new XmlCacheInformation();
46  
47          XmlCacheDefinition definition = new XmlCacheDefinition();
48  
49          XmlAttribute attribute = new XmlAttribute();
50  
51  
52  
53          definition.setName("foo");
54  
55          definition.setPath("path");
56  
57          definition.setRole("Role");
58  
59          definition.setController("controller");
60  
61          definition.setControllerType("type");
62  
63  
64  
65          definition.setIsVisited(true);
66  
67          definition.addCacheInformation(cacheInfo);
68  
69          definition.addAttribute(attribute);
70  
71  
72  
73          assertEquals("Name is equal", "foo", definition.getName());
74  
75          assertEquals("Path is equal", "path", definition.getPath());
76  
77          assertEquals("Role is equal", "Role", definition.getRole());
78  
79          assertEquals("Controller is equal", "controller", definition.getController());
80  
81          assertEquals("type is equal", "type", definition.getControllerType());
82  
83          assertEquals("CacheInformation is equal", cacheInfo, definition.getCacheInformation());
84  
85          assertEquals("Attribute count is 1", 1, definition.getAttributes().size());
86  
87      }
88  
89  
90  
91      public void testXmlCacheDefintionOverload() {
92  
93          XmlAttribute att = new XmlAttribute();
94  
95          XmlCacheDefinition current = new XmlCacheDefinition();
96  
97          current.setName("definition1");
98  
99          current.setPath("Path");
100 
101         current.setRole("complex");
102 
103         current.setController("xcontroll");
104 
105         current.setControllerType("0");
106 
107 
108 
109         XmlCacheDefinition child = new XmlCacheDefinition();
110 
111         child.setName("child1");
112 
113         child.setPath("childPath");
114 
115         child.setExtends("bar");
116 
117         child.setRole("simple");
118 
119         child.setController("controller");
120 
121         child.setControllerType("1");
122 
123         child.addAttribute(att);
124 
125 
126 
127         current.overload(child);
128 
129 
130 
131         assertEquals("Name is definition1", "definition1", current.getName());
132 
133         assertEquals("path is childPath", "childPath", current.getPath());
134 
135         assertEquals("Extends bar", "bar", current.getExtends());
136 
137         assertEquals("Controller controller", "controller", current.getController());
138 
139         assertEquals("Controller type is 1", "1", current.getControllerType());
140 
141         assertEquals("Attribute count is 1", 1, current.getAttributes().size());
142 
143     }
144 
145 
146 
147     public void testXmlCacheDefinitionResolveInheritance() throws NoSuchDefinitionException {
148 
149         XmlAttribute att = new XmlAttribute();
150 
151         XmlCacheDefinition current = new XmlCacheDefinition();
152 
153         current.setName("definition1");
154 
155         current.setPath("Path");
156 
157         current.setExtends("child1");
158 
159         current.setRole("complex");
160 
161         current.setController("xcontroll");
162 
163         current.setControllerType("0");
164 
165 
166 
167         XmlCacheDefinition child = new XmlCacheDefinition();
168 
169         child.setName("child1");
170 
171         child.setPath("childPath");
172 
173         child.setRole("simple");
174 
175         child.setController("controller");
176 
177         child.setControllerType("1");
178 
179         child.addAttribute(att);
180 
181 
182 
183         XmlCacheDefinitionSet set = new XmlCacheDefinitionSet();
184 
185         set.putDefinition(child);
186 
187 
188 
189         set.putDefinition(current);
190 
191 
192 
193         current.resolveInheritance(set);
194 
195 
196 
197         assertEquals("Name is definition1", "definition1", current.getName());
198 
199         assertEquals("path is childPath", "Path", current.getPath());
200 
201         assertEquals("Extends bar", "child1", current.getExtends());
202 
203         assertEquals("Controller controller", "xcontroll", current.getController());
204 
205         assertEquals("Controller type is 1", "0", current.getControllerType());
206 
207         assertEquals("Attribute count is 1", 1, current.getAttributes().size());
208 
209     }
210 
211 }
212