KickJava   Java API By Example, From Geeks To Geeks.

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


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

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