KickJava   Java API By Example, From Geeks To Geeks.

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


1 package xdoclet.modules.ojb.tests;
2
3 /* Copyright 2002-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /**
19  * Tests for the ojb.modify-inherited tag with the precision and scale attributes.
20  * Note that the XDoclet OJB module does not check the values of precision/scale
21  * because it may be database dependent what can be put in there.
22  * Also it does not check whether the jdbc type really supports precision/scale
23  *
24  * @author <a HREF="mailto:tomdz@users.sourceforge.net">Thomas Dudziak (tomdz@users.sourceforge.net)</a>
25  */

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