KickJava   Java API By Example, From Geeks To Geeks.

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


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

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