KickJava   Java API By Example, From Geeks To Geeks.

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


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

23 public class ModifyInheritedTagSequenceNameAttributeTests extends OjbTestBase
24 {
25     public ModifyInheritedTagSequenceNameAttributeTests(String JavaDoc name)
26     {
27         super(name);
28     }
29
30     // Test: modifying the sequence-name attribute of a field in a direct base class
31
public void testSequenceName1()
32     {
33         addClass(
34             "test.A",
35             "package test;\n"+
36             "/** @ojb.class */\n" +
37             "public class A {\n"+
38             " /** @ojb.field autoincrement=\"database\" */\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             " * sequence-name=\"SomeSequence\"\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             " autoincrement=\"true\"\n"+
61             " access=\"readonly\"\n"+
62             " >\n"+
63             " </field-descriptor>\n"+
64             "</class-descriptor>\n"+
65             "<class-descriptor\n"+
66             " class=\"test.B\"\n"+
67             " table=\"B\"\n"+
68             ">\n"+
69             " <field-descriptor\n"+
70             " name=\"attr\"\n"+
71             " column=\"attr\"\n"+
72             " jdbc-type=\"INTEGER\"\n"+
73             " autoincrement=\"true\"\n"+
74             " sequence-name=\"SomeSequence\"\n"+
75             " access=\"readonly\"\n"+
76             " >\n"+
77             " </field-descriptor>\n"+
78             "</class-descriptor>",
79             runOjbXDoclet(OJB_DEST_FILE));
80         assertEqualsTorqueSchemaFile(
81             "<database name=\"ojbtest\">\n"+
82             " <table name=\"A\">\n"+
83             " <column name=\"attr\"\n"+
84             " javaName=\"attr\"\n"+
85             " type=\"INTEGER\"\n"+
86             " autoIncrement=\"true\"\n"+
87             " />\n"+
88             " </table>\n"+
89             " <table name=\"B\">\n"+
90             " <column name=\"attr\"\n"+
91             " javaName=\"attr\"\n"+
92             " type=\"INTEGER\"\n"+
93             " autoIncrement=\"true\"\n"+
94             " />\n"+
95             " </table>\n"+
96             "</database>",
97             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
98     }
99
100     // Test: modifying the sequence-name attribute of a reference
101
public void testSequenceName2()
102     {
103         addClass(
104             "test.A",
105             "package test;\n"+
106             "/** @ojb.class */\n" +
107             "public class A {\n"+
108             " /** @ojb.field */\n"+
109             " private int bid;\n"+
110             " /** @ojb.reference foreignkey=\"bid\" */\n"+
111             " private B b;\n"+
112             "}");
113         addClass(
114             "test.B",
115             "package test;\n"+
116             "/** @ojb.class */\n" +
117             "public class B {\n"+
118             " /** @ojb.field primarykey=\"true\" */\n"+
119             " private int id;\n"+
120             "}");
121         addClass(
122             "test.C",
123             "package test;\n"+
124             "/** @ojb.class\n" +
125             " * @ojb.modify-inherited name=\"b\"\n"+
126             " * sequence-name=\"SomeSequence\"\n"+
127             " */\n"+
128             "public class C extends A {}\n");
129
130         assertNull(runOjbXDoclet(OJB_DEST_FILE));
131         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
132     }
133
134     // Test: modifying the sequence-name attribute of a collection
135
public void testSequenceName3()
136     {
137         addClass(
138             "test.A",
139             "package test;\n"+
140             "/** @ojb.class */\n" +
141             "public class A {\n"+
142             " /** @ojb.field primarykey=\"true\" */\n"+
143             " private int id;\n"+
144             " /** @ojb.collection element-class-ref=\"test.B\"\n"+
145             " * foreignkey=\"aid\"\n"+
146             " */\n"+
147             " private java.util.Collection bs;\n"+
148             "}");
149         addClass(
150             "test.B",
151             "package test;\n"+
152             "/** @ojb.class */\n" +
153             "public class B {\n"+
154             " /** @ojb.field */\n"+
155             " private int aid;\n"+
156             "}");
157         addClass(
158             "test.C",
159             "package test;\n"+
160             "/** @ojb.class\n" +
161             " * @ojb.modify-inherited name=\"bs\"\n"+
162             " * sequence-name=\"SomeSequence\"\n"+
163             " */\n"+
164             "public class C extends A {}\n");
165
166         assertNull(runOjbXDoclet(OJB_DEST_FILE));
167         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
168     }
169
170     // Test: modifying the sequence-name attribute of an anonymous field in a direct base class
171
public void testSequenceName4()
172     {
173         addClass(
174             "test.A",
175             "package test;\n"+
176             "/** @ojb.class\n"+
177             " * @ojb.field name=\"attr\"\n"+
178             " * jdbc-type=\"INTEGER\"\n"+
179             " */\n" +
180             "public class A {}");
181         addClass(
182             "test.B",
183             "package test;\n"+
184             "/** @ojb.class\n" +
185             " * @ojb.modify-inherited name=\"attr\"\n"+
186             " * autoincrement=\"ojb\"\n"+
187             " * sequence-name=\"SomeSequence\"\n"+
188             " */\n"+
189             "public class B extends A {}\n");
190
191         assertEqualsOjbDescriptorFile(
192             "<class-descriptor\n"+
193             " class=\"test.A\"\n"+
194             " table=\"A\"\n"+
195             ">\n"+
196             " <extent-class class-ref=\"test.B\"/>\n"+
197             " <field-descriptor\n"+
198             " name=\"attr\"\n"+
199             " column=\"attr\"\n"+
200             " jdbc-type=\"INTEGER\"\n"+
201             " access=\"anonymous\"\n"+
202             " >\n"+
203             " </field-descriptor>\n"+
204             "</class-descriptor>\n"+
205             "<class-descriptor\n"+
206             " class=\"test.B\"\n"+
207             " table=\"B\"\n"+
208             ">\n"+
209             " <field-descriptor\n"+
210             " name=\"attr\"\n"+
211             " column=\"attr\"\n"+
212             " jdbc-type=\"INTEGER\"\n"+
213             " autoincrement=\"true\"\n"+
214             " sequence-name=\"SomeSequence\"\n"+
215             " access=\"anonymous\"\n"+
216             " >\n"+
217             " </field-descriptor>\n"+
218             "</class-descriptor>",
219             runOjbXDoclet(OJB_DEST_FILE));
220         assertEqualsTorqueSchemaFile(
221             "<database name=\"ojbtest\">\n"+
222             " <table name=\"A\">\n"+
223             " <column name=\"attr\"\n"+
224             " javaName=\"attr\"\n"+
225             " type=\"INTEGER\"\n"+
226             " />\n"+
227             " </table>\n"+
228             " <table name=\"B\">\n"+
229             " <column name=\"attr\"\n"+
230             " javaName=\"attr\"\n"+
231             " type=\"INTEGER\"\n"+
232             " />\n"+
233             " </table>\n"+
234             "</database>",
235             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
236     }
237
238     // Test: unsetting value
239
public void testSequenceName5()
240     {
241         addClass(
242             "test.A",
243             "package test;\n"+
244             "/** @ojb.class */\n" +
245             "public class A {\n"+
246             " /** @ojb.field autoincrement=\"ojb\"\n"+
247             " * sequence-name=\"SomeSequence\"\n" +
248             " */\n"+
249             " private int attr;\n"+
250             "}");
251         addClass(
252             "test.B",
253             "package test;\n"+
254             "/** @ojb.class\n" +
255             " * @ojb.modify-inherited name=\"attr\"\n"+
256             " * sequence-name=\"\"\n"+
257             " */\n"+
258             "public class B extends A {}\n");
259
260         assertEqualsOjbDescriptorFile(
261             "<class-descriptor\n"+
262             " class=\"test.A\"\n"+
263             " table=\"A\"\n"+
264             ">\n"+
265             " <extent-class class-ref=\"test.B\"/>\n"+
266             " <field-descriptor\n"+
267             " name=\"attr\"\n"+
268             " column=\"attr\"\n"+
269             " jdbc-type=\"INTEGER\"\n"+
270             " autoincrement=\"true\"\n"+
271             " sequence-name=\"SomeSequence\"\n"+
272             " >\n"+
273             " </field-descriptor>\n"+
274             "</class-descriptor>\n"+
275             "<class-descriptor\n"+
276             " class=\"test.B\"\n"+
277             " table=\"B\"\n"+
278             ">\n"+
279             " <field-descriptor\n"+
280             " name=\"attr\"\n"+
281             " column=\"attr\"\n"+
282             " jdbc-type=\"INTEGER\"\n"+
283             " autoincrement=\"true\"\n"+
284             " >\n"+
285             " </field-descriptor>\n"+
286             "</class-descriptor>",
287             runOjbXDoclet(OJB_DEST_FILE));
288         assertEqualsTorqueSchemaFile(
289             "<database name=\"ojbtest\">\n"+
290             " <table name=\"A\">\n"+
291             " <column name=\"attr\"\n"+
292             " javaName=\"attr\"\n"+
293             " type=\"INTEGER\"\n"+
294             " />\n"+
295             " </table>\n"+
296             " <table name=\"B\">\n"+
297             " <column name=\"attr\"\n"+
298             " javaName=\"attr\"\n"+
299             " type=\"INTEGER\"\n"+
300             " />\n"+
301             " </table>\n"+
302             "</database>",
303             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
304     }
305
306     // Test: modifying both autoincrement and sequence-name but values don't fit
307
public void testSequenceName6()
308     {
309         addClass(
310             "test.A",
311             "package test;\n"+
312             "/** @ojb.class */\n" +
313             "public class A {\n"+
314             " /** @ojb.field autoincrement=\"ojb\" */\n"+
315             " private int attr;\n"+
316             "}");
317         addClass(
318             "test.B",
319             "package test;\n"+
320             "/** @ojb.class\n" +
321             " * @ojb.modify-inherited name=\"attr\"\n"+
322             " * autoincrement=\"database\"\n"+
323             " * sequence-name=\"SomeSequence\"\n"+
324             " */\n"+
325             "public class B extends A {}\n");
326
327         assertEqualsOjbDescriptorFile(
328             "<class-descriptor\n"+
329             " class=\"test.A\"\n"+
330             " table=\"A\"\n"+
331             ">\n"+
332             " <extent-class class-ref=\"test.B\"/>\n"+
333             " <field-descriptor\n"+
334             " name=\"attr\"\n"+
335             " column=\"attr\"\n"+
336             " jdbc-type=\"INTEGER\"\n"+
337             " autoincrement=\"true\"\n"+
338             " >\n"+
339             " </field-descriptor>\n"+
340             "</class-descriptor>\n"+
341             "<class-descriptor\n"+
342             " class=\"test.B\"\n"+
343             " table=\"B\"\n"+
344             ">\n"+
345             " <field-descriptor\n"+
346             " name=\"attr\"\n"+
347             " column=\"attr\"\n"+
348             " jdbc-type=\"INTEGER\"\n"+
349             " autoincrement=\"true\"\n"+
350             " sequence-name=\"SomeSequence\"\n"+
351             " access=\"readonly\"\n"+
352             " >\n"+
353             " </field-descriptor>\n"+
354             "</class-descriptor>",
355             runOjbXDoclet(OJB_DEST_FILE));
356         assertEqualsTorqueSchemaFile(
357             "<database name=\"ojbtest\">\n"+
358             " <table name=\"A\">\n"+
359             " <column name=\"attr\"\n"+
360             " javaName=\"attr\"\n"+
361             " type=\"INTEGER\"\n"+
362             " />\n"+
363             " </table>\n"+
364             " <table name=\"B\">\n"+
365             " <column name=\"attr\"\n"+
366             " javaName=\"attr\"\n"+
367             " type=\"INTEGER\"\n"+
368             " autoIncrement=\"true\"\n"+
369             " />\n"+
370             " </table>\n"+
371             "</database>",
372             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
373     }
374 }
375
Popular Tags