KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > ojb > tests > ObjectCacheTagTests


1 package xdoclet.modules.ojb.tests;
2
3 /* Copyright 2003-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /**
19  * Tests for the ojb.object-cache tag.
20  * TODO Add tests for strict=true
21  *
22  * @author <a HREF="mailto:tomdz@users.sourceforge.net">Thomas Dudziak (tomdz@users.sourceforge.net)</a>
23  */

24 public class ObjectCacheTagTests extends OjbTestBase
25 {
26     public ObjectCacheTagTests(String JavaDoc name)
27     {
28         super(name);
29     }
30
31     // Test: class attribute with empty value
32
public void testSimple1()
33     {
34         addClass(
35             "test.A",
36             "package test;\n"+
37             "/** @ojb.class\n"+
38             " * @ojb.object-cache class=\"\"\n"+
39             " */\n"+
40             "public class A {}\n");
41
42         assertNull(runOjbXDoclet(OJB_DEST_FILE));
43         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
44     }
45
46     // Test: OJB-supplied cache class
47
public void testSimple2()
48     {
49         addClass(
50             "test.A",
51             "package test;\n"+
52             "/** @ojb.class\n"+
53             " * @ojb.object-cache class=\"org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl\"\n"+
54             " */\n"+
55             "public class A {}\n");
56
57         assertEqualsOjbDescriptorFile(
58             "<class-descriptor\n"+
59             " class=\"test.A\"\n"+
60             " table=\"A\"\n"+
61             ">\n"+
62             " <object-cache class=\"org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl\">\n"+
63             " </object-cache>\n"+
64             "</class-descriptor>",
65             runOjbXDoclet(OJB_DEST_FILE));
66         assertEqualsTorqueSchemaFile(
67             "<database name=\"ojbtest\">\n"+
68             " <table name=\"A\">\n"+
69             " </table>\n"+
70             "</database>",
71             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
72     }
73
74     // Test: user-defined cache class
75
public void testSimple3()
76     {
77         addClass(
78             "test.A",
79             "package test;\n"+
80             "/** @ojb.class\n"+
81             " * @ojb.object-cache class=\""+TestObjectCache.class.getName()+"\"\n"+
82             " */\n"+
83             "public class A {}\n");
84
85         assertEqualsOjbDescriptorFile(
86             "<class-descriptor\n"+
87             " class=\"test.A\"\n"+
88             " table=\"A\"\n"+
89             ">\n"+
90             " <object-cache class=\""+TestObjectCache.class.getName()+"\">\n"+
91             " </object-cache>\n"+
92             "</class-descriptor>",
93             runOjbXDoclet(OJB_DEST_FILE));
94         assertEqualsTorqueSchemaFile(
95             "<database name=\"ojbtest\">\n"+
96             " <table name=\"A\">\n"+
97             " </table>\n"+
98             "</database>",
99             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
100     }
101
102     // Test: user-defined cache class which does not implement the ObjectCache interface
103
public void testSimple4()
104     {
105         addClass(
106             "test.A",
107             "package test;\n"+
108             "/** @ojb.class\n"+
109             " * @ojb.object-cache class=\"java.lang.Map\"\n"+
110             " */\n"+
111             "public class A {}\n");
112
113         assertNull(runOjbXDoclet(OJB_DEST_FILE));
114         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
115     }
116
117     // Test: inheritance
118
public void testSimple5()
119     {
120         addClass(
121             "test.A",
122             "package test;\n"+
123             "/** @ojb.class\n"+
124             " * @ojb.object-cache class=\"org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl\"\n"+
125             " */\n"+
126             "public class A {}\n");
127         addClass(
128             "test.B",
129             "package test;\n"+
130             "/** @ojb.class */\n"+
131             "public class B extends A {}\n");
132
133         assertEqualsOjbDescriptorFile(
134             "<class-descriptor\n"+
135             " class=\"test.A\"\n"+
136             " table=\"A\"\n"+
137             ">\n"+
138             " <object-cache class=\"org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl\">\n"+
139             " </object-cache>\n"+
140             " <extent-class class-ref=\"test.B\"/>\n"+
141             "</class-descriptor>\n"+
142             "<class-descriptor\n"+
143             " class=\"test.B\"\n"+
144             " table=\"B\"\n"+
145             ">\n"+
146             "</class-descriptor>",
147             runOjbXDoclet(OJB_DEST_FILE));
148         assertEqualsTorqueSchemaFile(
149             "<database name=\"ojbtest\">\n"+
150             " <table name=\"A\">\n"+
151             " </table>\n"+
152             " <table name=\"B\">\n"+
153             " </table>\n"+
154             "</database>",
155             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
156     }
157
158     // Test of attributes attribute: no value
159
public void testAttributes1()
160     {
161         addClass(
162             "test.A",
163             "package test;\n"+
164             "/** @ojb.class\n"+
165             " * @ojb.object-cache class=\""+TestObjectCache.class.getName()+"\"\n"+
166             " * attributes=\"\"\n"+
167             " */\n"+
168             "public class A {}\n");
169
170         assertEqualsOjbDescriptorFile(
171             "<class-descriptor\n"+
172             " class=\"test.A\"\n"+
173             " table=\"A\"\n"+
174             ">\n"+
175             " <object-cache class=\""+TestObjectCache.class.getName()+"\">\n"+
176             " </object-cache>\n"+
177             "</class-descriptor>",
178             runOjbXDoclet(OJB_DEST_FILE));
179         assertEqualsTorqueSchemaFile(
180             "<database name=\"ojbtest\">\n"+
181             " <table name=\"A\">\n"+
182             " </table>\n"+
183             "</database>",
184             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
185     }
186
187     // Test of attributes attribute: with one name-value pair
188
public void testAttributes2()
189     {
190         addClass(
191             "test.A",
192             "package test;\n"+
193             "/** @ojb.class\n"+
194             " * @ojb.object-cache class=\""+TestObjectCache.class.getName()+"\"\n"+
195             " * attributes=\"name=value\"\n"+
196             " */\n"+
197             "public class A {}\n");
198
199         assertEqualsOjbDescriptorFile(
200             "<class-descriptor\n"+
201             " class=\"test.A\"\n"+
202             " table=\"A\"\n"+
203             ">\n"+
204             " <object-cache class=\""+TestObjectCache.class.getName()+"\">\n"+
205             " <attribute attribute-name=\"name\" attribute-value=\"value\"/>\n"+
206             " </object-cache>\n"+
207             "</class-descriptor>",
208             runOjbXDoclet(OJB_DEST_FILE));
209         assertEqualsTorqueSchemaFile(
210             "<database name=\"ojbtest\">\n"+
211             " <table name=\"A\">\n"+
212             " </table>\n"+
213             "</database>",
214             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
215     }
216
217     // Test of attributes attribute: with empty attribute
218
public void testAttributes3()
219     {
220         addClass(
221             "test.A",
222             "package test;\n"+
223             "/** @ojb.class\n"+
224             " * @ojb.object-cache class=\""+TestObjectCache.class.getName()+"\"\n"+
225             " * attributes=\"name=\"\n"+
226             " */\n"+
227             "public class A {}\n");
228
229         assertEqualsOjbDescriptorFile(
230             "<class-descriptor\n"+
231             " class=\"test.A\"\n"+
232             " table=\"A\"\n"+
233             ">\n"+
234             " <object-cache class=\""+TestObjectCache.class.getName()+"\">\n"+
235             " <attribute attribute-name=\"name\" attribute-value=\"\"/>\n"+
236             " </object-cache>\n"+
237             "</class-descriptor>",
238             runOjbXDoclet(OJB_DEST_FILE));
239         assertEqualsTorqueSchemaFile(
240             "<database name=\"ojbtest\">\n"+
241             " <table name=\"A\">\n"+
242             " </table>\n"+
243             "</database>",
244             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
245     }
246
247     // Test of attributes attribute: with three name-value pairs, one without value
248
public void testAttributes4()
249     {
250         addClass(
251             "test.A",
252             "package test;\n"+
253             "/** @ojb.class\n"+
254             " * @ojb.object-cache class=\""+TestObjectCache.class.getName()+"\"\n"+
255             " * attributes=\"name1=value1,name2=,name3=value3\"\n"+
256             " */\n"+
257             "public class A {}\n");
258
259         assertEqualsOjbDescriptorFile(
260             "<class-descriptor\n"+
261             " class=\"test.A\"\n"+
262             " table=\"A\"\n"+
263             ">\n"+
264             " <object-cache class=\""+TestObjectCache.class.getName()+"\">\n"+
265             " <attribute attribute-name=\"name1\" attribute-value=\"value1\"/>\n"+
266             " <attribute attribute-name=\"name2\" attribute-value=\"\"/>\n"+
267             " <attribute attribute-name=\"name3\" attribute-value=\"value3\"/>\n"+
268             " </object-cache>\n"+
269             "</class-descriptor>",
270             runOjbXDoclet(OJB_DEST_FILE));
271         assertEqualsTorqueSchemaFile(
272             "<database name=\"ojbtest\">\n"+
273             " <table name=\"A\">\n"+
274             " </table>\n"+
275             "</database>",
276             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
277     }
278
279     // Test of documentation attribute: no value
280
public void testDocumentation1()
281     {
282         addClass(
283             "test.A",
284             "package test;\n"+
285             "/** @ojb.class\n"+
286             " * @ojb.object-cache class=\""+TestObjectCache.class.getName()+"\"\n"+
287             " * documentation=\"\"\n"+
288             " */\n"+
289             "public class A {}\n");
290
291         assertEqualsOjbDescriptorFile(
292             "<class-descriptor\n"+
293             " class=\"test.A\"\n"+
294             " table=\"A\"\n"+
295             ">\n"+
296             " <object-cache class=\""+TestObjectCache.class.getName()+"\">\n"+
297             " </object-cache>\n"+
298             "</class-descriptor>",
299             runOjbXDoclet(OJB_DEST_FILE));
300         assertEqualsTorqueSchemaFile(
301             "<database name=\"ojbtest\">\n"+
302             " <table name=\"A\">\n"+
303             " </table>\n"+
304             "</database>",
305             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
306     }
307
308     // Test of documentation attribute: with value
309
public void testDocumentation2()
310     {
311         addClass(
312             "test.A",
313             "package test;\n"+
314             "/** @ojb.class\n"+
315             " * @ojb.object-cache class=\""+TestObjectCache.class.getName()+"\"\n"+
316             " * documentation=\"some documentation\"\n"+
317             " */\n"+
318             "public class A {}\n");
319
320         assertEqualsOjbDescriptorFile(
321             "<class-descriptor\n"+
322             " class=\"test.A\"\n"+
323             " table=\"A\"\n"+
324             ">\n"+
325             " <object-cache class=\""+TestObjectCache.class.getName()+"\">\n"+
326             " <documentation>some documentation</documentation>\n"+
327             " </object-cache>\n"+
328             "</class-descriptor>",
329             runOjbXDoclet(OJB_DEST_FILE));
330         assertEqualsTorqueSchemaFile(
331             "<database name=\"ojbtest\">\n"+
332             " <table name=\"A\">\n"+
333             " </table>\n"+
334             "</database>",
335             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
336     }
337 }
338
Popular Tags