KickJava   Java API By Example, From Geeks To Geeks.

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


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 class-ref attribute
20  *
21  * @author <a HREF="mailto:tomdz@users.sourceforge.net">Thomas Dudziak (tomdz@users.sourceforge.net)</a>
22  */

23 public class ModifyInheritedTagClassRefAttributeTests extends OjbTestBase
24 {
25     public ModifyInheritedTagClassRefAttributeTests(String JavaDoc name)
26     {
27         super(name);
28     }
29
30     // Test: removing class-ref attribute of inherited reference
31
public void testClassRef1()
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 class-ref=\"test.D\"\n"+
41             " * foreignkey=\"attrKey\"\n"+
42             " */\n"+
43             " private test.C attr;\n"+
44             "}\n");
45         addClass(
46             "test.B",
47             "package test;\n"+
48             "/** @ojb.class\n"+
49             " * @ojb.modify-inherited name=\"attr\"\n"+
50             " * class-ref=\"\"\n"+
51             " */\n"+
52             "public class B extends A {}\n");
53         addClass(
54             "test.C",
55             "package test;\n"+
56             "/** @ojb.class */\n"+
57             "public class C {\n"+
58             " /** @ojb.field primarykey=\"true\" */\n"+
59             " private int id;\n"+
60             "}\n");
61         addClass(
62             "test.D",
63             "package test;\n"+
64             "/** @ojb.class */\n"+
65             "public class D extends C {}\n");
66
67         assertEqualsOjbDescriptorFile(
68             "<class-descriptor\n"+
69             " class=\"test.A\"\n"+
70             " table=\"A\"\n"+
71             ">\n"+
72             " <extent-class class-ref=\"test.B\"/>\n"+
73             " <field-descriptor\n"+
74             " name=\"attrKey\"\n"+
75             " column=\"attrKey\"\n"+
76             " jdbc-type=\"INTEGER\"\n"+
77             " >\n"+
78             " </field-descriptor>\n"+
79             " <reference-descriptor\n"+
80             " name=\"attr\"\n"+
81             " class-ref=\"test.D\"\n"+
82             " >\n"+
83             " <foreignkey field-ref=\"attrKey\"/>\n"+
84             " </reference-descriptor>\n"+
85             "</class-descriptor>\n"+
86             "<class-descriptor\n"+
87             " class=\"test.B\"\n"+
88             " table=\"B\"\n"+
89             ">\n"+
90             " <field-descriptor\n"+
91             " name=\"attrKey\"\n"+
92             " column=\"attrKey\"\n"+
93             " jdbc-type=\"INTEGER\"\n"+
94             " >\n"+
95             " </field-descriptor>\n"+
96             " <reference-descriptor\n"+
97             " name=\"attr\"\n"+
98             " class-ref=\"test.C\"\n"+
99             " >\n"+
100             " <foreignkey field-ref=\"attrKey\"/>\n"+
101             " </reference-descriptor>\n"+
102             "</class-descriptor>\n"+
103             "<class-descriptor\n"+
104             " class=\"test.C\"\n"+
105             " table=\"C\"\n"+
106             ">\n"+
107             " <extent-class class-ref=\"test.D\"/>\n"+
108             " <field-descriptor\n"+
109             " name=\"id\"\n"+
110             " column=\"id\"\n"+
111             " jdbc-type=\"INTEGER\"\n"+
112             " primarykey=\"true\"\n"+
113             " >\n"+
114             " </field-descriptor>\n"+
115             "</class-descriptor>\n"+
116             "<class-descriptor\n"+
117             " class=\"test.D\"\n"+
118             " table=\"D\"\n"+
119             ">\n"+
120             " <field-descriptor\n"+
121             " name=\"id\"\n"+
122             " column=\"id\"\n"+
123             " jdbc-type=\"INTEGER\"\n"+
124             " primarykey=\"true\"\n"+
125             " >\n"+
126             " </field-descriptor>\n"+
127             "</class-descriptor>",
128             runOjbXDoclet(OJB_DEST_FILE));
129         assertEqualsTorqueSchemaFile(
130             "<database name=\"ojbtest\">\n"+
131             " <table name=\"A\">\n"+
132             " <column name=\"attrKey\"\n"+
133             " javaName=\"attrKey\"\n"+
134             " type=\"INTEGER\"\n"+
135             " />\n"+
136             " <foreign-key foreignTable=\"D\">\n"+
137             " <reference local=\"attrKey\" foreign=\"id\"/>\n"+
138             " </foreign-key>\n"+
139             " </table>\n"+
140             " <table name=\"B\">\n"+
141             " <column name=\"attrKey\"\n"+
142             " javaName=\"attrKey\"\n"+
143             " type=\"INTEGER\"\n"+
144             " />\n"+
145             " </table>\n"+
146             " <table name=\"C\">\n"+
147             " <column name=\"id\"\n"+
148             " javaName=\"id\"\n"+
149             " type=\"INTEGER\"\n"+
150             " primaryKey=\"true\"\n"+
151             " required=\"true\"\n"+
152             " />\n"+
153             " </table>\n"+
154             " <table name=\"D\">\n"+
155             " <column name=\"id\"\n"+
156             " javaName=\"id\"\n"+
157             " type=\"INTEGER\"\n"+
158             " primaryKey=\"true\"\n"+
159             " required=\"true\"\n"+
160             " />\n"+
161             " </table>\n"+
162             "</database>",
163             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
164     }
165
166     // Test: setting class-ref attribute of inherited reference
167
public void testClassRef2()
168     {
169         addClass(
170             "test.A",
171             "package test;\n"+
172             "/** @ojb.class */\n"+
173             "public class A {\n"+
174             " /** @ojb.field */\n"+
175             " private int attrKey;\n"+
176             " /** @ojb.reference foreignkey=\"attrKey\" */\n"+
177             " private test.C attr;\n"+
178             "}\n");
179         addClass(
180             "test.B",
181             "package test;\n"+
182             "/** @ojb.class\n"+
183             " * @ojb.modify-inherited name=\"attr\"\n"+
184             " * class-ref=\"test.D\"\n"+
185             " */\n"+
186             "public class B extends A {}\n");
187         addClass(
188             "test.C",
189             "package test;\n"+
190             "/** @ojb.class generate-table-info=\"false\" */\n"+
191             "public interface C {}\n");
192         addClass(
193             "test.D",
194             "package test;\n"+
195             "/** @ojb.class */\n"+
196             "public class D implements C {\n"+
197             " /** @ojb.field primarykey=\"true\" */\n"+
198             " private int id;\n"+
199             "}\n");
200
201         assertEqualsOjbDescriptorFile(
202             "<class-descriptor\n"+
203             " class=\"test.A\"\n"+
204             " table=\"A\"\n"+
205             ">\n"+
206             " <extent-class class-ref=\"test.B\"/>\n"+
207             " <field-descriptor\n"+
208             " name=\"attrKey\"\n"+
209             " column=\"attrKey\"\n"+
210             " jdbc-type=\"INTEGER\"\n"+
211             " >\n"+
212             " </field-descriptor>\n"+
213             " <reference-descriptor\n"+
214             " name=\"attr\"\n"+
215             " class-ref=\"test.C\"\n"+
216             " >\n"+
217             " <foreignkey field-ref=\"attrKey\"/>\n"+
218             " </reference-descriptor>\n"+
219             "</class-descriptor>\n"+
220             "<class-descriptor\n"+
221             " class=\"test.B\"\n"+
222             " table=\"B\"\n"+
223             ">\n"+
224             " <field-descriptor\n"+
225             " name=\"attrKey\"\n"+
226             " column=\"attrKey\"\n"+
227             " jdbc-type=\"INTEGER\"\n"+
228             " >\n"+
229             " </field-descriptor>\n"+
230             " <reference-descriptor\n"+
231             " name=\"attr\"\n"+
232             " class-ref=\"test.D\"\n"+
233             " >\n"+
234             " <foreignkey field-ref=\"attrKey\"/>\n"+
235             " </reference-descriptor>\n"+
236             "</class-descriptor>\n"+
237             "<class-descriptor\n"+
238             " class=\"test.C\"\n"+
239             ">\n"+
240             " <extent-class class-ref=\"test.D\"/>\n"+
241             " <field-descriptor\n"+
242             " name=\"id\"\n"+
243             " column=\"id\"\n"+
244             " jdbc-type=\"INTEGER\"\n"+
245             " primarykey=\"true\"\n"+
246             " >\n"+
247             " </field-descriptor>\n"+
248             "</class-descriptor>\n"+
249             "<class-descriptor\n"+
250             " class=\"test.D\"\n"+
251             " table=\"D\"\n"+
252             ">\n"+
253             " <field-descriptor\n"+
254             " name=\"id\"\n"+
255             " column=\"id\"\n"+
256             " jdbc-type=\"INTEGER\"\n"+
257             " primarykey=\"true\"\n"+
258             " >\n"+
259             " </field-descriptor>\n"+
260             "</class-descriptor>",
261             runOjbXDoclet(OJB_DEST_FILE));
262         assertEqualsTorqueSchemaFile(
263             "<database name=\"ojbtest\">\n"+
264             " <table name=\"A\">\n"+
265             " <column name=\"attrKey\"\n"+
266             " javaName=\"attrKey\"\n"+
267             " type=\"INTEGER\"\n"+
268             " />\n"+
269             " <foreign-key foreignTable=\"D\">\n"+
270             " <reference local=\"attrKey\" foreign=\"id\"/>\n"+
271             " </foreign-key>\n"+
272             " </table>\n"+
273             " <table name=\"B\">\n"+
274             " <column name=\"attrKey\"\n"+
275             " javaName=\"attrKey\"\n"+
276             " type=\"INTEGER\"\n"+
277             " />\n"+
278             " <foreign-key foreignTable=\"D\">\n"+
279             " <reference local=\"attrKey\" foreign=\"id\"/>\n"+
280             " </foreign-key>\n"+
281             " </table>\n"+
282             " <table name=\"D\">\n"+
283             " <column name=\"id\"\n"+
284             " javaName=\"id\"\n"+
285             " type=\"INTEGER\"\n"+
286             " primaryKey=\"true\"\n"+
287             " required=\"true\"\n"+
288             " />\n"+
289             " </table>\n"+
290             "</database>",
291             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
292     }
293
294     // Test: setting class-ref attribute of inherited field to invalid value
295
public void testClassRef3()
296     {
297         addClass(
298             "test.A",
299             "package test;\n"+
300             "/** @ojb.class */\n"+
301             "public class A {\n"+
302             " /** @ojb.field */\n"+
303             " private int attrKey;\n"+
304             " /** @ojb.reference foreignkey=\"attrKey\" */\n"+
305             " private test.C attr;\n"+
306             "}\n");
307         addClass(
308             "test.B",
309             "package test;\n"+
310             "/** @ojb.class\n"+
311             " * @ojb.modify-inherited name=\"attr\"\n"+
312             " * class-ref=\"SomeClass\"\n"+
313             " */\n"+
314             "public class B extends A {}\n");
315         addClass(
316             "test.C",
317             "package test;\n"+
318             "/** @ojb.class */\n"+
319             "public class C {\n"+
320             " /** @ojb.field primarykey=\"true\" */\n"+
321             " private int id;\n"+
322             "}\n");
323
324         assertNull(runOjbXDoclet(OJB_DEST_FILE));
325         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
326     }
327
328     // Test: setting class-ref attribute of inherited field to primitive type
329
public void testClassRef4()
330     {
331         addClass(
332             "test.A",
333             "package test;\n"+
334             "/** @ojb.class */\n"+
335             "public class A {\n"+
336             " /** @ojb.field */\n"+
337             " private int attrKey;\n"+
338             " /** @ojb.reference foreignkey=\"attrKey\" */\n"+
339             " private test.C attr;\n"+
340             "}\n");
341         addClass(
342             "test.B",
343             "package test;\n"+
344             "/** @ojb.class\n"+
345             " * @ojb.modify-inherited name=\"attr\"\n"+
346             " * class-ref=\"int\"\n"+
347             " */\n"+
348             "public class B extends A {}\n");
349         addClass(
350             "test.C",
351             "package test;\n"+
352             "/** @ojb.class */\n"+
353             "public class C {\n"+
354             " /** @ojb.field primarykey=\"true\" */\n"+
355             " private int id;\n"+
356             "}\n");
357
358         assertNull(runOjbXDoclet(OJB_DEST_FILE));
359         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
360     }
361
362     // Test: setting class-ref attribute of inherited field to non-persistent type
363
public void testClassRef5()
364     {
365         addClass(
366             "test.A",
367             "package test;\n"+
368             "/** @ojb.class */\n"+
369             "public class A {\n"+
370             " /** @ojb.field */\n"+
371             " private int attrKey;\n"+
372             " /** @ojb.reference foreignkey=\"attrKey\" */\n"+
373             " private test.C attr;\n"+
374             "}\n");
375         addClass(
376             "test.B",
377             "package test;\n"+
378             "/** @ojb.class\n"+
379             " * @ojb.modify-inherited name=\"attr\"\n"+
380             " * class-ref=\"test.D\"\n"+
381             " */\n"+
382             "public class B extends A {}\n");
383         addClass(
384             "test.C",
385             "package test;\n"+
386             "/** @ojb.class */\n"+
387             "public class C {\n"+
388             " /** @ojb.field primarykey=\"true\" */\n"+
389             " private int id;\n"+
390             "}\n");
391         addClass(
392             "test.D",
393             "package test;\n"+
394             "public class D extends C {}\n");
395
396         assertNull(runOjbXDoclet(OJB_DEST_FILE));
397         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
398     }
399
400     // Test: setting class-ref attribute of inherited field to type that is not related to the variable type
401
public void testClassRef6()
402     {
403         addClass(
404             "test.A",
405             "package test;\n"+
406             "/** @ojb.class */\n"+
407             "public class A {\n"+
408             " /** @ojb.field */\n"+
409             " private int attrKey;\n"+
410             " /** @ojb.reference foreignkey=\"attrKey\" */\n"+
411             " private test.C attr;\n"+
412             "}\n");
413         addClass(
414             "test.B",
415             "package test;\n"+
416             "/** @ojb.class\n"+
417             " * @ojb.modify-inherited name=\"attr\"\n"+
418             " * class-ref=\"test.D\"\n"+
419             " */\n"+
420             "public class B extends A {}\n");
421         addClass(
422             "test.C",
423             "package test;\n"+
424             "/** @ojb.class */\n"+
425             "public class C {\n"+
426             " /** @ojb.field primarykey=\"true\" */\n"+
427             " private int id;\n"+
428             "}\n");
429         addClass(
430             "test.D",
431             "package test;\n"+
432             "/** @ojb.class */\n"+
433             "public class D {\n"+
434             " /** @ojb.field primarykey=\"true\" */\n"+
435             " private int id;\n"+
436             "}\n");
437
438         assertNull(runOjbXDoclet(OJB_DEST_FILE));
439         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
440     }
441     
442     // Test: changing class-ref attribute of inherited reference
443
public void testClassRef7()
444     {
445         addClass(
446             "test.A",
447             "package test;\n"+
448             "/** @ojb.class */\n"+
449             "public class A {\n"+
450             " /** @ojb.field */\n"+
451             " private int attrKey;\n"+
452             " /** @ojb.reference class-ref=\"test.C\"\n"+
453             " * foreignkey=\"attrKey\"\n"+
454             " */\n"+
455             " private Object attr;\n"+
456             "}\n");
457         addClass(
458             "test.B",
459             "package test;\n"+
460             "/** @ojb.class\n"+
461             " * @ojb.modify-inherited name=\"attr\"\n"+
462             " * class-ref=\"test.D\"\n"+
463             " */\n"+
464             "public class B extends A {}\n");
465         addClass(
466             "test.C",
467             "package test;\n"+
468             "/** @ojb.class */\n"+
469             "public class C {\n"+
470             " /** @ojb.field primarykey=\"true\" */\n"+
471             " private int id;\n"+
472             "}\n");
473         addClass(
474             "test.D",
475             "package test;\n"+
476             "/** @ojb.class */\n"+
477             "public class D extends C {}\n");
478
479         assertEqualsOjbDescriptorFile(
480             "<class-descriptor\n"+
481             " class=\"test.A\"\n"+
482             " table=\"A\"\n"+
483             ">\n"+
484             " <extent-class class-ref=\"test.B\"/>\n"+
485             " <field-descriptor\n"+
486             " name=\"attrKey\"\n"+
487             " column=\"attrKey\"\n"+
488             " jdbc-type=\"INTEGER\"\n"+
489             " >\n"+
490             " </field-descriptor>\n"+
491             " <reference-descriptor\n"+
492             " name=\"attr\"\n"+
493             " class-ref=\"test.C\"\n"+
494             " >\n"+
495             " <foreignkey field-ref=\"attrKey\"/>\n"+
496             " </reference-descriptor>\n"+
497             "</class-descriptor>\n"+
498             "<class-descriptor\n"+
499             " class=\"test.B\"\n"+
500             " table=\"B\"\n"+
501             ">\n"+
502             " <field-descriptor\n"+
503             " name=\"attrKey\"\n"+
504             " column=\"attrKey\"\n"+
505             " jdbc-type=\"INTEGER\"\n"+
506             " >\n"+
507             " </field-descriptor>\n"+
508             " <reference-descriptor\n"+
509             " name=\"attr\"\n"+
510             " class-ref=\"test.D\"\n"+
511             " >\n"+
512             " <foreignkey field-ref=\"attrKey\"/>\n"+
513             " </reference-descriptor>\n"+
514             "</class-descriptor>\n"+
515             "<class-descriptor\n"+
516             " class=\"test.C\"\n"+
517             " table=\"C\"\n"+
518             ">\n"+
519             " <extent-class class-ref=\"test.D\"/>\n"+
520             " <field-descriptor\n"+
521             " name=\"id\"\n"+
522             " column=\"id\"\n"+
523             " jdbc-type=\"INTEGER\"\n"+
524             " primarykey=\"true\"\n"+
525             " >\n"+
526             " </field-descriptor>\n"+
527             "</class-descriptor>\n"+
528             "<class-descriptor\n"+
529             " class=\"test.D\"\n"+
530             " table=\"D\"\n"+
531             ">\n"+
532             " <field-descriptor\n"+
533             " name=\"id\"\n"+
534             " column=\"id\"\n"+
535             " jdbc-type=\"INTEGER\"\n"+
536             " primarykey=\"true\"\n"+
537             " >\n"+
538             " </field-descriptor>\n"+
539             "</class-descriptor>",
540             runOjbXDoclet(OJB_DEST_FILE));
541         assertEqualsTorqueSchemaFile(
542             "<database name=\"ojbtest\">\n"+
543             " <table name=\"A\">\n"+
544             " <column name=\"attrKey\"\n"+
545             " javaName=\"attrKey\"\n"+
546             " type=\"INTEGER\"\n"+
547             " />\n"+
548             " </table>\n"+
549             " <table name=\"B\">\n"+
550             " <column name=\"attrKey\"\n"+
551             " javaName=\"attrKey\"\n"+
552             " type=\"INTEGER\"\n"+
553             " />\n"+
554             " <foreign-key foreignTable=\"D\">\n"+
555             " <reference local=\"attrKey\" foreign=\"id\"/>\n"+
556             " </foreign-key>\n"+
557             " </table>\n"+
558             " <table name=\"C\">\n"+
559             " <column name=\"id\"\n"+
560             " javaName=\"id\"\n"+
561             " type=\"INTEGER\"\n"+
562             " primaryKey=\"true\"\n"+
563             " required=\"true\"\n"+
564             " />\n"+
565             " </table>\n"+
566             " <table name=\"D\">\n"+
567             " <column name=\"id\"\n"+
568             " javaName=\"id\"\n"+
569             " type=\"INTEGER\"\n"+
570             " primaryKey=\"true\"\n"+
571             " required=\"true\"\n"+
572             " />\n"+
573             " </table>\n"+
574             "</database>",
575             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
576     }
577
578     // Test: changing class-ref attribute of inherited reference to invalid value
579
public void testClassRef8()
580     {
581         addClass(
582             "test.A",
583             "package test;\n"+
584             "/** @ojb.class */\n"+
585             "public class A {\n"+
586             " /** @ojb.field */\n"+
587             " private int attrKey;\n"+
588             " /** @ojb.reference class-ref=\"test.C\"\n"+
589             " * foreignkey=\"attrKey\"\n"+
590             " */\n"+
591             " private Object attr;\n"+
592             "}\n");
593         addClass(
594             "test.B",
595             "package test;\n"+
596             "/** @ojb.class\n"+
597             " * @ojb.modify-inherited name=\"attr\"\n"+
598             " * class-ref=\"SomeClass\"\n"+
599             " */\n"+
600             "public class B extends A {}\n");
601         addClass(
602             "test.C",
603             "package test;\n"+
604             "/** @ojb.class */\n"+
605             "public class C {\n"+
606             " /** @ojb.field primarykey=\"true\" */\n"+
607             " private int id;\n"+
608             "}\n");
609
610         assertNull(runOjbXDoclet(OJB_DEST_FILE));
611         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
612     }
613
614     // Test: changing class-ref attribute of inherited reference to primitive type
615
public void testClassRef9()
616     {
617         addClass(
618             "test.A",
619             "package test;\n"+
620             "/** @ojb.class */\n"+
621             "public class A {\n"+
622             " /** @ojb.field */\n"+
623             " private int attrKey;\n"+
624             " /** @ojb.reference class-ref=\"test.C\"\n"+
625             " * foreignkey=\"attrKey\"\n"+
626             " */\n"+
627             " private Object attr;\n"+
628             "}\n");
629         addClass(
630             "test.B",
631             "package test;\n"+
632             "/** @ojb.class\n"+
633             " * @ojb.modify-inherited name=\"attr\"\n"+
634             " * class-ref=\"char\"\n"+
635             " */\n"+
636             "public class B extends A {}\n");
637         addClass(
638             "test.C",
639             "package test;\n"+
640             "/** @ojb.class */\n"+
641             "public class C {\n"+
642             " /** @ojb.field primarykey=\"true\" */\n"+
643             " private int id;\n"+
644             "}\n");
645
646         assertNull(runOjbXDoclet(OJB_DEST_FILE));
647         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
648     }
649
650     // Test: changing class-ref attribute of inherited reference to non-persistent type
651
public void testClassRef10()
652     {
653         addClass(
654             "test.A",
655             "package test;\n"+
656             "/** @ojb.class */\n"+
657             "public class A {\n"+
658             " /** @ojb.field */\n"+
659             " private int attrKey;\n"+
660             " /** @ojb.reference class-ref=\"test.C\"\n"+
661             " * foreignkey=\"attrKey\"\n"+
662             " */\n"+
663             " private Object attr;\n"+
664             "}\n");
665         addClass(
666             "test.B",
667             "package test;\n"+
668             "/** @ojb.class\n"+
669             " * @ojb.modify-inherited name=\"attr\"\n"+
670             " * class-ref=\"test.D\"\n"+
671             " */\n"+
672             "public class B extends A {}\n");
673         addClass(
674             "test.C",
675             "package test;\n"+
676             "/** @ojb.class */\n"+
677             "public class C {\n"+
678             " /** @ojb.field primarykey=\"true\" */\n"+
679             " private int id;\n"+
680             "}\n");
681         addClass(
682             "test.D",
683             "package test;\n"+
684             "public class D extends C {}\n");
685
686         assertNull(runOjbXDoclet(OJB_DEST_FILE));
687         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
688     }
689
690     // Test: changing class-ref attribute of inherited reference to type not related to the original type but to the variable type
691
public void testClassRef11()
692     {
693         addClass(
694             "test.A",
695             "package test;\n"+
696             "/** @ojb.class */\n"+
697             "public class A {\n"+
698             " /** @ojb.field */\n"+
699             " private int attrKey;\n"+
700             " /** @ojb.reference class-ref=\"test.C\"\n"+
701             " * foreignkey=\"attrKey\"\n"+
702             " */\n"+
703             " private Object attr;\n"+
704             "}\n");
705         addClass(
706             "test.B",
707             "package test;\n"+
708             "/** @ojb.class\n"+
709             " * @ojb.modify-inherited name=\"attr\"\n"+
710             " * class-ref=\"test.D\"\n"+
711             " */\n"+
712             "public class B extends A {}\n");
713         addClass(
714             "test.C",
715             "package test;\n"+
716             "/** @ojb.class */\n"+
717             "public class C {\n"+
718             " /** @ojb.field primarykey=\"true\" */\n"+
719             " private int idC;\n"+
720             "}\n");
721         addClass(
722             "test.D",
723             "package test;\n"+
724             "/** @ojb.class */\n"+
725             "public class D {\n"+
726             " /** @ojb.field primarykey=\"true\" */\n"+
727             " private int idD;\n"+
728             "}\n");
729
730         assertEqualsOjbDescriptorFile(
731             "<class-descriptor\n"+
732             " class=\"test.A\"\n"+
733             " table=\"A\"\n"+
734             ">\n"+
735             " <extent-class class-ref=\"test.B\"/>\n"+
736             " <field-descriptor\n"+
737             " name=\"attrKey\"\n"+
738             " column=\"attrKey\"\n"+
739             " jdbc-type=\"INTEGER\"\n"+
740             " >\n"+
741             " </field-descriptor>\n"+
742             " <reference-descriptor\n"+
743             " name=\"attr\"\n"+
744             " class-ref=\"test.C\"\n"+
745             " >\n"+
746             " <foreignkey field-ref=\"attrKey\"/>\n"+
747             " </reference-descriptor>\n"+
748             "</class-descriptor>\n"+
749             "<class-descriptor\n"+
750             " class=\"test.B\"\n"+
751             " table=\"B\"\n"+
752             ">\n"+
753             " <field-descriptor\n"+
754             " name=\"attrKey\"\n"+
755             " column=\"attrKey\"\n"+
756             " jdbc-type=\"INTEGER\"\n"+
757             " >\n"+
758             " </field-descriptor>\n"+
759             " <reference-descriptor\n"+
760             " name=\"attr\"\n"+
761             " class-ref=\"test.D\"\n"+
762             " >\n"+
763             " <foreignkey field-ref=\"attrKey\"/>\n"+
764             " </reference-descriptor>\n"+
765             "</class-descriptor>\n"+
766             "<class-descriptor\n"+
767             " class=\"test.C\"\n"+
768             " table=\"C\"\n"+
769             ">\n"+
770             " <field-descriptor\n"+
771             " name=\"idC\"\n"+
772             " column=\"idC\"\n"+
773             " jdbc-type=\"INTEGER\"\n"+
774             " primarykey=\"true\"\n"+
775             " >\n"+
776             " </field-descriptor>\n"+
777             "</class-descriptor>\n"+
778             "<class-descriptor\n"+
779             " class=\"test.D\"\n"+
780             " table=\"D\"\n"+
781             ">\n"+
782             " <field-descriptor\n"+
783             " name=\"idD\"\n"+
784             " column=\"idD\"\n"+
785             " jdbc-type=\"INTEGER\"\n"+
786             " primarykey=\"true\"\n"+
787             " >\n"+
788             " </field-descriptor>\n"+
789             "</class-descriptor>",
790             runOjbXDoclet(OJB_DEST_FILE));
791         assertEqualsTorqueSchemaFile(
792             "<database name=\"ojbtest\">\n"+
793             " <table name=\"A\">\n"+
794             " <column name=\"attrKey\"\n"+
795             " javaName=\"attrKey\"\n"+
796             " type=\"INTEGER\"\n"+
797             " />\n"+
798             " <foreign-key foreignTable=\"C\">\n"+
799             " <reference local=\"attrKey\" foreign=\"idC\"/>\n"+
800             " </foreign-key>\n"+
801             " </table>\n"+
802             " <table name=\"B\">\n"+
803             " <column name=\"attrKey\"\n"+
804             " javaName=\"attrKey\"\n"+
805             " type=\"INTEGER\"\n"+
806             " />\n"+
807             " <foreign-key foreignTable=\"D\">\n"+
808             " <reference local=\"attrKey\" foreign=\"idD\"/>\n"+
809             " </foreign-key>\n"+
810             " </table>\n"+
811             " <table name=\"C\">\n"+
812             " <column name=\"idC\"\n"+
813             " javaName=\"idC\"\n"+
814             " type=\"INTEGER\"\n"+
815             " primaryKey=\"true\"\n"+
816             " required=\"true\"\n"+
817             " />\n"+
818             " </table>\n"+
819             " <table name=\"D\">\n"+
820             " <column name=\"idD\"\n"+
821             " javaName=\"idD\"\n"+
822             " type=\"INTEGER\"\n"+
823             " primaryKey=\"true\"\n"+
824             " required=\"true\"\n"+
825             " />\n"+
826             " </table>\n"+
827             "</database>",
828             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
829     }
830
831     // Test: changing class-ref attribute of inherited field to type not related to variable type
832
public void testClassRef12()
833     {
834         addClass(
835             "test.A",
836             "package test;\n"+
837             "/** @ojb.class */\n"+
838             "public class A {\n"+
839             " /** @ojb.field */\n"+
840             " private int attrKey;\n"+
841             " /** @ojb.reference class-ref=\"test.D\"\n"+
842             " * foreignkey=\"attrKey\"\n"+
843             " */\n"+
844             " private test.C attr;\n"+
845             "}\n");
846         addClass(
847             "test.B",
848             "package test;\n"+
849             "/** @ojb.class\n"+
850             " * @ojb.modify-inherited name=\"attr\"\n"+
851             " * class-ref=\"test.E\"\n"+
852             " */\n"+
853             "public class B extends A {}\n");
854         addClass(
855             "test.C",
856             "package test;\n"+
857             "/** @ojb.class\n"+
858             " * @ojb.field name=\"id\"\n"+
859             " * jdbc-type=\"INTEGER\"\n"+
860             " * primarykey=\"true\"\n"+
861             " */\n"+
862             "public interface C {}\n");
863         addClass(
864             "test.D",
865             "package test;\n"+
866             "/** @ojb.class */\n"+
867             "public class D implements C {}\n");
868         addClass(
869             "test.E",
870             "package test;\n"+
871             "/** @ojb.class */\n"+
872             "public class E {\n"+
873             " /** @ojb.field primarykey=\"true\" */\n"+
874             " private int id;\n"+
875             "}\n");
876
877         assertNull(runOjbXDoclet(OJB_DEST_FILE));
878         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
879     }
880 }
881
Popular Tags