KickJava   Java API By Example, From Geeks To Geeks.

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


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.modify-inherited tag with the ignore attribute.
20  *
21  * @author <a HREF="mailto:tomdz@apache.org">Thomas Dudziak</a>
22  */

23 public class ModifyInheritedTagIgnoreAttributeTests extends OjbTestBase
24 {
25     public ModifyInheritedTagIgnoreAttributeTests(String JavaDoc name)
26     {
27         super(name);
28     }
29
30     // Test: ignoring a base class field from a direct base class
31
public void testIgnore1()
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 attr;\n"+
40             "}");
41         addClass(
42             "test.B",
43             "package test;\n"+
44             "/** @ojb.class\n" +
45             " * @ojb.modify-inherited name=\"attr\"\n"+
46             " * ignore=\"true\"\n"+
47             " */\n"+
48             "public class B extends A {}\n");
49
50         assertEqualsOjbDescriptorFile(
51             "<class-descriptor\n"+
52             " class=\"test.A\"\n"+
53             " table=\"A\"\n"+
54             ">\n"+
55             " <extent-class class-ref=\"test.B\"/>\n"+
56             " <field-descriptor\n"+
57             " name=\"attr\"\n"+
58             " column=\"attr\"\n"+
59             " jdbc-type=\"INTEGER\"\n"+
60             " >\n"+
61             " </field-descriptor>\n"+
62             "</class-descriptor>\n"+
63             "<class-descriptor\n"+
64             " class=\"test.B\"\n"+
65             " table=\"B\"\n"+
66             ">\n"+
67             "</class-descriptor>",
68             runOjbXDoclet(OJB_DEST_FILE));
69         assertEqualsTorqueSchemaFile(
70             "<database name=\"ojbtest\">\n"+
71             " <table name=\"A\">\n"+
72             " <column name=\"attr\"\n"+
73             " javaName=\"attr\"\n"+
74             " type=\"INTEGER\"\n"+
75             " />\n"+
76             " </table>\n"+
77             " <table name=\"B\">\n"+
78             " </table>\n"+
79             "</database>",
80             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
81     }
82
83     // Test: ignoring a base class reference from an indirect base class
84
public void testIgnore2()
85     {
86         addClass(
87             "test.A",
88             "package test;\n"+
89             "/** @ojb.class */\n" +
90             "public class A {\n"+
91             " /** @ojb.field */\n"+
92             " private int bid;\n"+
93             " /** @ojb.reference foreignkey=\"bid\" */\n"+
94             " private B b;\n"+
95             "}");
96         addClass(
97             "test.B",
98             "package test;\n"+
99             "/** @ojb.class */\n" +
100             "public class B {\n"+
101             " /** @ojb.field primarykey=\"true\" */\n"+
102             " private int id;\n"+
103             "}");
104         addClass(
105             "test.C",
106             "package test;\n"+
107             "public class C extends A {}");
108         addClass(
109             "test.D",
110             "package test;\n"+
111             "/** @ojb.class */\n" +
112             "public class D extends C {}");
113         addClass(
114             "test.E",
115             "package test;\n"+
116             "/** @ojb.class\n" +
117             " * @ojb.modify-inherited name=\"b\"\n"+
118             " * ignore=\"true\"\n"+
119             " */\n"+
120             "public class E extends D {}\n");
121
122         assertEqualsOjbDescriptorFile(
123             "<class-descriptor\n"+
124             " class=\"test.A\"\n"+
125             " table=\"A\"\n"+
126             ">\n"+
127             " <extent-class class-ref=\"test.D\"/>\n"+
128             " <field-descriptor\n"+
129             " name=\"bid\"\n"+
130             " column=\"bid\"\n"+
131             " jdbc-type=\"INTEGER\"\n"+
132             " >\n"+
133             " </field-descriptor>\n"+
134             " <reference-descriptor\n"+
135             " name=\"b\"\n"+
136             " class-ref=\"test.B\"\n"+
137             " >\n"+
138             " <foreignkey field-ref=\"bid\"/>\n"+
139             " </reference-descriptor>\n"+
140             "</class-descriptor>\n"+
141             "<class-descriptor\n"+
142             " class=\"test.B\"\n"+
143             " table=\"B\"\n"+
144             ">\n"+
145             " <field-descriptor\n"+
146             " name=\"id\"\n"+
147             " column=\"id\"\n"+
148             " jdbc-type=\"INTEGER\"\n"+
149             " primarykey=\"true\"\n"+
150             " >\n"+
151             " </field-descriptor>\n"+
152             "</class-descriptor>\n"+
153             "<class-descriptor\n"+
154             " class=\"test.D\"\n"+
155             " table=\"D\"\n"+
156             ">\n"+
157             " <extent-class class-ref=\"test.E\"/>\n"+
158             " <field-descriptor\n"+
159             " name=\"bid\"\n"+
160             " column=\"bid\"\n"+
161             " jdbc-type=\"INTEGER\"\n"+
162             " >\n"+
163             " </field-descriptor>\n"+
164             " <reference-descriptor\n"+
165             " name=\"b\"\n"+
166             " class-ref=\"test.B\"\n"+
167             " >\n"+
168             " <foreignkey field-ref=\"bid\"/>\n"+
169             " </reference-descriptor>\n"+
170             "</class-descriptor>\n"+
171             "<class-descriptor\n"+
172             " class=\"test.E\"\n"+
173             " table=\"E\"\n"+
174             ">\n"+
175             " <field-descriptor\n"+
176             " name=\"bid\"\n"+
177             " column=\"bid\"\n"+
178             " jdbc-type=\"INTEGER\"\n"+
179             " >\n"+
180             " </field-descriptor>\n"+
181             "</class-descriptor>",
182             runOjbXDoclet(OJB_DEST_FILE));
183         assertEqualsTorqueSchemaFile(
184             "<database name=\"ojbtest\">\n"+
185             " <table name=\"A\">\n"+
186             " <column name=\"bid\"\n"+
187             " javaName=\"bid\"\n"+
188             " type=\"INTEGER\"\n"+
189             " />\n"+
190             " <foreign-key foreignTable=\"B\">\n"+
191             " <reference local=\"bid\" foreign=\"id\"/>\n"+
192             " </foreign-key>\n"+
193             " </table>\n"+
194             " <table name=\"B\">\n"+
195             " <column name=\"id\"\n"+
196             " javaName=\"id\"\n"+
197             " type=\"INTEGER\"\n"+
198             " primaryKey=\"true\"\n"+
199             " required=\"true\"\n"+
200             " />\n"+
201             " </table>\n"+
202             " <table name=\"D\">\n"+
203             " <column name=\"bid\"\n"+
204             " javaName=\"bid\"\n"+
205             " type=\"INTEGER\"\n"+
206             " />\n"+
207             " <foreign-key foreignTable=\"B\">\n"+
208             " <reference local=\"bid\" foreign=\"id\"/>\n"+
209             " </foreign-key>\n"+
210             " </table>\n"+
211             " <table name=\"E\">\n"+
212             " <column name=\"bid\"\n"+
213             " javaName=\"bid\"\n"+
214             " type=\"INTEGER\"\n"+
215             " />\n"+
216             " </table>\n"+
217             "</database>",
218             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
219     }
220
221     // Test: ignoring a base class collection, but not ignoring it in a subtype
222
public void testIgnore3()
223     {
224         addClass(
225             "test.A",
226             "package test;\n"+
227             "/** @ojb.class */\n" +
228             "public class A {\n"+
229             " /** @ojb.field primarykey=\"true\" */\n"+
230             " private int id;\n"+
231             " /** @ojb.collection element-class-ref=\"test.B\"\n"+
232             " * foreignkey=\"aid\"\n"+
233             " * database-foreignkey=\"false\"\n"+
234             " */\n"+
235             " private java.util.Collection bs;\n"+
236             "}");
237         addClass(
238             "test.B",
239             "package test;\n"+
240             "/** @ojb.class */\n" +
241             "public class B {\n"+
242             " /** @ojb.field */\n"+
243             " private int aid;\n"+
244             "}");
245         addClass(
246             "test.C",
247             "package test;\n"+
248             "/** @ojb.class\n" +
249             " * @ojb.modify-inherited name=\"bs\"\n"+
250             " * ignore=\"true\"\n"+
251             " */\n"+
252             "public class C extends A {}\n");
253         addClass(
254             "test.D",
255             "package test;\n"+
256             "/** @ojb.class */\n"+
257             "public class D extends C {}\n");
258
259         assertEqualsOjbDescriptorFile(
260             "<class-descriptor\n"+
261             " class=\"test.A\"\n"+
262             " table=\"A\"\n"+
263             ">\n"+
264             " <extent-class class-ref=\"test.C\"/>\n"+
265             " <field-descriptor\n"+
266             " name=\"id\"\n"+
267             " column=\"id\"\n"+
268             " jdbc-type=\"INTEGER\"\n"+
269             " primarykey=\"true\"\n"+
270             " >\n"+
271             " </field-descriptor>\n"+
272             " <collection-descriptor\n"+
273             " name=\"bs\"\n"+
274             " element-class-ref=\"test.B\"\n"+
275             " >\n"+
276             " <inverse-foreignkey field-ref=\"aid\"/>\n"+
277             " </collection-descriptor>\n"+
278             "</class-descriptor>\n"+
279             "<class-descriptor\n"+
280             " class=\"test.B\"\n"+
281             " table=\"B\"\n"+
282             ">\n"+
283             " <field-descriptor\n"+
284             " name=\"aid\"\n"+
285             " column=\"aid\"\n"+
286             " jdbc-type=\"INTEGER\"\n"+
287             " >\n"+
288             " </field-descriptor>\n"+
289             "</class-descriptor>\n"+
290             "<class-descriptor\n"+
291             " class=\"test.C\"\n"+
292             " table=\"C\"\n"+
293             ">\n"+
294             " <extent-class class-ref=\"test.D\"/>\n"+
295             " <field-descriptor\n"+
296             " name=\"id\"\n"+
297             " column=\"id\"\n"+
298             " jdbc-type=\"INTEGER\"\n"+
299             " primarykey=\"true\"\n"+
300             " >\n"+
301             " </field-descriptor>\n"+
302             "</class-descriptor>\n"+
303             "<class-descriptor\n"+
304             " class=\"test.D\"\n"+
305             " table=\"D\"\n"+
306             ">\n"+
307             " <field-descriptor\n"+
308             " name=\"id\"\n"+
309             " column=\"id\"\n"+
310             " jdbc-type=\"INTEGER\"\n"+
311             " primarykey=\"true\"\n"+
312             " >\n"+
313             " </field-descriptor>\n"+
314             " <collection-descriptor\n"+
315             " name=\"bs\"\n"+
316             " element-class-ref=\"test.B\"\n"+
317             " >\n"+
318             " <inverse-foreignkey field-ref=\"aid\"/>\n"+
319             " </collection-descriptor>\n"+
320             "</class-descriptor>",
321             runOjbXDoclet(OJB_DEST_FILE));
322         assertEqualsTorqueSchemaFile(
323             "<database name=\"ojbtest\">\n"+
324             " <table name=\"A\">\n"+
325             " <column name=\"id\"\n"+
326             " javaName=\"id\"\n"+
327             " type=\"INTEGER\"\n"+
328             " primaryKey=\"true\"\n"+
329             " required=\"true\"\n"+
330             " />\n"+
331             " </table>\n"+
332             " <table name=\"B\">\n"+
333             " <column name=\"aid\"\n"+
334             " javaName=\"aid\"\n"+
335             " type=\"INTEGER\"\n"+
336             " />\n"+
337             " </table>\n"+
338             " <table name=\"C\">\n"+
339             " <column name=\"id\"\n"+
340             " javaName=\"id\"\n"+
341             " type=\"INTEGER\"\n"+
342             " primaryKey=\"true\"\n"+
343             " required=\"true\"\n"+
344             " />\n"+
345             " </table>\n"+
346             " <table name=\"D\">\n"+
347             " <column name=\"id\"\n"+
348             " javaName=\"id\"\n"+
349             " type=\"INTEGER\"\n"+
350             " primaryKey=\"true\"\n"+
351             " required=\"true\"\n"+
352             " />\n"+
353             " </table>\n"+
354             "</database>",
355             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
356     }
357
358     // Test: ignoring an undefined field
359
public void testIgnore4()
360     {
361         addClass(
362             "test.A",
363             "package test;\n"+
364             "/** @ojb.class */\n" +
365             "public class A {\n"+
366             " /** @ojb.field */\n"+
367             " private int attr;\n"+
368             "}");
369         addClass(
370             "test.B",
371             "package test;\n"+
372             "/** @ojb.class\n" +
373             " * @ojb.modify-inherited name=\"bttr\"\n"+
374             " * ignore=\"true\"\n"+
375             " */\n"+
376             "public class B extends A {}\n");
377
378         assertNull(runOjbXDoclet(OJB_DEST_FILE));
379         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
380     }
381
382     // Test: ignoring a field used as a reference foreignkey in the same class
383
public void testIgnore5()
384     {
385         addClass(
386             "test.A",
387             "package test;\n"+
388             "/** @ojb.class */\n" +
389             "public class A {\n"+
390             " /** @ojb.field */\n"+
391             " private int bid;\n"+
392             " /** @ojb.reference foreignkey=\"bid\" */\n"+
393             " private B b;\n"+
394             "}");
395         addClass(
396             "test.B",
397             "package test;\n"+
398             "/** @ojb.class */\n" +
399             "public class B {\n"+
400             " /** @ojb.field primarykey=\"true\" */\n"+
401             " private int id;\n"+
402             "}");
403         addClass(
404             "test.C",
405             "package test;\n"+
406             "/** @ojb.class\n" +
407             " * @ojb.modify-inherited name=\"bid\"\n"+
408             " * ignore=\"true\"\n"+
409             " */\n"+
410             "public class C extends A {}\n");
411
412         assertNull(runOjbXDoclet(OJB_DEST_FILE));
413         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
414     }
415
416     // Test: ignoring a primary key field of a type used in a reference
417
public void testIgnore6()
418     {
419         addClass(
420             "test.A",
421             "package test;\n"+
422             "/** @ojb.class */\n" +
423             "public class A {\n"+
424             " /** @ojb.field */\n"+
425             " private int bid;\n"+
426             " /** @ojb.reference foreignkey=\"bid\" */\n"+
427             " private B b;\n"+
428             "}");
429         addClass(
430             "test.B",
431             "package test;\n"+
432             "/** @ojb.class */\n" +
433             "public class B {\n"+
434             " /** @ojb.field primarykey=\"true\" */\n"+
435             " private int id;\n"+
436             "}");
437         addClass(
438             "test.C",
439             "package test;\n"+
440             "/** @ojb.class\n" +
441             " * @ojb.modify-inherited name=\"id\"\n"+
442             " * ignore=\"true\"\n"+
443             " */\n"+
444             "public class C extends B {}\n");
445
446         assertNull(runOjbXDoclet(OJB_DEST_FILE));
447         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
448     }
449
450     // Test: ignoring a field used as a collection foreignkey
451
public void testIgnore7()
452     {
453         addClass(
454             "test.A",
455             "package test;\n"+
456             "/** @ojb.class */\n" +
457             "public class A {\n"+
458             " /** @ojb.collection element-class-ref=\"test.B\"\n"+
459             " * foreignkey=\"aid\"\n"+
460             " */\n"+
461             " private java.util.Collection bs;\n"+
462             "}");
463         addClass(
464             "test.B",
465             "package test;\n"+
466             "/** @ojb.class */\n" +
467             "public class B {\n"+
468             " /** @ojb.field */\n"+
469             " private int aid;\n"+
470             "}");
471         addClass(
472             "test.C",
473             "package test;\n"+
474             "/** @ojb.class\n" +
475             " * @ojb.modify-inherited name=\"aid\"\n"+
476             " * ignore=\"true\"\n"+
477             " */\n"+
478             "public class C extends B {}\n");
479
480         assertNull(runOjbXDoclet(OJB_DEST_FILE));
481         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
482     }
483
484     // Test: ignoring a base class anonymous field
485
public void testIgnore8()
486     {
487         addClass(
488             "test.A",
489             "package test;\n"+
490             "/** @ojb.class\n"+
491             " * @ojb.field name=\"attr\"\n"+
492             " * jdbc-type=\"INTEGER\"\n"+
493             " */\n" +
494             "public class A {}");
495         addClass(
496             "test.B",
497             "package test;\n"+
498             "/** @ojb.class\n" +
499             " * @ojb.modify-inherited name=\"attr\"\n"+
500             " * ignore=\"true\"\n"+
501             " */\n"+
502             "public class B extends A {}\n");
503
504         assertEqualsOjbDescriptorFile(
505             "<class-descriptor\n"+
506             " class=\"test.A\"\n"+
507             " table=\"A\"\n"+
508             ">\n"+
509             " <extent-class class-ref=\"test.B\"/>\n"+
510             " <field-descriptor\n"+
511             " name=\"attr\"\n"+
512             " column=\"attr\"\n"+
513             " jdbc-type=\"INTEGER\"\n"+
514             " access=\"anonymous\"\n"+
515             " >\n"+
516             " </field-descriptor>\n"+
517             "</class-descriptor>\n"+
518             "<class-descriptor\n"+
519             " class=\"test.B\"\n"+
520             " table=\"B\"\n"+
521             ">\n"+
522             "</class-descriptor>",
523             runOjbXDoclet(OJB_DEST_FILE));
524         assertEqualsTorqueSchemaFile(
525             "<database name=\"ojbtest\">\n"+
526             " <table name=\"A\">\n"+
527             " <column name=\"attr\"\n"+
528             " javaName=\"attr\"\n"+
529             " type=\"INTEGER\"\n"+
530             " />\n"+
531             " </table>\n"+
532             " <table name=\"B\">\n"+
533             " </table>\n"+
534             "</database>",
535             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
536     }
537
538     // Test: ignoring a reference and its foreignkey field from a direct base class
539
public void testIgnore9()
540     {
541         addClass(
542             "test.A",
543             "package test;\n"+
544             "/** @ojb.class */\n" +
545             "public class A {\n"+
546             " /** @ojb.field */\n"+
547             " private int cid;\n"+
548             " /** @ojb.reference foreignkey=\"cid\" */\n"+
549             " private C c;\n"+
550             "}");
551         addClass(
552             "test.B",
553             "package test;\n"+
554             "/** @ojb.class\n" +
555             " * @ojb.modify-inherited name=\"c\"\n"+
556             " * ignore=\"true\"\n"+
557             " * @ojb.modify-inherited name=\"cid\"\n"+
558             " * ignore=\"true\"\n"+
559             " */\n"+
560             "public class B extends A {}\n");
561         addClass(
562             "test.C",
563             "package test;\n"+
564             "/** @ojb.class */\n" +
565             "public class C {\n"+
566             " /** @ojb.field primarykey=\"true\" */\n"+
567             " private int id;\n"+
568             "}");
569
570         assertEqualsOjbDescriptorFile(
571             "<class-descriptor\n"+
572             " class=\"test.A\"\n"+
573             " table=\"A\"\n"+
574             ">\n"+
575             " <extent-class class-ref=\"test.B\"/>\n"+
576             " <field-descriptor\n"+
577             " name=\"cid\"\n"+
578             " column=\"cid\"\n"+
579             " jdbc-type=\"INTEGER\"\n"+
580             " >\n"+
581             " </field-descriptor>\n"+
582             " <reference-descriptor\n"+
583             " name=\"c\"\n"+
584             " class-ref=\"test.C\"\n"+
585             " >\n"+
586             " <foreignkey field-ref=\"cid\"/>\n"+
587             " </reference-descriptor>\n"+
588             "</class-descriptor>\n"+
589             "<class-descriptor\n"+
590             " class=\"test.B\"\n"+
591             " table=\"B\"\n"+
592             ">\n"+
593             "</class-descriptor>\n"+
594             "<class-descriptor\n"+
595             " class=\"test.C\"\n"+
596             " table=\"C\"\n"+
597             ">\n"+
598             " <field-descriptor\n"+
599             " name=\"id\"\n"+
600             " column=\"id\"\n"+
601             " jdbc-type=\"INTEGER\"\n"+
602             " primarykey=\"true\"\n"+
603             " >\n"+
604             " </field-descriptor>\n"+
605             "</class-descriptor>",
606             runOjbXDoclet(OJB_DEST_FILE));
607         assertEqualsTorqueSchemaFile(
608             "<database name=\"ojbtest\">\n"+
609             " <table name=\"A\">\n"+
610             " <column name=\"cid\"\n"+
611             " javaName=\"cid\"\n"+
612             " type=\"INTEGER\"\n"+
613             " />\n"+
614             " <foreign-key foreignTable=\"C\">\n"+
615             " <reference local=\"cid\" foreign=\"id\"/>\n"+
616             " </foreign-key>\n"+
617             " </table>\n"+
618             " <table name=\"B\">\n"+
619             " </table>\n"+
620             " <table name=\"C\">\n"+
621             " <column name=\"id\"\n"+
622             " javaName=\"id\"\n"+
623             " type=\"INTEGER\"\n"+
624             " primaryKey=\"true\"\n"+
625             " required=\"true\"\n"+
626             " />\n"+
627             " </table>\n"+
628             "</database>",
629             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
630     }
631
632     // Test for OJB-53
633
public void testIgnore10()
634     {
635         addClass(
636             "test.A",
637             "package test;\n"+
638             "/** @ojb.class */\n" +
639             "public class A {\n"+
640             " /** @ojb.field primarykey=\"true\" */\n"+
641             " private int id;\n"+
642             " /** @ojb.field */\n"+
643             " private int bid;\n"+
644             " /** @ojb.reference foreignkey=\"bid\" */\n"+
645             " private B b;\n"+
646             "}");
647         addClass(
648             "test.B",
649             "package test;\n"+
650             "/** @ojb.class */\n"+
651             "public class B {\n"+
652             " /** @ojb.field primarykey=\"true\" */\n"+
653             " private int id;\n"+
654             " /** @ojb.collection element-class-ref=\"test.A\"\n"+
655             " * foreignkey=\"bid\"\n"+
656             " */\n"+
657             " private java.util.List as;\n"+
658             "}");
659         addClass(
660             "test.C",
661             "package test;\n"+
662             "/** @ojb.class\n" +
663             " * @ojb.modify-inherited name=\"bid\"\n"+
664             " * ignore=\"true\"\n"+
665             " * @ojb.modify-inherited name=\"b\"\n"+
666             " * ignore=\"true\"\n"+
667             " */\n"+
668             "public class C extends A {}\n");
669         addClass(
670             "test.D",
671             "package test;\n"+
672             "/** @ojb.class\n" +
673             " * @ojb.modify-inherited name=\"as\"\n"+
674             " * ignore=\"true\"\n"+
675             " */\n"+
676             "public class D extends B {}\n");
677
678         // This is supposed to fail because the as collection in B may contain a C instance,
679
// but they cannot be correctly handled by OJB because the field establishing the
680
// collection (bid in A) is no longer mapped in C
681
assertNull(runOjbXDoclet(OJB_DEST_FILE));
682         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
683     }
684 }
685
Popular Tags