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  import org.apache.struts.tiles.DefinitionsFactoryException;
12  
13  import org.apache.struts.tiles.ComponentDefinition;
14  
15  import com.macvu.tiles.CacheComponentDefinition;
16  
17  
18  
19  /***
20  
21   * Created by IntelliJ IDEA.
22  
23   * User: MVu
24  
25   * Date: Mar 23, 2004
26  
27   * Time: 3:34:11 PM
28  
29   * To change this template use File | Settings | File Templates.
30  
31   */
32  
33  public class CacheDefinitionFactoryTest extends TestCase {
34  
35      XmlCacheDefinitionSet set;
36  
37  
38  
39      public CacheDefinitionFactoryTest(String s) {
40  
41          super(s);
42  
43      }
44  
45  
46  
47      public void setUp() throws Exception {
48  
49          set = new XmlCacheDefinitionSet();
50  
51  
52  
53          XmlAttribute att = new XmlAttribute();
54  
55          XmlCacheDefinition current = new XmlCacheDefinition();
56  
57          current.setName("definition1");
58  
59          current.setPath("Path");
60  
61          current.setExtends("child1");
62  
63          current.setRole("complex");
64  
65          current.setController("xcontroll");
66  
67          current.setControllerType("0");
68  
69  
70  
71          XmlCacheDefinition child = new XmlCacheDefinition();
72  
73          child.setName("child1");
74  
75          child.setPath("childPath");
76  
77          child.setRole("simple");
78  
79          child.setController("controller");
80  
81          child.setControllerType("1");
82  
83          child.addAttribute(att);
84  
85  
86  
87          set.putDefinition(child);
88  
89          set.putDefinition(current);
90  
91      }
92  
93  
94  
95      public void testCacheDefinitionFactory() {
96  
97          try {
98  
99              CacheDefinitionFactory factory = new CacheDefinitionFactory(set);
100 
101 
102 
103             XmlCacheDefinition child = new XmlCacheDefinition();
104 
105             child.setName("child2");
106 
107             child.setPath("childPath");
108 
109             child.setRole("simple");
110 
111             child.setController("controller");
112 
113             child.setControllerType("1");
114 
115 
116 
117             factory.putDefinition(child);
118 
119 
120 
121             ComponentDefinition def = factory.getDefinition("definition1", null, null);
122 
123 
124 
125             assertNotNull("Definition should be valid", def);
126 
127         } catch (DefinitionsFactoryException e) {
128 
129             fail("Should not throw the exception");
130 
131         }
132 
133     }
134 
135 }
136