KickJava   Java API By Example, From Geeks To Geeks.

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


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.collection tag with the auto-delete attribute
20  *
21  * @author <a HREF="mailto:tomdz@users.sourceforge.net">Thomas Dudziak (tomdz@users.sourceforge.net)</a>
22  */

23 public class CollectionTagAutoUpdateAttributeTests extends OjbTestBase
24 {
25     public CollectionTagAutoUpdateAttributeTests(String JavaDoc name)
26     {
27         super(name);
28     }
29
30     // Test: auto-update attribute has empty value
31
public void testAutoUpdate1()
32     {
33         addClass(
34             "test.A",
35             "package test;\n"+
36             "/** @ojb.class */\n"+
37             "public class A {\n"+
38             "/** @ojb.field primarykey=\"true\" */\n"+
39             " private int id;\n"+
40             "/** @ojb.collection element-class-ref=\"test.B\"\n"+
41             " * foreignkey=\"aid\"\n"+
42             " * auto-update=\"\"\n"+
43             " */\n"+
44             " private java.util.List objs;\n"+
45             "}\n");
46         addClass(
47             "test.B",
48             "package test;\n"+
49             "/** @ojb.class */\n"+
50             "public class B {\n"+
51             "/** @ojb.field */\n"+
52             " private int aid;\n"+
53             "}\n");
54
55         assertNull(runOjbXDoclet(OJB_DEST_FILE));
56         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
57     }
58
59     // Test: auto-update attribute has invalid value
60
public void testAutoUpdate2()
61     {
62         addClass(
63             "test.A",
64             "package test;\n"+
65             "/** @ojb.class */\n"+
66             "public class A {\n"+
67             "/** @ojb.field primarykey=\"true\" */\n"+
68             " private int id;\n"+
69             "/** @ojb.collection element-class-ref=\"test.B\"\n"+
70             " * foreignkey=\"aid\"\n"+
71             " * auto-update=\"no\"\n"+
72             " */\n"+
73             " private java.util.List objs;\n"+
74             "}\n");
75         addClass(
76             "test.B",
77             "package test;\n"+
78             "/** @ojb.class */\n"+
79             "public class B {\n"+
80             "/** @ojb.field */\n"+
81             " private int aid;\n"+
82             "}\n");
83
84         assertNull(runOjbXDoclet(OJB_DEST_FILE));
85         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
86     }
87
88     // Test: auto-update attribute has 'true' value
89
public void testAutoUpdate3()
90     {
91         addClass(
92             "test.A",
93             "package test;\n"+
94             "/** @ojb.class */\n"+
95             "public class A {\n"+
96             "/** @ojb.field primarykey=\"true\" */\n"+
97             " private int id;\n"+
98             "/** @ojb.collection element-class-ref=\"test.B\"\n"+
99             " * foreignkey=\"aid\"\n"+
100             " * auto-update=\"true\"\n"+
101             " */\n"+
102             " private java.util.List objs;\n"+
103             "}\n");
104         addClass(
105             "test.B",
106             "package test;\n"+
107             "/** @ojb.class */\n"+
108             "public class B {\n"+
109             "/** @ojb.field */\n"+
110             " private int aid;\n"+
111             "}\n");
112
113         assertEqualsOjbDescriptorFile(
114             "<class-descriptor\n"+
115             " class=\"test.A\"\n"+
116             " table=\"A\"\n"+
117             ">\n"+
118             " <field-descriptor\n"+
119             " name=\"id\"\n"+
120             " column=\"id\"\n"+
121             " jdbc-type=\"INTEGER\"\n"+
122             " primarykey=\"true\"\n"+
123             " >\n"+
124             " </field-descriptor>\n"+
125             " <collection-descriptor\n"+
126             " name=\"objs\"\n"+
127             " element-class-ref=\"test.B\"\n"+
128             " auto-update=\"true\"\n"+
129             " >\n"+
130             " <inverse-foreignkey field-ref=\"aid\"/>\n"+
131             " </collection-descriptor>\n"+
132             "</class-descriptor>\n"+
133             "<class-descriptor\n"+
134             " class=\"test.B\"\n"+
135             " table=\"B\"\n"+
136             ">\n"+
137             " <field-descriptor\n"+
138             " name=\"aid\"\n"+
139             " column=\"aid\"\n"+
140             " jdbc-type=\"INTEGER\"\n"+
141             " >\n"+
142             " </field-descriptor>\n"+
143             "</class-descriptor>",
144             runOjbXDoclet(OJB_DEST_FILE));
145         assertEqualsTorqueSchemaFile(
146             "<database name=\"ojbtest\">\n"+
147             " <table name=\"A\">\n"+
148             " <column name=\"id\"\n"+
149             " javaName=\"id\"\n"+
150             " type=\"INTEGER\"\n"+
151             " primaryKey=\"true\"\n"+
152             " required=\"true\"\n"+
153             " />\n"+
154             " </table>\n"+
155             " <table name=\"B\">\n"+
156             " <column name=\"aid\"\n"+
157             " javaName=\"aid\"\n"+
158             " type=\"INTEGER\"\n"+
159             " />\n"+
160             " <foreign-key foreignTable=\"A\">\n"+
161             " <reference local=\"aid\" foreign=\"id\"/>\n"+
162             " </foreign-key>\n"+
163             " </table>\n"+
164             "</database>",
165             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
166     }
167
168     // Test: auto-update attribute has 'false' value
169
public void testAutoUpdate4()
170     {
171         addClass(
172             "test.A",
173             "package test;\n"+
174             "/** @ojb.class */\n"+
175             "public class A {\n"+
176             "/** @ojb.field primarykey=\"true\" */\n"+
177             " private int id;\n"+
178             "/** @ojb.collection element-class-ref=\"test.B\"\n"+
179             " * foreignkey=\"aid\"\n"+
180             " * auto-update=\"false\"\n"+
181             " */\n"+
182             " private java.util.List objs;\n"+
183             "}\n");
184         addClass(
185             "test.B",
186             "package test;\n"+
187             "/** @ojb.class */\n"+
188             "public class B {\n"+
189             "/** @ojb.field */\n"+
190             " private int aid;\n"+
191             "}\n");
192
193         assertEqualsOjbDescriptorFile(
194             "<class-descriptor\n"+
195             " class=\"test.A\"\n"+
196             " table=\"A\"\n"+
197             ">\n"+
198             " <field-descriptor\n"+
199             " name=\"id\"\n"+
200             " column=\"id\"\n"+
201             " jdbc-type=\"INTEGER\"\n"+
202             " primarykey=\"true\"\n"+
203             " >\n"+
204             " </field-descriptor>\n"+
205             " <collection-descriptor\n"+
206             " name=\"objs\"\n"+
207             " element-class-ref=\"test.B\"\n"+
208             " auto-update=\"false\"\n"+
209             " >\n"+
210             " <inverse-foreignkey field-ref=\"aid\"/>\n"+
211             " </collection-descriptor>\n"+
212             "</class-descriptor>\n"+
213             "<class-descriptor\n"+
214             " class=\"test.B\"\n"+
215             " table=\"B\"\n"+
216             ">\n"+
217             " <field-descriptor\n"+
218             " name=\"aid\"\n"+
219             " column=\"aid\"\n"+
220             " jdbc-type=\"INTEGER\"\n"+
221             " >\n"+
222             " </field-descriptor>\n"+
223             "</class-descriptor>",
224             runOjbXDoclet(OJB_DEST_FILE));
225         assertEqualsTorqueSchemaFile(
226             "<database name=\"ojbtest\">\n"+
227             " <table name=\"A\">\n"+
228             " <column name=\"id\"\n"+
229             " javaName=\"id\"\n"+
230             " type=\"INTEGER\"\n"+
231             " primaryKey=\"true\"\n"+
232             " required=\"true\"\n"+
233             " />\n"+
234             " </table>\n"+
235             " <table name=\"B\">\n"+
236             " <column name=\"aid\"\n"+
237             " javaName=\"aid\"\n"+
238             " type=\"INTEGER\"\n"+
239             " />\n"+
240             " <foreign-key foreignTable=\"A\">\n"+
241             " <reference local=\"aid\" foreign=\"id\"/>\n"+
242             " </foreign-key>\n"+
243             " </table>\n"+
244             "</database>",
245             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
246     }
247
248     // Test: auto-update attribute has 'none' value
249
public void testAutoUpdate5()
250     {
251         addClass(
252             "test.A",
253             "package test;\n"+
254             "/** @ojb.class */\n"+
255             "public class A {\n"+
256             "/** @ojb.field primarykey=\"true\" */\n"+
257             " private int id;\n"+
258             "/** @ojb.collection element-class-ref=\"test.B\"\n"+
259             " * foreignkey=\"aid\"\n"+
260             " * auto-update=\"none\"\n"+
261             " */\n"+
262             " private java.util.List objs;\n"+
263             "}\n");
264         addClass(
265             "test.B",
266             "package test;\n"+
267             "/** @ojb.class */\n"+
268             "public class B {\n"+
269             "/** @ojb.field */\n"+
270             " private int aid;\n"+
271             "}\n");
272
273         assertEqualsOjbDescriptorFile(
274             "<class-descriptor\n"+
275             " class=\"test.A\"\n"+
276             " table=\"A\"\n"+
277             ">\n"+
278             " <field-descriptor\n"+
279             " name=\"id\"\n"+
280             " column=\"id\"\n"+
281             " jdbc-type=\"INTEGER\"\n"+
282             " primarykey=\"true\"\n"+
283             " >\n"+
284             " </field-descriptor>\n"+
285             " <collection-descriptor\n"+
286             " name=\"objs\"\n"+
287             " element-class-ref=\"test.B\"\n"+
288             " auto-update=\"none\"\n"+
289             " >\n"+
290             " <inverse-foreignkey field-ref=\"aid\"/>\n"+
291             " </collection-descriptor>\n"+
292             "</class-descriptor>\n"+
293             "<class-descriptor\n"+
294             " class=\"test.B\"\n"+
295             " table=\"B\"\n"+
296             ">\n"+
297             " <field-descriptor\n"+
298             " name=\"aid\"\n"+
299             " column=\"aid\"\n"+
300             " jdbc-type=\"INTEGER\"\n"+
301             " >\n"+
302             " </field-descriptor>\n"+
303             "</class-descriptor>",
304             runOjbXDoclet(OJB_DEST_FILE));
305         assertEqualsTorqueSchemaFile(
306             "<database name=\"ojbtest\">\n"+
307             " <table name=\"A\">\n"+
308             " <column name=\"id\"\n"+
309             " javaName=\"id\"\n"+
310             " type=\"INTEGER\"\n"+
311             " primaryKey=\"true\"\n"+
312             " required=\"true\"\n"+
313             " />\n"+
314             " </table>\n"+
315             " <table name=\"B\">\n"+
316             " <column name=\"aid\"\n"+
317             " javaName=\"aid\"\n"+
318             " type=\"INTEGER\"\n"+
319             " />\n"+
320             " <foreign-key foreignTable=\"A\">\n"+
321             " <reference local=\"aid\" foreign=\"id\"/>\n"+
322             " </foreign-key>\n"+
323             " </table>\n"+
324             "</database>",
325             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
326     }
327
328     // Test: auto-update attribute has 'link' value
329
public void testAutoUpdate6()
330     {
331         addClass(
332             "test.A",
333             "package test;\n"+
334             "/** @ojb.class */\n"+
335             "public class A {\n"+
336             "/** @ojb.field primarykey=\"true\" */\n"+
337             " private int id;\n"+
338             "/** @ojb.collection element-class-ref=\"test.B\"\n"+
339             " * foreignkey=\"aid\"\n"+
340             " * auto-update=\"link\"\n"+
341             " */\n"+
342             " private java.util.List objs;\n"+
343             "}\n");
344         addClass(
345             "test.B",
346             "package test;\n"+
347             "/** @ojb.class */\n"+
348             "public class B {\n"+
349             "/** @ojb.field */\n"+
350             " private int aid;\n"+
351             "}\n");
352
353         assertEqualsOjbDescriptorFile(
354             "<class-descriptor\n"+
355             " class=\"test.A\"\n"+
356             " table=\"A\"\n"+
357             ">\n"+
358             " <field-descriptor\n"+
359             " name=\"id\"\n"+
360             " column=\"id\"\n"+
361             " jdbc-type=\"INTEGER\"\n"+
362             " primarykey=\"true\"\n"+
363             " >\n"+
364             " </field-descriptor>\n"+
365             " <collection-descriptor\n"+
366             " name=\"objs\"\n"+
367             " element-class-ref=\"test.B\"\n"+
368             " auto-update=\"link\"\n"+
369             " >\n"+
370             " <inverse-foreignkey field-ref=\"aid\"/>\n"+
371             " </collection-descriptor>\n"+
372             "</class-descriptor>\n"+
373             "<class-descriptor\n"+
374             " class=\"test.B\"\n"+
375             " table=\"B\"\n"+
376             ">\n"+
377             " <field-descriptor\n"+
378             " name=\"aid\"\n"+
379             " column=\"aid\"\n"+
380             " jdbc-type=\"INTEGER\"\n"+
381             " >\n"+
382             " </field-descriptor>\n"+
383             "</class-descriptor>",
384             runOjbXDoclet(OJB_DEST_FILE));
385         assertEqualsTorqueSchemaFile(
386             "<database name=\"ojbtest\">\n"+
387             " <table name=\"A\">\n"+
388             " <column name=\"id\"\n"+
389             " javaName=\"id\"\n"+
390             " type=\"INTEGER\"\n"+
391             " primaryKey=\"true\"\n"+
392             " required=\"true\"\n"+
393             " />\n"+
394             " </table>\n"+
395             " <table name=\"B\">\n"+
396             " <column name=\"aid\"\n"+
397             " javaName=\"aid\"\n"+
398             " type=\"INTEGER\"\n"+
399             " />\n"+
400             " <foreign-key foreignTable=\"A\">\n"+
401             " <reference local=\"aid\" foreign=\"id\"/>\n"+
402             " </foreign-key>\n"+
403             " </table>\n"+
404             "</database>",
405             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
406     }
407
408     // Test: auto-update attribute has 'object' value
409
public void testAutoUpdate7()
410     {
411         addClass(
412             "test.A",
413             "package test;\n"+
414             "/** @ojb.class */\n"+
415             "public class A {\n"+
416             "/** @ojb.field primarykey=\"true\" */\n"+
417             " private int id;\n"+
418             "/** @ojb.collection element-class-ref=\"test.B\"\n"+
419             " * foreignkey=\"aid\"\n"+
420             " * auto-update=\"object\"\n"+
421             " */\n"+
422             " private java.util.List objs;\n"+
423             "}\n");
424         addClass(
425             "test.B",
426             "package test;\n"+
427             "/** @ojb.class */\n"+
428             "public class B {\n"+
429             "/** @ojb.field */\n"+
430             " private int aid;\n"+
431             "}\n");
432
433         assertEqualsOjbDescriptorFile(
434             "<class-descriptor\n"+
435             " class=\"test.A\"\n"+
436             " table=\"A\"\n"+
437             ">\n"+
438             " <field-descriptor\n"+
439             " name=\"id\"\n"+
440             " column=\"id\"\n"+
441             " jdbc-type=\"INTEGER\"\n"+
442             " primarykey=\"true\"\n"+
443             " >\n"+
444             " </field-descriptor>\n"+
445             " <collection-descriptor\n"+
446             " name=\"objs\"\n"+
447             " element-class-ref=\"test.B\"\n"+
448             " auto-update=\"object\"\n"+
449             " >\n"+
450             " <inverse-foreignkey field-ref=\"aid\"/>\n"+
451             " </collection-descriptor>\n"+
452             "</class-descriptor>\n"+
453             "<class-descriptor\n"+
454             " class=\"test.B\"\n"+
455             " table=\"B\"\n"+
456             ">\n"+
457             " <field-descriptor\n"+
458             " name=\"aid\"\n"+
459             " column=\"aid\"\n"+
460             " jdbc-type=\"INTEGER\"\n"+
461             " >\n"+
462             " </field-descriptor>\n"+
463             "</class-descriptor>",
464             runOjbXDoclet(OJB_DEST_FILE));
465         assertEqualsTorqueSchemaFile(
466             "<database name=\"ojbtest\">\n"+
467             " <table name=\"A\">\n"+
468             " <column name=\"id\"\n"+
469             " javaName=\"id\"\n"+
470             " type=\"INTEGER\"\n"+
471             " primaryKey=\"true\"\n"+
472             " required=\"true\"\n"+
473             " />\n"+
474             " </table>\n"+
475             " <table name=\"B\">\n"+
476             " <column name=\"aid\"\n"+
477             " javaName=\"aid\"\n"+
478             " type=\"INTEGER\"\n"+
479             " />\n"+
480             " <foreign-key foreignTable=\"A\">\n"+
481             " <reference local=\"aid\" foreign=\"id\"/>\n"+
482             " </foreign-key>\n"+
483             " </table>\n"+
484             "</database>",
485             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
486     }
487
488     // Test: inherited auto-update attribute
489
public void testAutoUpdate8()
490     {
491         addClass(
492             "test.A",
493             "package test;\n"+
494             "/** @ojb.class */\n"+
495             "public class A {\n"+
496             "/** @ojb.field primarykey=\"true\" */\n"+
497             " private int id;\n"+
498             "/** @ojb.collection element-class-ref=\"test.B\"\n"+
499             " * foreignkey=\"aid\"\n"+
500             " * auto-update=\"object\"\n"+
501             " * database-foreignkey=\"false\"\n"+
502             " */\n"+
503             " private java.util.List objs;\n"+
504             "}\n");
505         addClass(
506             "test.B",
507             "package test;\n"+
508             "/** @ojb.class */\n"+
509             "public class B {\n"+
510             "/** @ojb.field */\n"+
511             " private int aid;\n"+
512             "}\n");
513         addClass(
514             "test.C",
515             "package test;\n"+
516             "/** @ojb.class */\n"+
517             "public class C extends A {}\n");
518
519         assertEqualsOjbDescriptorFile(
520             "<class-descriptor\n"+
521             " class=\"test.A\"\n"+
522             " table=\"A\"\n"+
523             ">\n"+
524             " <extent-class class-ref=\"test.C\"/>\n"+
525             " <field-descriptor\n"+
526             " name=\"id\"\n"+
527             " column=\"id\"\n"+
528             " jdbc-type=\"INTEGER\"\n"+
529             " primarykey=\"true\"\n"+
530             " >\n"+
531             " </field-descriptor>\n"+
532             " <collection-descriptor\n"+
533             " name=\"objs\"\n"+
534             " element-class-ref=\"test.B\"\n"+
535             " auto-update=\"object\"\n"+
536             " >\n"+
537             " <inverse-foreignkey field-ref=\"aid\"/>\n"+
538             " </collection-descriptor>\n"+
539             "</class-descriptor>\n"+
540             "<class-descriptor\n"+
541             " class=\"test.B\"\n"+
542             " table=\"B\"\n"+
543             ">\n"+
544             " <field-descriptor\n"+
545             " name=\"aid\"\n"+
546             " column=\"aid\"\n"+
547             " jdbc-type=\"INTEGER\"\n"+
548             " >\n"+
549             " </field-descriptor>\n"+
550             "</class-descriptor>\n"+
551             "<class-descriptor\n"+
552             " class=\"test.C\"\n"+
553             " table=\"C\"\n"+
554             ">\n"+
555             " <field-descriptor\n"+
556             " name=\"id\"\n"+
557             " column=\"id\"\n"+
558             " jdbc-type=\"INTEGER\"\n"+
559             " primarykey=\"true\"\n"+
560             " >\n"+
561             " </field-descriptor>\n"+
562             " <collection-descriptor\n"+
563             " name=\"objs\"\n"+
564             " element-class-ref=\"test.B\"\n"+
565             " auto-update=\"object\"\n"+
566             " >\n"+
567             " <inverse-foreignkey field-ref=\"aid\"/>\n"+
568             " </collection-descriptor>\n"+
569             "</class-descriptor>",
570             runOjbXDoclet(OJB_DEST_FILE));
571         assertEqualsTorqueSchemaFile(
572             "<database name=\"ojbtest\">\n"+
573             " <table name=\"A\">\n"+
574             " <column name=\"id\"\n"+
575             " javaName=\"id\"\n"+
576             " type=\"INTEGER\"\n"+
577             " primaryKey=\"true\"\n"+
578             " required=\"true\"\n"+
579             " />\n"+
580             " </table>\n"+
581             " <table name=\"B\">\n"+
582             " <column name=\"aid\"\n"+
583             " javaName=\"aid\"\n"+
584             " type=\"INTEGER\"\n"+
585             " />\n"+
586             " </table>\n"+
587             " <table name=\"C\">\n"+
588             " <column name=\"id\"\n"+
589             " javaName=\"id\"\n"+
590             " type=\"INTEGER\"\n"+
591             " primaryKey=\"true\"\n"+
592             " required=\"true\"\n"+
593             " />\n"+
594             " </table>\n"+
595             "</database>",
596             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
597     }
598 }
599
Popular Tags