KickJava   Java API By Example, From Geeks To Geeks.

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


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