KickJava   Java API By Example, From Geeks To Geeks.

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


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