KickJava   Java API By Example, From Geeks To Geeks.

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


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

23 public class FieldTagAutoincrementAttributeTests extends OjbTestBase
24 {
25     public FieldTagAutoincrementAttributeTests(String JavaDoc name)
26     {
27         super(name);
28     }
29
30     // Test: autoincrement attribute with no value
31
public void testAutoincrement1()
32     {
33         addClass(
34             "test.A",
35             "package test;\n"+
36             "/** @ojb.class */\n"+
37             "public class A {\n"+
38             "/** @ojb.field autoincrement=\"\" */\n"+
39             " private int attr;\n"+
40             "}\n");
41
42         assertNull(runOjbXDoclet(OJB_DEST_FILE));
43         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
44     }
45
46     // Test: autoincrement attribute with invalid value
47
public void testAutoincrement2()
48     {
49         addClass(
50             "test.A",
51             "package test;\n"+
52             "/** @ojb.class */\n"+
53             "public class A {\n"+
54             "/** @ojb.field autoincrement=\"true\" */\n"+
55             " private int attr;\n"+
56             "}\n");
57
58         assertNull(runOjbXDoclet(OJB_DEST_FILE));
59         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
60     }
61
62     // Test: autoincrement attribute with 'none' value
63
public void testAutoincrement3()
64     {
65         addClass(
66             "test.A",
67             "package test;\n"+
68             "/** @ojb.class */\n"+
69             "public class A {\n"+
70             "/** @ojb.field autoincrement=\"none\" */\n"+
71             " private int attr;\n"+
72             "}\n");
73
74         assertEqualsOjbDescriptorFile(
75             "<class-descriptor\n"+
76             " class=\"test.A\"\n"+
77             " table=\"A\"\n"+
78             ">\n"+
79             " <field-descriptor\n"+
80             " name=\"attr\"\n"+
81             " column=\"attr\"\n"+
82             " jdbc-type=\"INTEGER\"\n"+
83             " >\n"+
84             " </field-descriptor>\n"+
85             "</class-descriptor>",
86             runOjbXDoclet(OJB_DEST_FILE));
87         assertEqualsTorqueSchemaFile(
88             "<database name=\"ojbtest\">\n"+
89             " <table name=\"A\">\n"+
90             " <column name=\"attr\"\n"+
91             " javaName=\"attr\"\n"+
92             " type=\"INTEGER\"\n"+
93             " />\n"+
94             " </table>\n"+
95             "</database>",
96             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
97     }
98
99     // Test: autoincrement attribute with 'ojb' value
100
public void testAutoincrement4()
101     {
102         addClass(
103             "test.A",
104             "package test;\n"+
105             "/** @ojb.class */\n"+
106             "public class A {\n"+
107             "/** @ojb.field autoincrement=\"ojb\" */\n"+
108             " private int attr;\n"+
109             "}\n");
110
111         assertEqualsOjbDescriptorFile(
112             "<class-descriptor\n"+
113             " class=\"test.A\"\n"+
114             " table=\"A\"\n"+
115             ">\n"+
116             " <field-descriptor\n"+
117             " name=\"attr\"\n"+
118             " column=\"attr\"\n"+
119             " jdbc-type=\"INTEGER\"\n"+
120             " autoincrement=\"true\"\n"+
121             " >\n"+
122             " </field-descriptor>\n"+
123             "</class-descriptor>",
124             runOjbXDoclet(OJB_DEST_FILE));
125         assertEqualsTorqueSchemaFile(
126             "<database name=\"ojbtest\">\n"+
127             " <table name=\"A\">\n"+
128             " <column name=\"attr\"\n"+
129             " javaName=\"attr\"\n"+
130             " type=\"INTEGER\"\n"+
131             " />\n"+
132             " </table>\n"+
133             "</database>",
134             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
135     }
136
137     // Test: autoincrement attribute with 'database' value
138
public void testAutoincrement5()
139     {
140         addClass(
141             "test.A",
142             "package test;\n"+
143             "/** @ojb.class */\n"+
144             "public class A {\n"+
145             "/** @ojb.field autoincrement=\"database\" */\n"+
146             " private int attr;\n"+
147             "}\n");
148
149         assertEqualsOjbDescriptorFile(
150             "<class-descriptor\n"+
151             " class=\"test.A\"\n"+
152             " table=\"A\"\n"+
153             ">\n"+
154             " <field-descriptor\n"+
155             " name=\"attr\"\n"+
156             " column=\"attr\"\n"+
157             " jdbc-type=\"INTEGER\"\n"+
158             " autoincrement=\"true\"\n"+
159             " access=\"readonly\"\n"+
160             " >\n"+
161             " </field-descriptor>\n"+
162             "</class-descriptor>",
163             runOjbXDoclet(OJB_DEST_FILE));
164         assertEqualsTorqueSchemaFile(
165             "<database name=\"ojbtest\">\n"+
166             " <table name=\"A\">\n"+
167             " <column name=\"attr\"\n"+
168             " javaName=\"attr\"\n"+
169             " type=\"INTEGER\"\n"+
170             " autoIncrement=\"true\"\n"+
171             " />\n"+
172             " </table>\n"+
173             "</database>",
174             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
175     }
176     
177     // Test: inherited autoincrement attribute with 'ojb' value
178
public void testAutoincrement6()
179     {
180         addClass(
181             "test.A",
182             "package test;\n"+
183             "/** @ojb.class */\n"+
184             "public class A {\n"+
185             "/** @ojb.field autoincrement=\"ojb\" */\n"+
186             " private int attr;\n"+
187             "}\n");
188         addClass(
189             "test.B",
190             "package test;\n"+
191             "public class B extends A {}\n");
192         addClass(
193             "test.C",
194             "package test;\n"+
195             "/** @ojb.class */\n"+
196             "public class C extends B {}\n");
197
198         assertEqualsOjbDescriptorFile(
199             "<class-descriptor\n"+
200             " class=\"test.A\"\n"+
201             " table=\"A\"\n"+
202             ">\n"+
203             " <extent-class class-ref=\"test.C\"/>\n"+
204             " <field-descriptor\n"+
205             " name=\"attr\"\n"+
206             " column=\"attr\"\n"+
207             " jdbc-type=\"INTEGER\"\n"+
208             " autoincrement=\"true\"\n"+
209             " >\n"+
210             " </field-descriptor>\n"+
211             "</class-descriptor>\n"+
212             "<class-descriptor\n"+
213             " class=\"test.C\"\n"+
214             " table=\"C\"\n"+
215             ">\n"+
216             " <field-descriptor\n"+
217             " name=\"attr\"\n"+
218             " column=\"attr\"\n"+
219             " jdbc-type=\"INTEGER\"\n"+
220             " autoincrement=\"true\"\n"+
221             " >\n"+
222             " </field-descriptor>\n"+
223             "</class-descriptor>",
224             runOjbXDoclet(OJB_DEST_FILE));
225         assertEqualsTorqueSchemaFile(
226             "<database name=\"ojbtest\">\n"+
227             " <table name=\"A\">\n"+
228             " <column name=\"attr\"\n"+
229             " javaName=\"attr\"\n"+
230             " type=\"INTEGER\"\n"+
231             " />\n"+
232             " </table>\n"+
233             " <table name=\"C\">\n"+
234             " <column name=\"attr\"\n"+
235             " javaName=\"attr\"\n"+
236             " type=\"INTEGER\"\n"+
237             " />\n"+
238             " </table>\n"+
239             "</database>",
240             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
241     }
242
243     // Test: autoincrement attribute with 'database' value together with access attribute
244
public void testAutoincrement7()
245     {
246         addClass(
247             "test.A",
248             "package test;\n"+
249             "/** @ojb.class */\n"+
250             "public class A {\n"+
251             " /** @ojb.field autoincrement=\"database\"\n"+
252             " * access=\"readonly\"\n"+
253             " */\n"+
254             " private int attr;\n"+
255             "}\n");
256
257         assertEqualsOjbDescriptorFile(
258             "<class-descriptor\n"+
259             " class=\"test.A\"\n"+
260             " table=\"A\"\n"+
261             ">\n"+
262             " <field-descriptor\n"+
263             " name=\"attr\"\n"+
264             " column=\"attr\"\n"+
265             " jdbc-type=\"INTEGER\"\n"+
266             " autoincrement=\"true\"\n"+
267             " access=\"readonly\"\n"+
268             " >\n"+
269             " </field-descriptor>\n"+
270             "</class-descriptor>",
271             runOjbXDoclet(OJB_DEST_FILE));
272         assertEqualsTorqueSchemaFile(
273             "<database name=\"ojbtest\">\n"+
274             " <table name=\"A\">\n"+
275             " <column name=\"attr\"\n"+
276             " javaName=\"attr\"\n"+
277             " type=\"INTEGER\"\n"+
278             " autoIncrement=\"true\"\n"+
279             " />\n"+
280             " </table>\n"+
281             "</database>",
282             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
283     }
284
285     // Test: autoincrement attribute with 'database' value together with different access attribute
286
public void testAutoincrement8()
287     {
288         addClass(
289             "test.A",
290             "package test;\n"+
291             "/** @ojb.class */\n"+
292             "public class A {\n"+
293             " /** @ojb.field autoincrement=\"database\"\n"+
294             " * access=\"readwrite\"\n"+
295             " */\n"+
296             " private int attr;\n"+
297             "}\n");
298
299         assertEqualsOjbDescriptorFile(
300             "<class-descriptor\n"+
301             " class=\"test.A\"\n"+
302             " table=\"A\"\n"+
303             ">\n"+
304             " <field-descriptor\n"+
305             " name=\"attr\"\n"+
306             " column=\"attr\"\n"+
307             " jdbc-type=\"INTEGER\"\n"+
308             " autoincrement=\"true\"\n"+
309             " access=\"readonly\"\n"+
310             " >\n"+
311             " </field-descriptor>\n"+
312             "</class-descriptor>",
313             runOjbXDoclet(OJB_DEST_FILE));
314         assertEqualsTorqueSchemaFile(
315             "<database name=\"ojbtest\">\n"+
316             " <table name=\"A\">\n"+
317             " <column name=\"attr\"\n"+
318             " javaName=\"attr\"\n"+
319             " type=\"INTEGER\"\n"+
320             " autoIncrement=\"true\"\n"+
321             " />\n"+
322             " </table>\n"+
323             "</database>",
324             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
325     }
326 }
327
328
Popular Tags