KickJava   Java API By Example, From Geeks To Geeks.

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


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

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