KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.HashMap JavaDoc;
19
20 /**
21  * Tests for the ojb.collection tag with the element-class-ref attribute.
22  *
23  * @author <a HREF="mailto:tomdz@users.sourceforge.net">Thomas Dudziak (tomdz@users.sourceforge.net)</a>
24  */

25 public class ModifyInheritedTagElementClassRefAttributeTests extends OjbTestBase
26 {
27     public ModifyInheritedTagElementClassRefAttributeTests(String JavaDoc name)
28     {
29         super(name);
30     }
31
32     // Test: removing element-class-ref attribute of inherited array
33
public void testElementClassRef1()
34     {
35         addClass(
36             "test.A",
37             "package test;\n"+
38             "/** @ojb.class */\n" +
39             "public class A {\n"+
40             " /** @ojb.field primarykey=\"true\" */\n"+
41             " private int id;\n"+
42             " /** @ojb.collection element-class-ref=\"test.D\"\n"+
43             " * foreignkey=\"aid\"\n"+
44             " * database-foreignkey=\"false\"\n"+
45             " */\n"+
46             " private C[] attr;\n"+
47             "}");
48         addClass(
49             "test.B",
50             "package test;\n"+
51             "/** @ojb.class\n"+
52             " * @ojb.modify-inherited name=\"attr\"\n"+
53             " * element-class-ref=\"\"\n"+
54             " */\n"+
55             "public class B extends A {}\n");
56         addClass(
57             "test.C",
58             "package test;\n"+
59             "/** @ojb.class */\n"+
60             "public class C {\n"+
61             " /** @ojb.field */\n"+
62             " private int aid;\n"+
63             "}\n");
64         addClass(
65             "test.D",
66             "package test;\n"+
67             "/** @ojb.class */\n"+
68             "public class D extends C {}\n");
69
70         assertEqualsOjbDescriptorFile(
71             "<class-descriptor\n"+
72             " class=\"test.A\"\n"+
73             " table=\"A\"\n"+
74             ">\n"+
75             " <extent-class class-ref=\"test.B\"/>\n"+
76             " <field-descriptor\n"+
77             " name=\"id\"\n"+
78             " column=\"id\"\n"+
79             " jdbc-type=\"INTEGER\"\n"+
80             " primarykey=\"true\"\n"+
81             " >\n"+
82             " </field-descriptor>\n"+
83             " <collection-descriptor\n"+
84             " name=\"attr\"\n"+
85             " element-class-ref=\"test.D\"\n"+
86             " >\n"+
87             " <inverse-foreignkey field-ref=\"aid\"/>\n"+
88             " </collection-descriptor>\n"+
89             "</class-descriptor>\n"+
90             "<class-descriptor\n"+
91             " class=\"test.B\"\n"+
92             " table=\"B\"\n"+
93             ">\n"+
94             " <field-descriptor\n"+
95             " name=\"id\"\n"+
96             " column=\"id\"\n"+
97             " jdbc-type=\"INTEGER\"\n"+
98             " primarykey=\"true\"\n"+
99             " >\n"+
100             " </field-descriptor>\n"+
101             " <collection-descriptor\n"+
102             " name=\"attr\"\n"+
103             " element-class-ref=\"test.C\"\n"+
104             " >\n"+
105             " <inverse-foreignkey field-ref=\"aid\"/>\n"+
106             " </collection-descriptor>\n"+
107             "</class-descriptor>\n"+
108             "<class-descriptor\n"+
109             " class=\"test.C\"\n"+
110             " table=\"C\"\n"+
111             ">\n"+
112             " <extent-class class-ref=\"test.D\"/>\n"+
113             " <field-descriptor\n"+
114             " name=\"aid\"\n"+
115             " column=\"aid\"\n"+
116             " jdbc-type=\"INTEGER\"\n"+
117             " >\n"+
118             " </field-descriptor>\n"+
119             "</class-descriptor>\n"+
120             "<class-descriptor\n"+
121             " class=\"test.D\"\n"+
122             " table=\"D\"\n"+
123             ">\n"+
124             " <field-descriptor\n"+
125             " name=\"aid\"\n"+
126             " column=\"aid\"\n"+
127             " jdbc-type=\"INTEGER\"\n"+
128             " >\n"+
129             " </field-descriptor>\n"+
130             "</class-descriptor>",
131             runOjbXDoclet(OJB_DEST_FILE));
132         assertEqualsTorqueSchemaFile(
133             "<database name=\"ojbtest\">\n"+
134             " <table name=\"A\">\n"+
135             " <column name=\"id\"\n"+
136             " javaName=\"id\"\n"+
137             " type=\"INTEGER\"\n"+
138             " primaryKey=\"true\"\n"+
139             " required=\"true\"\n"+
140             " />\n"+
141             " </table>\n"+
142             " <table name=\"B\">\n"+
143             " <column name=\"id\"\n"+
144             " javaName=\"id\"\n"+
145             " type=\"INTEGER\"\n"+
146             " primaryKey=\"true\"\n"+
147             " required=\"true\"\n"+
148             " />\n"+
149             " </table>\n"+
150             " <table name=\"C\">\n"+
151             " <column name=\"aid\"\n"+
152             " javaName=\"aid\"\n"+
153             " type=\"INTEGER\"\n"+
154             " />\n"+
155             " </table>\n"+
156             " <table name=\"D\">\n"+
157             " <column name=\"aid\"\n"+
158             " javaName=\"aid\"\n"+
159             " type=\"INTEGER\"\n"+
160             " />\n"+
161             " </table>\n"+
162             "</database>",
163             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
164     }
165
166     // Test: removing element-class-ref attribute of inherited collection
167
public void testElementClassRef2()
168     {
169         addClass(
170             "test.A",
171             "package test;\n"+
172             "/** @ojb.class */\n" +
173             "public class A {\n"+
174             " /** @ojb.field primarykey=\"true\" */\n"+
175             " private int id;\n"+
176             " /** @ojb.collection element-class-ref=\"test.C\"\n"+
177             " * foreignkey=\"aid\"\n"+
178             " */\n"+
179             " private java.util.List attr;\n"+
180             "}");
181         addClass(
182             "test.B",
183             "package test;\n"+
184             "/** @ojb.class\n"+
185             " * @ojb.modify-inherited name=\"attr\"\n"+
186             " * element-class-ref=\"\"\n"+
187             " */\n"+
188             "public class B extends A {}\n");
189         addClass(
190             "test.C",
191             "package test;\n"+
192             "/** @ojb.class */\n"+
193             "public class C {\n"+
194             " /** @ojb.field */\n"+
195             " private int aid;\n"+
196             "}\n");
197
198         assertNull(runOjbXDoclet(OJB_DEST_FILE));
199         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
200     }
201
202     // Test: setting element-class-ref attribute of inherited array to array element type
203
public void testElementClassRef3()
204     {
205         addClass(
206             "test.A",
207             "package test;\n"+
208             "/** @ojb.class */\n" +
209             "public class A {\n"+
210             " /** @ojb.field primarykey=\"true\" */\n"+
211             " private int id;\n"+
212             " /** @ojb.collection foreignkey=\"aid\"\n"+
213             " * database-foreignkey=\"false\"\n"+
214             " */\n"+
215             " private C[] attr;\n"+
216             "}");
217         addClass(
218             "test.B",
219             "package test;\n"+
220             "/** @ojb.class\n"+
221             " * @ojb.modify-inherited name=\"attr\"\n"+
222             " * element-class-ref=\"test.C\"\n"+
223             " */\n"+
224             "public class B extends A {}\n");
225         addClass(
226             "test.C",
227             "package test;\n"+
228             "/** @ojb.class */\n"+
229             "public class C {\n"+
230             " /** @ojb.field */\n"+
231             " private int aid;\n"+
232             "}\n");
233         addClass(
234             "test.D",
235             "package test;\n"+
236             "/** @ojb.class */\n"+
237             "public class D extends C {}\n");
238
239         assertEqualsOjbDescriptorFile(
240             "<class-descriptor\n"+
241             " class=\"test.A\"\n"+
242             " table=\"A\"\n"+
243             ">\n"+
244             " <extent-class class-ref=\"test.B\"/>\n"+
245             " <field-descriptor\n"+
246             " name=\"id\"\n"+
247             " column=\"id\"\n"+
248             " jdbc-type=\"INTEGER\"\n"+
249             " primarykey=\"true\"\n"+
250             " >\n"+
251             " </field-descriptor>\n"+
252             " <collection-descriptor\n"+
253             " name=\"attr\"\n"+
254             " element-class-ref=\"test.C\"\n"+
255             " >\n"+
256             " <inverse-foreignkey field-ref=\"aid\"/>\n"+
257             " </collection-descriptor>\n"+
258             "</class-descriptor>\n"+
259             "<class-descriptor\n"+
260             " class=\"test.B\"\n"+
261             " table=\"B\"\n"+
262             ">\n"+
263             " <field-descriptor\n"+
264             " name=\"id\"\n"+
265             " column=\"id\"\n"+
266             " jdbc-type=\"INTEGER\"\n"+
267             " primarykey=\"true\"\n"+
268             " >\n"+
269             " </field-descriptor>\n"+
270             " <collection-descriptor\n"+
271             " name=\"attr\"\n"+
272             " element-class-ref=\"test.C\"\n"+
273             " >\n"+
274             " <inverse-foreignkey field-ref=\"aid\"/>\n"+
275             " </collection-descriptor>\n"+
276             "</class-descriptor>\n"+
277             "<class-descriptor\n"+
278             " class=\"test.C\"\n"+
279             " table=\"C\"\n"+
280             ">\n"+
281             " <extent-class class-ref=\"test.D\"/>\n"+
282             " <field-descriptor\n"+
283             " name=\"aid\"\n"+
284             " column=\"aid\"\n"+
285             " jdbc-type=\"INTEGER\"\n"+
286             " >\n"+
287             " </field-descriptor>\n"+
288             "</class-descriptor>\n"+
289             "<class-descriptor\n"+
290             " class=\"test.D\"\n"+
291             " table=\"D\"\n"+
292             ">\n"+
293             " <field-descriptor\n"+
294             " name=\"aid\"\n"+
295             " column=\"aid\"\n"+
296             " jdbc-type=\"INTEGER\"\n"+
297             " >\n"+
298             " </field-descriptor>\n"+
299             "</class-descriptor>",
300             runOjbXDoclet(OJB_DEST_FILE));
301         assertEqualsTorqueSchemaFile(
302             "<database name=\"ojbtest\">\n"+
303             " <table name=\"A\">\n"+
304             " <column name=\"id\"\n"+
305             " javaName=\"id\"\n"+
306             " type=\"INTEGER\"\n"+
307             " primaryKey=\"true\"\n"+
308             " required=\"true\"\n"+
309             " />\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             " <table name=\"C\">\n"+
320             " <column name=\"aid\"\n"+
321             " javaName=\"aid\"\n"+
322             " type=\"INTEGER\"\n"+
323             " />\n"+
324             " </table>\n"+
325             " <table name=\"D\">\n"+
326             " <column name=\"aid\"\n"+
327             " javaName=\"aid\"\n"+
328             " type=\"INTEGER\"\n"+
329             " />\n"+
330             " </table>\n"+
331             "</database>",
332             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
333     }
334
335     // Test: setting element-class-ref attribute of inherited array to sub-type of array element type
336
public void testElementClassRef4()
337     {
338         addClass(
339             "test.A",
340             "package test;\n"+
341             "/** @ojb.class */\n" +
342             "public class A {\n"+
343             " /** @ojb.field primarykey=\"true\" */\n"+
344             " private int id;\n"+
345             " /** @ojb.collection foreignkey=\"aid\"\n"+
346             " * database-foreignkey=\"false\"\n"+
347             " */\n"+
348             " private C[] attr;\n"+
349             "}");
350         addClass(
351             "test.B",
352             "package test;\n"+
353             "/** @ojb.class\n"+
354             " * @ojb.modify-inherited name=\"attr\"\n"+
355             " * element-class-ref=\"test.D\"\n"+
356             " */\n"+
357             "public class B extends A {}\n");
358         addClass(
359             "test.C",
360             "package test;\n"+
361             "/** @ojb.class */\n"+
362             "public class C {\n"+
363             " /** @ojb.field */\n"+
364             " private int aid;\n"+
365             "}\n");
366         addClass(
367             "test.D",
368             "package test;\n"+
369             "/** @ojb.class */\n"+
370             "public class D extends C {}\n");
371
372         assertEqualsOjbDescriptorFile(
373             "<class-descriptor\n"+
374             " class=\"test.A\"\n"+
375             " table=\"A\"\n"+
376             ">\n"+
377             " <extent-class class-ref=\"test.B\"/>\n"+
378             " <field-descriptor\n"+
379             " name=\"id\"\n"+
380             " column=\"id\"\n"+
381             " jdbc-type=\"INTEGER\"\n"+
382             " primarykey=\"true\"\n"+
383             " >\n"+
384             " </field-descriptor>\n"+
385             " <collection-descriptor\n"+
386             " name=\"attr\"\n"+
387             " element-class-ref=\"test.C\"\n"+
388             " >\n"+
389             " <inverse-foreignkey field-ref=\"aid\"/>\n"+
390             " </collection-descriptor>\n"+
391             "</class-descriptor>\n"+
392             "<class-descriptor\n"+
393             " class=\"test.B\"\n"+
394             " table=\"B\"\n"+
395             ">\n"+
396             " <field-descriptor\n"+
397             " name=\"id\"\n"+
398             " column=\"id\"\n"+
399             " jdbc-type=\"INTEGER\"\n"+
400             " primarykey=\"true\"\n"+
401             " >\n"+
402             " </field-descriptor>\n"+
403             " <collection-descriptor\n"+
404             " name=\"attr\"\n"+
405             " element-class-ref=\"test.D\"\n"+
406             " >\n"+
407             " <inverse-foreignkey field-ref=\"aid\"/>\n"+
408             " </collection-descriptor>\n"+
409             "</class-descriptor>\n"+
410             "<class-descriptor\n"+
411             " class=\"test.C\"\n"+
412             " table=\"C\"\n"+
413             ">\n"+
414             " <extent-class class-ref=\"test.D\"/>\n"+
415             " <field-descriptor\n"+
416             " name=\"aid\"\n"+
417             " column=\"aid\"\n"+
418             " jdbc-type=\"INTEGER\"\n"+
419             " >\n"+
420             " </field-descriptor>\n"+
421             "</class-descriptor>\n"+
422             "<class-descriptor\n"+
423             " class=\"test.D\"\n"+
424             " table=\"D\"\n"+
425             ">\n"+
426             " <field-descriptor\n"+
427             " name=\"aid\"\n"+
428             " column=\"aid\"\n"+
429             " jdbc-type=\"INTEGER\"\n"+
430             " >\n"+
431             " </field-descriptor>\n"+
432             "</class-descriptor>",
433             runOjbXDoclet(OJB_DEST_FILE));
434         assertEqualsTorqueSchemaFile(
435             "<database name=\"ojbtest\">\n"+
436             " <table name=\"A\">\n"+
437             " <column name=\"id\"\n"+
438             " javaName=\"id\"\n"+
439             " type=\"INTEGER\"\n"+
440             " primaryKey=\"true\"\n"+
441             " required=\"true\"\n"+
442             " />\n"+
443             " </table>\n"+
444             " <table name=\"B\">\n"+
445             " <column name=\"id\"\n"+
446             " javaName=\"id\"\n"+
447             " type=\"INTEGER\"\n"+
448             " primaryKey=\"true\"\n"+
449             " required=\"true\"\n"+
450             " />\n"+
451             " </table>\n"+
452             " <table name=\"C\">\n"+
453             " <column name=\"aid\"\n"+
454             " javaName=\"aid\"\n"+
455             " type=\"INTEGER\"\n"+
456             " />\n"+
457             " </table>\n"+
458             " <table name=\"D\">\n"+
459             " <column name=\"aid\"\n"+
460             " javaName=\"aid\"\n"+
461             " type=\"INTEGER\"\n"+
462             " />\n"+
463             " </table>\n"+
464             "</database>",
465             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
466     }
467
468     // Test: setting element-class-ref attribute of inherited array to type unrelated to array element type
469
public void testElementClassRef5()
470     {
471         addClass(
472             "test.A",
473             "package test;\n"+
474             "/** @ojb.class */\n" +
475             "public class A {\n"+
476             " /** @ojb.field primarykey=\"true\" */\n"+
477             " private int id;\n"+
478             " /** @ojb.collection foreignkey=\"aid\" */\n"+
479             " private C[] attr;\n"+
480             "}");
481         addClass(
482             "test.B",
483             "package test;\n"+
484             "/** @ojb.class\n"+
485             " * @ojb.modify-inherited name=\"attr\"\n"+
486             " * element-class-ref=\"test.D\"\n"+
487             " */\n"+
488             "public class B extends A {}\n");
489         addClass(
490             "test.C",
491             "package test;\n"+
492             "/** @ojb.class */\n"+
493             "public class C {\n"+
494             " /** @ojb.field */\n"+
495             " private int aid;\n"+
496             "}\n");
497         addClass(
498             "test.D",
499             "package test;\n"+
500             "/** @ojb.class */\n"+
501             "public class D {\n"+
502             " /** @ojb.field */\n"+
503             " private int aid;\n"+
504             "}\n");
505
506         assertNull(runOjbXDoclet(OJB_DEST_FILE));
507         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
508     }
509
510     // Test: changing element-class-ref attribute of inherited array to sub-type of array element type
511
public void testElementClassRef6()
512     {
513         addClass(
514             "test.A",
515             "package test;\n"+
516             "/** @ojb.class */\n" +
517             "public class A {\n"+
518             " /** @ojb.field primarykey=\"true\" */\n"+
519             " private int id;\n"+
520             " /** @ojb.collection element-class-ref=\"test.C\"\n"+
521             " * foreignkey=\"aid\"\n"+
522             " * database-foreignkey=\"false\"\n"+
523             " */\n"+
524             " private C[] attr;\n"+
525             "}");
526         addClass(
527             "test.B",
528             "package test;\n"+
529             "/** @ojb.class\n"+
530             " * @ojb.modify-inherited name=\"attr\"\n"+
531             " * element-class-ref=\"test.D\"\n"+
532             " */\n"+
533             "public class B extends A {}\n");
534         addClass(
535             "test.C",
536             "package test;\n"+
537             "/** @ojb.class */\n"+
538             "public class C {\n"+
539             " /** @ojb.field */\n"+
540             " private int aid;\n"+
541             "}\n");
542         addClass(
543             "test.D",
544             "package test;\n"+
545             "/** @ojb.class */\n"+
546             "public class D extends C {}\n");
547
548         assertEqualsOjbDescriptorFile(
549             "<class-descriptor\n"+
550             " class=\"test.A\"\n"+
551             " table=\"A\"\n"+
552             ">\n"+
553             " <extent-class class-ref=\"test.B\"/>\n"+
554             " <field-descriptor\n"+
555             " name=\"id\"\n"+
556             " column=\"id\"\n"+
557             " jdbc-type=\"INTEGER\"\n"+
558             " primarykey=\"true\"\n"+
559             " >\n"+
560             " </field-descriptor>\n"+
561             " <collection-descriptor\n"+
562             " name=\"attr\"\n"+
563             " element-class-ref=\"test.C\"\n"+
564             " >\n"+
565             " <inverse-foreignkey field-ref=\"aid\"/>\n"+
566             " </collection-descriptor>\n"+
567             "</class-descriptor>\n"+
568             "<class-descriptor\n"+
569             " class=\"test.B\"\n"+
570             " table=\"B\"\n"+
571             ">\n"+
572             " <field-descriptor\n"+
573             " name=\"id\"\n"+
574             " column=\"id\"\n"+
575             " jdbc-type=\"INTEGER\"\n"+
576             " primarykey=\"true\"\n"+
577             " >\n"+
578             " </field-descriptor>\n"+
579             " <collection-descriptor\n"+
580             " name=\"attr\"\n"+
581             " element-class-ref=\"test.D\"\n"+
582             " >\n"+
583             " <inverse-foreignkey field-ref=\"aid\"/>\n"+
584             " </collection-descriptor>\n"+
585             "</class-descriptor>\n"+
586             "<class-descriptor\n"+
587             " class=\"test.C\"\n"+
588             " table=\"C\"\n"+
589             ">\n"+
590             " <extent-class class-ref=\"test.D\"/>\n"+
591             " <field-descriptor\n"+
592             " name=\"aid\"\n"+
593             " column=\"aid\"\n"+
594             " jdbc-type=\"INTEGER\"\n"+
595             " >\n"+
596             " </field-descriptor>\n"+
597             "</class-descriptor>\n"+
598             "<class-descriptor\n"+
599             " class=\"test.D\"\n"+
600             " table=\"D\"\n"+
601             ">\n"+
602             " <field-descriptor\n"+
603             " name=\"aid\"\n"+
604             " column=\"aid\"\n"+
605             " jdbc-type=\"INTEGER\"\n"+
606             " >\n"+
607             " </field-descriptor>\n"+
608             "</class-descriptor>",
609             runOjbXDoclet(OJB_DEST_FILE));
610         assertEqualsTorqueSchemaFile(
611             "<database name=\"ojbtest\">\n"+
612             " <table name=\"A\">\n"+
613             " <column name=\"id\"\n"+
614             " javaName=\"id\"\n"+
615             " type=\"INTEGER\"\n"+
616             " primaryKey=\"true\"\n"+
617             " required=\"true\"\n"+
618             " />\n"+
619             " </table>\n"+
620             " <table name=\"B\">\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             " <table name=\"C\">\n"+
629             " <column name=\"aid\"\n"+
630             " javaName=\"aid\"\n"+
631             " type=\"INTEGER\"\n"+
632             " />\n"+
633             " </table>\n"+
634             " <table name=\"D\">\n"+
635             " <column name=\"aid\"\n"+
636             " javaName=\"aid\"\n"+
637             " type=\"INTEGER\"\n"+
638             " />\n"+
639             " </table>\n"+
640             "</database>",
641             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
642     }
643
644     // Test: changing element-class-ref attribute of inherited array to unrelated type
645
public void testElementClassRef7()
646     {
647         addClass(
648             "test.A",
649             "package test;\n"+
650             "/** @ojb.class */\n" +
651             "public class A {\n"+
652             " /** @ojb.field primarykey=\"true\" */\n"+
653             " private int id;\n"+
654             " /** @ojb.collection element-class-ref=\"test.C\"\n"+
655             " * foreignkey=\"aid\"\n"+
656             " */\n"+
657             " private C[] attr;\n"+
658             "}");
659         addClass(
660             "test.B",
661             "package test;\n"+
662             "/** @ojb.class\n"+
663             " * @ojb.modify-inherited name=\"attr\"\n"+
664             " * element-class-ref=\"test.D\"\n"+
665             " */\n"+
666             "public class B extends A {}\n");
667         addClass(
668             "test.C",
669             "package test;\n"+
670             "/** @ojb.class */\n"+
671             "public class C {\n"+
672             " /** @ojb.field */\n"+
673             " private int aid;\n"+
674             "}\n");
675         addClass(
676             "test.D",
677             "package test;\n"+
678             "/** @ojb.class */\n"+
679             "public class D {\n"+
680             " /** @ojb.field */\n"+
681             " private int aid;\n"+
682             "}\n");
683
684         assertNull(runOjbXDoclet(OJB_DEST_FILE));
685         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
686     }
687
688     // Test: changing element-class-ref attribute of remotely inherited collection to sub-type of original element type with new foreignkey
689
public void testElementClassRef8()
690     {
691         addClass(
692             "test.A",
693             "package test;\n"+
694             "/** @ojb.class */\n" +
695             "public class A {\n"+
696             " /** @ojb.field primarykey=\"true\" */\n"+
697             " private int id;\n"+
698             " /** @ojb.collection element-class-ref=\"test.D\"\n"+
699             " * foreignkey=\"aid\"\n"+
700             " * database-foreignkey=\"false\"\n"+
701             " */\n"+
702             " private java.util.List attr;\n"+
703             "}");
704         addClass(
705             "test.B",
706             "package test;\n"+
707             "public class B extends A {}\n");
708         addClass(
709             "test.C",
710             "package test;\n"+
711             "/** @ojb.class\n"+
712             " * @ojb.modify-inherited name=\"attr\"\n"+
713             " * element-class-ref=\"test.E\"\n"+
714             " * foreignkey=\"aid2\"\n"+
715             " */\n"+
716             "public class C extends B {}\n");
717         addClass(
718             "test.D",
719             "package test;\n"+
720             "/** @ojb.class */\n"+
721             "public class D {\n"+
722             " /** @ojb.field */\n"+
723             " private int aid;\n"+
724             "}\n");
725         addClass(
726             "test.E",
727             "package test;\n"+
728             "/** @ojb.class */\n"+
729             "public class E extends D {\n"+
730             " /** @ojb.field */\n"+
731             " private int aid2;\n"+
732             "}\n");
733
734         assertEqualsOjbDescriptorFile(
735             "<class-descriptor\n"+
736             " class=\"test.A\"\n"+
737             " table=\"A\"\n"+
738             ">\n"+
739             " <extent-class class-ref=\"test.C\"/>\n"+
740             " <field-descriptor\n"+
741             " name=\"id\"\n"+
742             " column=\"id\"\n"+
743             " jdbc-type=\"INTEGER\"\n"+
744             " primarykey=\"true\"\n"+
745             " >\n"+
746             " </field-descriptor>\n"+
747             " <collection-descriptor\n"+
748             " name=\"attr\"\n"+
749             " element-class-ref=\"test.D\"\n"+
750             " >\n"+
751             " <inverse-foreignkey field-ref=\"aid\"/>\n"+
752             " </collection-descriptor>\n"+
753             "</class-descriptor>\n"+
754             "<class-descriptor\n"+
755             " class=\"test.C\"\n"+
756             " table=\"C\"\n"+
757             ">\n"+
758             " <field-descriptor\n"+
759             " name=\"id\"\n"+
760             " column=\"id\"\n"+
761             " jdbc-type=\"INTEGER\"\n"+
762             " primarykey=\"true\"\n"+
763             " >\n"+
764             " </field-descriptor>\n"+
765             " <collection-descriptor\n"+
766             " name=\"attr\"\n"+
767             " element-class-ref=\"test.E\"\n"+
768             " >\n"+
769             " <inverse-foreignkey field-ref=\"aid2\"/>\n"+
770             " </collection-descriptor>\n"+
771             "</class-descriptor>\n"+
772             "<class-descriptor\n"+
773             " class=\"test.D\"\n"+
774             " table=\"D\"\n"+
775             ">\n"+
776             " <extent-class class-ref=\"test.E\"/>\n"+
777             " <field-descriptor\n"+
778             " name=\"aid\"\n"+
779             " column=\"aid\"\n"+
780             " jdbc-type=\"INTEGER\"\n"+
781             " >\n"+
782             " </field-descriptor>\n"+
783             "</class-descriptor>\n"+
784             "<class-descriptor\n"+
785             " class=\"test.E\"\n"+
786             " table=\"E\"\n"+
787             ">\n"+
788             " <field-descriptor\n"+
789             " name=\"aid\"\n"+
790             " column=\"aid\"\n"+
791             " jdbc-type=\"INTEGER\"\n"+
792             " >\n"+
793             " </field-descriptor>\n"+
794             " <field-descriptor\n"+
795             " name=\"aid2\"\n"+
796             " column=\"aid2\"\n"+
797             " jdbc-type=\"INTEGER\"\n"+
798             " >\n"+
799             " </field-descriptor>\n"+
800             "</class-descriptor>",
801             runOjbXDoclet(OJB_DEST_FILE));
802         assertEqualsTorqueSchemaFile(
803             "<database name=\"ojbtest\">\n"+
804             " <table name=\"A\">\n"+
805             " <column name=\"id\"\n"+
806             " javaName=\"id\"\n"+
807             " type=\"INTEGER\"\n"+
808             " primaryKey=\"true\"\n"+
809             " required=\"true\"\n"+
810             " />\n"+
811             " </table>\n"+
812             " <table name=\"C\">\n"+
813             " <column name=\"id\"\n"+
814             " javaName=\"id\"\n"+
815             " type=\"INTEGER\"\n"+
816             " primaryKey=\"true\"\n"+
817             " required=\"true\"\n"+
818             " />\n"+
819             " </table>\n"+
820             " <table name=\"D\">\n"+
821             " <column name=\"aid\"\n"+
822             " javaName=\"aid\"\n"+
823             " type=\"INTEGER\"\n"+
824             " />\n"+
825             " </table>\n"+
826             " <table name=\"E\">\n"+
827             " <column name=\"aid\"\n"+
828             " javaName=\"aid\"\n"+
829             " type=\"INTEGER\"\n"+
830             " />\n"+
831             " <column name=\"aid2\"\n"+
832             " javaName=\"aid2\"\n"+
833             " type=\"INTEGER\"\n"+
834             " />\n"+
835             " </table>\n"+
836             "</database>",
837             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
838     }
839
840     // Test: changing element-class-ref attribute of inherited collection to non-persistent sub-type of original element type
841
public void testElementClassRef9()
842     {
843         addClass(
844             "test.A",
845             "package test;\n"+
846             "/** @ojb.class */\n" +
847             "public class A {\n"+
848             " /** @ojb.field primarykey=\"true\" */\n"+
849             " private int id;\n"+
850             " /** @ojb.collection element-class-ref=\"test.C\"\n"+
851             " * foreignkey=\"aid\"\n"+
852             " */\n"+
853             " private java.util.List attr;\n"+
854             "}");
855         addClass(
856             "test.B",
857             "package test;\n"+
858             "/** @ojb.class\n"+
859             " * @ojb.modify-inherited name=\"attr\"\n"+
860             " * element-class-ref=\"test.D\"\n"+
861             " */\n"+
862             "public class B extends A {}\n");
863         addClass(
864             "test.C",
865             "package test;\n"+
866             "/** @ojb.class */\n"+
867             "public class C {\n"+
868             " /** @ojb.field */\n"+
869             " private int aid;\n"+
870             "}\n");
871         addClass(
872             "test.D",
873             "package test;\n"+
874             "public class D extends C {}\n");
875
876         assertNull(runOjbXDoclet(OJB_DEST_FILE));
877         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
878     }
879
880     // Test: changing element-class-ref attribute of inherited collection to type unrelated to the original element type
881
// Note that both element classes have a field 'aid'
882
public void testElementClassRef10()
883     {
884         addClass(
885             "test.A",
886             "package test;\n"+
887             "/** @ojb.class */\n" +
888             "public class A {\n"+
889             " /** @ojb.field primarykey=\"true\" */\n"+
890             " private int id;\n"+
891             " /** @ojb.collection element-class-ref=\"test.C\"\n"+
892             " * foreignkey=\"aid\"\n"+
893             " * database-foreignkey=\"false\"\n"+
894             " */\n"+
895             " private java.util.List attr;\n"+
896             "}");
897         addClass(
898             "test.B",
899             "package test;\n"+
900             "/** @ojb.class\n"+
901             " * @ojb.modify-inherited name=\"attr\"\n"+
902             " * element-class-ref=\"test.D\"\n"+
903             " */\n"+
904             "public class B extends A {}\n");
905         addClass(
906             "test.C",
907             "package test;\n"+
908             "/** @ojb.class */\n"+
909             "public class C {\n"+
910             " /** @ojb.field */\n"+
911             " private int aid;\n"+
912             "}\n");
913         addClass(
914             "test.D",
915             "package test;\n"+
916             "/** @ojb.class */\n"+
917             "public class D {\n"+
918             " /** @ojb.field */\n"+
919             " private int aid;\n"+
920             "}\n");
921
922         assertEqualsOjbDescriptorFile(
923             "<class-descriptor\n"+
924             " class=\"test.A\"\n"+
925             " table=\"A\"\n"+
926             ">\n"+
927             " <extent-class class-ref=\"test.B\"/>\n"+
928             " <field-descriptor\n"+
929             " name=\"id\"\n"+
930             " column=\"id\"\n"+
931             " jdbc-type=\"INTEGER\"\n"+
932             " primarykey=\"true\"\n"+
933             " >\n"+
934             " </field-descriptor>\n"+
935             " <collection-descriptor\n"+
936             " name=\"attr\"\n"+
937             " element-class-ref=\"test.C\"\n"+
938             " >\n"+
939             " <inverse-foreignkey field-ref=\"aid\"/>\n"+
940             " </collection-descriptor>\n"+
941             "</class-descriptor>\n"+
942             "<class-descriptor\n"+
943             " class=\"test.B\"\n"+
944             " table=\"B\"\n"+
945             ">\n"+
946             " <field-descriptor\n"+
947             " name=\"id\"\n"+
948             " column=\"id\"\n"+
949             " jdbc-type=\"INTEGER\"\n"+
950             " primarykey=\"true\"\n"+
951             " >\n"+
952             " </field-descriptor>\n"+
953             " <collection-descriptor\n"+
954             " name=\"attr\"\n"+
955             " element-class-ref=\"test.D\"\n"+
956             " >\n"+
957             " <inverse-foreignkey field-ref=\"aid\"/>\n"+
958             " </collection-descriptor>\n"+
959             "</class-descriptor>\n"+
960             "<class-descriptor\n"+
961             " class=\"test.C\"\n"+
962             " table=\"C\"\n"+
963             ">\n"+
964             " <field-descriptor\n"+
965             " name=\"aid\"\n"+
966             " column=\"aid\"\n"+
967             " jdbc-type=\"INTEGER\"\n"+
968             " >\n"+
969             " </field-descriptor>\n"+
970             "</class-descriptor>\n"+
971             "<class-descriptor\n"+
972             " class=\"test.D\"\n"+
973             " table=\"D\"\n"+
974             ">\n"+
975             " <field-descriptor\n"+
976             " name=\"aid\"\n"+
977             " column=\"aid\"\n"+
978             " jdbc-type=\"INTEGER\"\n"+
979             " >\n"+
980             " </field-descriptor>\n"+
981             "</class-descriptor>",
982             runOjbXDoclet(OJB_DEST_FILE));
983         assertEqualsTorqueSchemaFile(
984             "<database name=\"ojbtest\">\n"+
985             " <table name=\"A\">\n"+
986             " <column name=\"id\"\n"+
987             " javaName=\"id\"\n"+
988             " type=\"INTEGER\"\n"+
989             " primaryKey=\"true\"\n"+
990             " required=\"true\"\n"+
991             " />\n"+
992             " </table>\n"+
993             " <table name=\"B\">\n"+
994             " <column name=\"id\"\n"+
995             " javaName=\"id\"\n"+
996             " type=\"INTEGER\"\n"+
997             " primaryKey=\"true\"\n"+
998             " required=\"true\"\n"+
999             " />\n"+
1000            " </table>\n"+
1001            " <table name=\"C\">\n"+
1002            " <column name=\"aid\"\n"+
1003            " javaName=\"aid\"\n"+
1004            " type=\"INTEGER\"\n"+
1005            " />\n"+
1006            " </table>\n"+
1007            " <table name=\"D\">\n"+
1008            " <column name=\"aid\"\n"+
1009            " javaName=\"aid\"\n"+
1010            " type=\"INTEGER\"\n"+
1011            " />\n"+
1012            " </table>\n"+
1013            "</database>",
1014            runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
1015    }
1016
1017    // Test: changing element-class-ref attribute of inherited collection to invalid type
1018
public void testElementClassRef11()
1019    {
1020        addClass(
1021            "test.A",
1022            "package test;\n"+
1023            "/** @ojb.class */\n" +
1024            "public class A {\n"+
1025            " /** @ojb.field primarykey=\"true\" */\n"+
1026            " private int id;\n"+
1027            " /** @ojb.collection element-class-ref=\"test.C\"\n"+
1028            " * foreignkey=\"aid\"\n"+
1029            " */\n"+
1030            " private java.util.List attr;\n"+
1031            "}");
1032        addClass(
1033            "test.B",
1034            "package test;\n"+
1035            "/** @ojb.class\n"+
1036            " * @ojb.modify-inherited name=\"attr\"\n"+
1037            " * element-class-ref=\"SomeClass\"\n"+
1038            " */\n"+
1039            "public class B extends A {}\n");
1040        addClass(
1041            "test.C",
1042            "package test;\n"+
1043            "/** @ojb.class */\n"+
1044            "public class C {\n"+
1045            " /** @ojb.field */\n"+
1046            " private int aid;\n"+
1047            "}\n");
1048
1049        assertNull(runOjbXDoclet(OJB_DEST_FILE));
1050        assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
1051    }
1052
1053    // Test: changing element-class-ref attribute of inherited collection to primitive type
1054
public void testElementClassRef12()
1055    {
1056        addClass(
1057            "test.A",
1058            "package test;\n"+
1059            "/** @ojb.class */\n" +
1060            "public class A {\n"+
1061            " /** @ojb.field primarykey=\"true\" */\n"+
1062            " private int id;\n"+
1063            " /** @ojb.collection element-class-ref=\"test.C\"\n"+
1064            " * foreignkey=\"aid\"\n"+
1065            " */\n"+
1066            " private java.util.List attr;\n"+
1067            "}");
1068        addClass(
1069            "test.B",
1070            "package test;\n"+
1071            "/** @ojb.class\n"+
1072            " * @ojb.modify-inherited name=\"attr\"\n"+
1073            " * element-class-ref=\"float\"\n"+
1074            " */\n"+
1075            "public class B extends A {}\n");
1076        addClass(
1077            "test.C",
1078            "package test;\n"+
1079            "/** @ojb.class */\n"+
1080            "public class C {\n"+
1081            " /** @ojb.field */\n"+
1082            " private int aid;\n"+
1083            "}\n");
1084
1085        assertNull(runOjbXDoclet(OJB_DEST_FILE));
1086        assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
1087    }
1088
1089    // Test: changing element-class-ref attribute of inherited array to type that is unrelated to array element type
1090
// but strict is set to false
1091
public void testElementClassRef13()
1092    {
1093        addClass(
1094            "test.A",
1095            "package test;\n"+
1096            "/** @ojb.class */\n" +
1097            "public class A {\n"+
1098            " /** @ojb.field primarykey=\"true\" */\n"+
1099            " private int id;\n"+
1100            " /** @ojb.collection element-class-ref=\"test.C\"\n"+
1101            " * foreignkey=\"aid\"\n"+
1102            " * database-foreignkey=\"false\"\n"+
1103            " */\n"+
1104            " private C[] attr;\n"+
1105            "}");
1106        addClass(
1107            "test.B",
1108            "package test;\n"+
1109            "/** @ojb.class\n"+
1110            " * @ojb.modify-inherited name=\"attr\"\n"+
1111            " * element-class-ref=\"test.D\"\n"+
1112            " */\n"+
1113            "public class B extends A {}\n");
1114        addClass(
1115            "test.C",
1116            "package test;\n"+
1117            "/** @ojb.class */\n"+
1118            "public class C {\n"+
1119            " /** @ojb.field */\n"+
1120            " private int aid;\n"+
1121            "}\n");
1122        addClass(
1123            "test.D",
1124            "package test;\n"+
1125            "/** @ojb.class */\n"+
1126            "public class D {\n"+
1127            " /** @ojb.field */\n"+
1128            " private int aid;\n"+
1129            "}\n");
1130        
1131        HashMap JavaDoc taskProps = new HashMap JavaDoc();
1132        HashMap JavaDoc torqueSubTaskProps = new HashMap JavaDoc();
1133        
1134        taskProps.put(PROPERTY_CHECKS, "basic");
1135        torqueSubTaskProps.put(PROPERTY_DATABASENAME, "ojbtest");
1136
1137        assertEqualsOjbDescriptorFile(
1138            "<class-descriptor\n"+
1139            " class=\"test.A\"\n"+
1140            " table=\"A\"\n"+
1141            ">\n"+
1142            " <extent-class class-ref=\"test.B\"/>\n"+
1143            " <field-descriptor\n"+
1144            " name=\"id\"\n"+
1145            " column=\"id\"\n"+
1146            " jdbc-type=\"INTEGER\"\n"+
1147            " primarykey=\"true\"\n"+
1148            " >\n"+
1149            " </field-descriptor>\n"+
1150            " <collection-descriptor\n"+
1151            " name=\"attr\"\n"+
1152            " element-class-ref=\"test.C\"\n"+
1153            " >\n"+
1154            " <inverse-foreignkey field-ref=\"aid\"/>\n"+
1155            " </collection-descriptor>\n"+
1156            "</class-descriptor>\n"+
1157            "<class-descriptor\n"+
1158            " class=\"test.B\"\n"+
1159            " table=\"B\"\n"+
1160            ">\n"+
1161            " <field-descriptor\n"+
1162            " name=\"id\"\n"+
1163            " column=\"id\"\n"+
1164            " jdbc-type=\"INTEGER\"\n"+
1165            " primarykey=\"true\"\n"+
1166            " >\n"+
1167            " </field-descriptor>\n"+
1168            " <collection-descriptor\n"+
1169            " name=\"attr\"\n"+
1170            " element-class-ref=\"test.D\"\n"+
1171            " >\n"+
1172            " <inverse-foreignkey field-ref=\"aid\"/>\n"+
1173            " </collection-descriptor>\n"+
1174            "</class-descriptor>\n"+
1175            "<class-descriptor\n"+
1176            " class=\"test.C\"\n"+
1177            " table=\"C\"\n"+
1178            ">\n"+
1179            " <field-descriptor\n"+
1180            " name=\"aid\"\n"+
1181            " column=\"aid\"\n"+
1182            " jdbc-type=\"INTEGER\"\n"+
1183            " >\n"+
1184            " </field-descriptor>\n"+
1185            "</class-descriptor>\n"+
1186            "<class-descriptor\n"+
1187            " class=\"test.D\"\n"+
1188            " table=\"D\"\n"+
1189            ">\n"+
1190            " <field-descriptor\n"+
1191            " name=\"aid\"\n"+
1192            " column=\"aid\"\n"+
1193            " jdbc-type=\"INTEGER\"\n"+
1194            " >\n"+
1195            " </field-descriptor>\n"+
1196            "</class-descriptor>",
1197            runOjbXDoclet(OJB_DEST_FILE, taskProps, null));
1198        assertEqualsTorqueSchemaFile(
1199            "<database name=\"ojbtest\">\n"+
1200            " <table name=\"A\">\n"+
1201            " <column name=\"id\"\n"+
1202            " javaName=\"id\"\n"+
1203            " type=\"INTEGER\"\n"+
1204            " primaryKey=\"true\"\n"+
1205            " required=\"true\"\n"+
1206            " />\n"+
1207            " </table>\n"+
1208            " <table name=\"B\">\n"+
1209            " <column name=\"id\"\n"+
1210            " javaName=\"id\"\n"+
1211            " type=\"INTEGER\"\n"+
1212            " primaryKey=\"true\"\n"+
1213            " required=\"true\"\n"+
1214            " />\n"+
1215            " </table>\n"+
1216            " <table name=\"C\">\n"+
1217            " <column name=\"aid\"\n"+
1218            " javaName=\"aid\"\n"+
1219            " type=\"INTEGER\"\n"+
1220            " />\n"+
1221            " </table>\n"+
1222            " <table name=\"D\">\n"+
1223            " <column name=\"aid\"\n"+
1224            " javaName=\"aid\"\n"+
1225            " type=\"INTEGER\"\n"+
1226            " />\n"+
1227            " </table>\n"+
1228            "</database>",
1229            runTorqueXDoclet(TORQUE_DEST_FILE, taskProps, torqueSubTaskProps));
1230    }
1231}
1232
Popular Tags