KickJava   Java API By Example, From Geeks To Geeks.

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


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 jdbc-type attribute
20  * Note that the xdoclet ojb module does not check whether the JDBC type required a conversion when used
21  * for the field's java type, so most of the tests here would not make sense in a real application.
22  *
23  * @author <a HREF="mailto:tomdz@users.sourceforge.net">Thomas Dudziak (tomdz@users.sourceforge.net)</a>
24  * TODO Add tests for the new allowed jdbc types: STRUCT | ARRAY | REF | BOOLEAN | DATALINK
25  */

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