KickJava   Java API By Example, From Geeks To Geeks.

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


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.class tag with the generate-table-info attribute.
20  *
21  * @author <a HREF="mailto:tomdz@apache.org">Thomas Dudziak (tomdz@apache.org)</a>
22  */

23 public class ClassTagGenerateTableInfoAttributeTests extends OjbTestBase
24 {
25     public ClassTagGenerateTableInfoAttributeTests(String JavaDoc name)
26     {
27         super(name);
28     }
29
30     // Test of generate-table-info: empty value
31
public void testGenerateTableInfo1()
32     {
33         addClass(
34             "test.A",
35             "package test;\n"+
36             "/** @ojb.class generate-table-info=\"\" */\n"+
37             "public class A {}\n");
38
39         assertNull(runOjbXDoclet(OJB_DEST_FILE));
40         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
41     }
42
43     // Test of generate-table-info: invalid value
44
public void testGenerateTableInfo2()
45     {
46         addClass(
47             "test.A",
48             "package test;\n"+
49             "/** @ojb.class generate-table-info=\"yes\" */\n"+
50             "public class A {}\n");
51
52         assertNull(runOjbXDoclet(OJB_DEST_FILE));
53         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
54     }
55
56     // Test of generate-table-info: 'true' value
57
public void testGenerateTableInfo3()
58     {
59         addClass(
60             "test.A",
61             "package test;\n"+
62             "/** @ojb.class generate-table-info=\"true\" */\n"+
63             "public class A {}\n");
64
65         assertEqualsOjbDescriptorFile(
66             "<class-descriptor\n"+
67             " class=\"test.A\"\n"+
68             " table=\"A\"\n"+
69             ">\n"+
70             "</class-descriptor>",
71             runOjbXDoclet(OJB_DEST_FILE));
72         assertEqualsTorqueSchemaFile(
73             "<database name=\"ojbtest\">\n"+
74             " <table name=\"A\">\n"+
75             " </table>\n"+
76             "</database>",
77             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
78     }
79
80     // Test of generate-table-info: 'true' value with remote base- and subclass
81
public void testGenerateTableInfo4()
82     {
83         addClass(
84             "test.A",
85             "package test;\n"+
86             "/** @ojb.class */\n"+
87             "public class A {}\n");
88         addClass(
89             "test.B",
90             "package test;\n"+
91             "public class B extends A {}\n");
92         addClass(
93             "test.C",
94             "package test;\n"+
95             "/** @ojb.class generate-table-info=\"true\" */\n"+
96             "public class C extends B {}\n");
97         addClass(
98             "test.D",
99             "package test;\n"+
100             "public class D extends C {}\n");
101         addClass(
102             "test.E",
103             "package test;\n"+
104             "/** @ojb.class */\n"+
105             "public class E extends D {}\n");
106
107         assertEqualsOjbDescriptorFile(
108             "<class-descriptor\n"+
109             " class=\"test.A\"\n"+
110             " table=\"A\"\n"+
111             ">\n"+
112             " <extent-class class-ref=\"test.C\"/>\n"+
113             "</class-descriptor>\n"+
114             "<class-descriptor\n"+
115             " class=\"test.C\"\n"+
116             " table=\"C\"\n"+
117             ">\n"+
118             " <extent-class class-ref=\"test.E\"/>\n"+
119             "</class-descriptor>\n"+
120             "<class-descriptor\n"+
121             " class=\"test.E\"\n"+
122             " table=\"E\"\n"+
123             ">\n"+
124             "</class-descriptor>",
125             runOjbXDoclet(OJB_DEST_FILE));
126         assertEqualsTorqueSchemaFile(
127             "<database name=\"ojbtest\">\n"+
128             " <table name=\"A\">\n"+
129             " </table>\n"+
130             " <table name=\"C\">\n"+
131             " </table>\n"+
132             " <table name=\"E\">\n"+
133             " </table>\n"+
134             "</database>",
135             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
136     }
137
138     // Test of generate-table-info: 'false' value
139
public void testGenerateTableInfo5()
140     {
141         addClass(
142             "test.A",
143             "package test;\n"+
144             "/** @ojb.class generate-table-info=\"false\" */\n"+
145             "public class A {}\n");
146
147         assertEqualsOjbDescriptorFile(
148             "<class-descriptor\n"+
149             " class=\"test.A\"\n"+
150             ">\n"+
151             "</class-descriptor>",
152             runOjbXDoclet(OJB_DEST_FILE));
153         assertEqualsTorqueSchemaFile(
154             "<database name=\"ojbtest\">\n"+
155             "</database>",
156             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
157     }
158
159     // Test of generate-table-info: 'false' value with remote base- and subclass and a reference
160
public void testGenerateTableInfo6()
161     {
162         addClass(
163             "test.A",
164             "package test;\n"+
165             "/** @ojb.class */\n"+
166             "public class A {\n"+
167             " /** @ojb.field primarykey=\"true\" */\n"+
168             " private int id;\n"+
169             "}\n");
170         addClass(
171             "test.B",
172             "package test;\n"+
173             "public class B extends A {}\n");
174         addClass(
175             "test.C",
176             "package test;\n"+
177             "/** @ojb.class generate-table-info=\"false\" */\n"+
178             "public class C extends B {}\n");
179         addClass(
180             "test.D",
181             "package test;\n"+
182             "public class D extends C {}\n");
183         addClass(
184             "test.E",
185             "package test;\n"+
186             "/** @ojb.class */\n"+
187             "public class E extends D {}\n");
188
189         assertEqualsOjbDescriptorFile(
190             "<class-descriptor\n"+
191             " class=\"test.A\"\n"+
192             " table=\"A\"\n"+
193             ">\n"+
194             " <extent-class class-ref=\"test.C\"/>\n"+
195             " <field-descriptor\n"+
196             " name=\"id\"\n"+
197             " column=\"id\"\n"+
198             " jdbc-type=\"INTEGER\"\n"+
199             " primarykey=\"true\"\n"+
200             " >\n"+
201             " </field-descriptor>\n"+
202             "</class-descriptor>\n"+
203             "<class-descriptor\n"+
204             " class=\"test.C\"\n"+
205             ">\n"+
206             " <extent-class class-ref=\"test.E\"/>\n"+
207             " <field-descriptor\n"+
208             " name=\"id\"\n"+
209             " column=\"id\"\n"+
210             " jdbc-type=\"INTEGER\"\n"+
211             " primarykey=\"true\"\n"+
212             " >\n"+
213             " </field-descriptor>\n"+
214             "</class-descriptor>\n"+
215             "<class-descriptor\n"+
216             " class=\"test.E\"\n"+
217             " table=\"E\"\n"+
218             ">\n"+
219             " <field-descriptor\n"+
220             " name=\"id\"\n"+
221             " column=\"id\"\n"+
222             " jdbc-type=\"INTEGER\"\n"+
223             " primarykey=\"true\"\n"+
224             " >\n"+
225             " </field-descriptor>\n"+
226             "</class-descriptor>",
227             runOjbXDoclet(OJB_DEST_FILE));
228         assertEqualsTorqueSchemaFile(
229             "<database name=\"ojbtest\">\n"+
230             " <table name=\"A\">\n"+
231             " <column name=\"id\"\n"+
232             " javaName=\"id\"\n"+
233             " type=\"INTEGER\"\n"+
234             " primaryKey=\"true\"\n"+
235             " required=\"true\"\n"+
236             " />\n"+
237             " </table>\n"+
238             " <table name=\"E\">\n"+
239             " <column name=\"id\"\n"+
240             " javaName=\"id\"\n"+
241             " type=\"INTEGER\"\n"+
242             " primaryKey=\"true\"\n"+
243             " required=\"true\"\n"+
244             " />\n"+
245             " </table>\n"+
246             "</database>",
247             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
248     }
249
250     // Test of generate-table-info: used as reference target
251
public void testGenerateTableInfo7()
252     {
253         addClass(
254             "test.A",
255             "package test;\n"+
256             "/** @ojb.class generate-table-info=\"false\" */\n"+
257             "public class A {\n"+
258             " /** @ojb.field primarykey=\"true\" */\n"+
259             " private int id;\n"+
260             "}\n");
261         addClass(
262             "test.B",
263             "package test;\n"+
264             "/** @ojb.class */\n"+
265             "public class B extends A {}\n");
266         addClass(
267             "test.C",
268             "package test;\n"+
269             "/** @ojb.class */\n"+
270             "public class C {\n"+
271             " /** @ojb.field */\n"+
272             " private int aid;\n"+
273             " /** @ojb.reference foreignkey=\"aid\" */\n"+
274             " private A attr;\n"+
275             "}\n");
276
277         assertEqualsOjbDescriptorFile(
278             "<class-descriptor\n"+
279             " class=\"test.A\"\n"+
280             ">\n"+
281             " <extent-class class-ref=\"test.B\"/>\n"+
282             " <field-descriptor\n"+
283             " name=\"id\"\n"+
284             " column=\"id\"\n"+
285             " jdbc-type=\"INTEGER\"\n"+
286             " primarykey=\"true\"\n"+
287             " >\n"+
288             " </field-descriptor>\n"+
289             "</class-descriptor>\n"+
290             "<class-descriptor\n"+
291             " class=\"test.B\"\n"+
292             " table=\"B\"\n"+
293             ">\n"+
294             " <field-descriptor\n"+
295             " name=\"id\"\n"+
296             " column=\"id\"\n"+
297             " jdbc-type=\"INTEGER\"\n"+
298             " primarykey=\"true\"\n"+
299             " >\n"+
300             " </field-descriptor>\n"+
301             "</class-descriptor>\n"+
302             "<class-descriptor\n"+
303             " class=\"test.C\"\n"+
304             " table=\"C\"\n"+
305             ">\n"+
306             " <field-descriptor\n"+
307             " name=\"aid\"\n"+
308             " column=\"aid\"\n"+
309             " jdbc-type=\"INTEGER\"\n"+
310             " >\n"+
311             " </field-descriptor>\n"+
312             " <reference-descriptor\n"+
313             " name=\"attr\"\n"+
314             " class-ref=\"test.A\"\n"+
315             " >\n"+
316             " <foreignkey field-ref=\"aid\"/>\n"+
317             " </reference-descriptor>\n"+
318             "</class-descriptor>",
319             runOjbXDoclet(OJB_DEST_FILE));
320         assertEqualsTorqueSchemaFile(
321             "<database name=\"ojbtest\">\n"+
322             " <table name=\"B\">\n"+
323             " <column name=\"id\"\n"+
324             " javaName=\"id\"\n"+
325             " type=\"INTEGER\"\n"+
326             " primaryKey=\"true\"\n"+
327             " required=\"true\"\n"+
328             " />\n"+
329             " </table>\n"+
330             " <table name=\"C\">\n"+
331             " <column name=\"aid\"\n"+
332             " javaName=\"aid\"\n"+
333             " type=\"INTEGER\"\n"+
334             " />\n"+
335             " <foreign-key foreignTable=\"B\">\n"+
336             " <reference local=\"aid\" foreign=\"id\"/>\n"+
337             " </foreign-key>\n"+
338             " </table>\n"+
339             "</database>",
340             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
341     }
342
343     // Test of generate-table-info: used as reference target
344
public void testGenerateTableInfo8()
345     {
346         addClass(
347             "test.A",
348             "package test;\n"+
349             "/** @ojb.class generate-table-info=\"false\" */\n"+
350             "public class A {\n"+
351             " /** @ojb.field primarykey=\"true\" */\n"+
352             " private int id;\n"+
353             "}\n");
354         addClass(
355             "test.B",
356             "package test;\n"+
357             "/** @ojb.class */\n"+
358             "public class B extends A {}\n");
359         addClass(
360             "test.C",
361             "package test;\n"+
362             "/** @ojb.class */\n"+
363             "public class C extends B {}\n");
364         addClass(
365             "test.D",
366             "package test;\n"+
367             "/** @ojb.class */\n"+
368             "public class D {\n"+
369             " /** @ojb.field */\n"+
370             " private int aid;\n"+
371             " /** @ojb.reference foreignkey=\"aid\" */\n"+
372             " private A attr;\n"+
373             "}\n");
374
375         assertEqualsOjbDescriptorFile(
376             "<class-descriptor\n"+
377             " class=\"test.A\"\n"+
378             ">\n"+
379             " <extent-class class-ref=\"test.B\"/>\n"+
380             " <field-descriptor\n"+
381             " name=\"id\"\n"+
382             " column=\"id\"\n"+
383             " jdbc-type=\"INTEGER\"\n"+
384             " primarykey=\"true\"\n"+
385             " >\n"+
386             " </field-descriptor>\n"+
387             "</class-descriptor>\n"+
388             "<class-descriptor\n"+
389             " class=\"test.B\"\n"+
390             " table=\"B\"\n"+
391             ">\n"+
392             " <extent-class class-ref=\"test.C\"/>\n"+
393             " <field-descriptor\n"+
394             " name=\"id\"\n"+
395             " column=\"id\"\n"+
396             " jdbc-type=\"INTEGER\"\n"+
397             " primarykey=\"true\"\n"+
398             " >\n"+
399             " </field-descriptor>\n"+
400             "</class-descriptor>\n"+
401             "<class-descriptor\n"+
402             " class=\"test.C\"\n"+
403             " table=\"C\"\n"+
404             ">\n"+
405             " <field-descriptor\n"+
406             " name=\"id\"\n"+
407             " column=\"id\"\n"+
408             " jdbc-type=\"INTEGER\"\n"+
409             " primarykey=\"true\"\n"+
410             " >\n"+
411             " </field-descriptor>\n"+
412             "</class-descriptor>\n"+
413             "<class-descriptor\n"+
414             " class=\"test.D\"\n"+
415             " table=\"D\"\n"+
416             ">\n"+
417             " <field-descriptor\n"+
418             " name=\"aid\"\n"+
419             " column=\"aid\"\n"+
420             " jdbc-type=\"INTEGER\"\n"+
421             " >\n"+
422             " </field-descriptor>\n"+
423             " <reference-descriptor\n"+
424             " name=\"attr\"\n"+
425             " class-ref=\"test.A\"\n"+
426             " >\n"+
427             " <foreignkey field-ref=\"aid\"/>\n"+
428             " </reference-descriptor>\n"+
429             "</class-descriptor>",
430             runOjbXDoclet(OJB_DEST_FILE));
431         assertEqualsTorqueSchemaFile(
432             "<database name=\"ojbtest\">\n"+
433             " <table name=\"B\">\n"+
434             " <column name=\"id\"\n"+
435             " javaName=\"id\"\n"+
436             " type=\"INTEGER\"\n"+
437             " primaryKey=\"true\"\n"+
438             " required=\"true\"\n"+
439             " />\n"+
440             " </table>\n"+
441             " <table name=\"C\">\n"+
442             " <column name=\"id\"\n"+
443             " javaName=\"id\"\n"+
444             " type=\"INTEGER\"\n"+
445             " primaryKey=\"true\"\n"+
446             " required=\"true\"\n"+
447             " />\n"+
448             " </table>\n"+
449             " <table name=\"D\">\n"+
450             " <column name=\"aid\"\n"+
451             " javaName=\"aid\"\n"+
452             " type=\"INTEGER\"\n"+
453             " />\n"+
454             " </table>\n"+
455             "</database>",
456             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
457     }
458 }
459
Popular Tags