KickJava   Java API By Example, From Geeks To Geeks.

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


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

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