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:32:13 PM
22  
23   * To change this template use File | Settings | File Templates.
24  
25   */
26  
27  public class XmlCacheDefinitionSetTest extends TestCase {
28  
29      XmlCacheDefinitionSet set;
30  
31  
32  
33      public XmlCacheDefinitionSetTest(String s) {
34  
35          super(s);
36  
37      }
38  
39  
40  
41      public void setUp() throws Exception {
42  
43          set = new XmlCacheDefinitionSet();
44  
45  
46  
47          XmlAttribute att = new XmlAttribute();
48  
49          XmlCacheDefinition current = new XmlCacheDefinition();
50  
51          current.setName("definition1");
52  
53          current.setPath("Path");
54  
55          current.setExtends("child1");
56  
57          current.setRole("complex");
58  
59          current.setController("xcontroll");
60  
61          current.setControllerType("0");
62  
63  
64  
65          XmlCacheDefinition child = new XmlCacheDefinition();
66  
67          child.setName("child1");
68  
69          child.setPath("childPath");
70  
71          child.setRole("simple");
72  
73          child.setController("controller");
74  
75          child.setControllerType("1");
76  
77          child.addAttribute(att);
78  
79  
80  
81          set.putDefinition(child);
82  
83          set.putDefinition(current);
84  
85      }
86  
87  
88  
89      public void testXmlCacheDefinitionSet() throws NoSuchDefinitionException {
90  
91          set.resolveInheritances();
92  
93  
94  
95          XmlCacheDefinition current = set.getDefinition("definition1");
96  
97  
98  
99          assertEquals("Name is definition1", "definition1", current.getName());
100 
101         assertEquals("path is childPath", "Path", current.getPath());
102 
103         assertEquals("Extends bar", "child1", current.getExtends());
104 
105         assertEquals("Controller controller", "xcontroll", current.getController());
106 
107         assertEquals("Controller type is 1", "0", current.getControllerType());
108 
109         assertEquals("Attribute count is 1", 1, current.getAttributes().size());
110 
111     }
112 
113 
114 
115     public void testXmlCacheDefinitionSetOveride() {
116 
117         XmlAttribute att = new XmlAttribute();
118 
119         XmlCacheDefinitionSet childSet = new XmlCacheDefinitionSet();
120 
121         XmlCacheDefinition current = new XmlCacheDefinition();
122 
123         current.setName("definition1");
124 
125         current.setPath("foo");
126 
127         current.setRole("simple");
128 
129         current.setController("xcontroll");
130 
131         current.setControllerType("1");
132 
133 
134 
135         XmlCacheDefinition child = new XmlCacheDefinition();
136 
137         child.setName("foobar");
138 
139         child.setPath("childPath");
140 
141         child.setRole("simple");
142 
143         child.setController("controller");
144 
145         child.setControllerType("1");
146 
147         child.addAttribute(att);
148 
149 
150 
151         childSet.putDefinition(current);
152 
153         childSet.putDefinition(child);
154 
155 
156 
157         set.extend(childSet);
158 
159 
160 
161         XmlCacheDefinition foobar = set.getDefinition("foobar");
162 
163         assertNotNull("Should get back a valid object", foobar);
164 
165 
166 
167         XmlCacheDefinition testDef = set.getDefinition("definition1");
168 
169         assertEquals("Name is definition1", "definition1", current.getName());
170 
171         assertEquals("path is childPath", "foo", current.getPath());
172 
173         assertEquals("Controller controller", "xcontroll", current.getController());
174 
175         assertEquals("Controller type is 1", "1", current.getControllerType());
176 
177         assertEquals("Attribute count is 0", 0, current.getAttributes().size());
178 
179     }
180 
181 }
182