KickJava   Java API By Example, From Geeks To Geeks.

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


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

23 public class ModifyInheritedTagIdAttributeTests extends OjbTestBase
24 {
25     public ModifyInheritedTagIdAttributeTests(String JavaDoc name)
26     {
27         super(name);
28     }
29
30     // Test: removing id attribute of inherited field
31
public void testId1()
32     {
33         addClass(
34             "test.A",
35             "package test;\n"+
36             "/** @ojb.class */\n"+
37             "public class A {\n"+
38             "/** @ojb.field id=\"3\" */\n"+
39             " private int attrA;\n"+
40             "/** @ojb.field id=\"1\" */\n"+
41             " private int attrB;\n"+
42             "/** @ojb.field id=\"2\" */\n"+
43             " private int attrC;\n"+
44             "}\n");
45         addClass(
46             "test.B",
47             "package test;\n"+
48             "/** @ojb.class\n"+
49             " * @ojb.modify-inherited name=\"attrC\"\n"+
50             " * id=\"\"\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=\"attrB\"\n"+
62             " column=\"attrB\"\n"+
63             " jdbc-type=\"INTEGER\"\n"+
64             " >\n"+
65             " </field-descriptor>\n"+
66             " <field-descriptor\n"+
67             " name=\"attrC\"\n"+
68             " column=\"attrC\"\n"+
69             " jdbc-type=\"INTEGER\"\n"+
70             " >\n"+
71             " </field-descriptor>\n"+
72             " <field-descriptor\n"+
73             " name=\"attrA\"\n"+
74             " column=\"attrA\"\n"+
75             " jdbc-type=\"INTEGER\"\n"+
76             " >\n"+
77             " </field-descriptor>\n"+
78             "</class-descriptor>\n"+
79             "<class-descriptor\n"+
80             " class=\"test.B\"\n"+
81             " table=\"B\"\n"+
82             ">\n"+
83             " <field-descriptor\n"+
84             " name=\"attrB\"\n"+
85             " column=\"attrB\"\n"+
86             " jdbc-type=\"INTEGER\"\n"+
87             " >\n"+
88             " </field-descriptor>\n"+
89             " <field-descriptor\n"+
90             " name=\"attrA\"\n"+
91             " column=\"attrA\"\n"+
92             " jdbc-type=\"INTEGER\"\n"+
93             " >\n"+
94             " </field-descriptor>\n"+
95             " <field-descriptor\n"+
96             " name=\"attrC\"\n"+
97             " column=\"attrC\"\n"+
98             " jdbc-type=\"INTEGER\"\n"+
99             " >\n"+
100             " </field-descriptor>\n"+
101             "</class-descriptor>",
102             runOjbXDoclet(OJB_DEST_FILE));
103         assertEqualsTorqueSchemaFile(
104             "<database name=\"ojbtest\">\n"+
105             " <table name=\"A\">\n"+
106             " <column name=\"attrB\"\n"+
107             " javaName=\"attrB\"\n"+
108             " type=\"INTEGER\"\n"+
109             " />\n"+
110             " <column name=\"attrC\"\n"+
111             " javaName=\"attrC\"\n"+
112             " type=\"INTEGER\"\n"+
113             " />\n"+
114             " <column name=\"attrA\"\n"+
115             " javaName=\"attrA\"\n"+
116             " type=\"INTEGER\"\n"+
117             " />\n"+
118             " </table>\n"+
119             " <table name=\"B\">\n"+
120             " <column name=\"attrB\"\n"+
121             " javaName=\"attrB\"\n"+
122             " type=\"INTEGER\"\n"+
123             " />\n"+
124             " <column name=\"attrA\"\n"+
125             " javaName=\"attrA\"\n"+
126             " type=\"INTEGER\"\n"+
127             " />\n"+
128             " <column name=\"attrC\"\n"+
129             " javaName=\"attrC\"\n"+
130             " type=\"INTEGER\"\n"+
131             " />\n"+
132             " </table>\n"+
133             "</database>",
134             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
135     }
136
137     // Test: adding id attribute to remotely inherited field
138
public void testId2()
139     {
140         addClass(
141             "test.A",
142             "package test;\n"+
143             "/** @ojb.class\n"+
144             " * @ojb.field name=\"attrC\"\n"+
145             " * jdbc-type=\"INTEGER\"\n"+
146             " */\n"+
147             "public class A {\n"+
148             "/** @ojb.field id=\"3\" */\n"+
149             " private int attrA;\n"+
150             "/** @ojb.field id=\"1\" */\n"+
151             " private int attrB;\n"+
152             "}\n");
153         addClass(
154             "test.B",
155             "package test;\n"+
156             "/** @ojb.class */\n"+
157             "public class B extends A {}\n");
158         addClass(
159             "test.C",
160             "package test;\n"+
161             "/** @ojb.class\n"+
162             " * @ojb.modify-inherited name=\"attrC\"\n"+
163             " * id=\"2\"\n"+
164             " */\n"+
165             "public class C extends B {}\n");
166
167         assertEqualsOjbDescriptorFile(
168             "<class-descriptor\n"+
169             " class=\"test.A\"\n"+
170             " table=\"A\"\n"+
171             ">\n"+
172             " <extent-class class-ref=\"test.B\"/>\n"+
173             " <field-descriptor\n"+
174             " name=\"attrB\"\n"+
175             " column=\"attrB\"\n"+
176             " jdbc-type=\"INTEGER\"\n"+
177             " >\n"+
178             " </field-descriptor>\n"+
179             " <field-descriptor\n"+
180             " name=\"attrA\"\n"+
181             " column=\"attrA\"\n"+
182             " jdbc-type=\"INTEGER\"\n"+
183             " >\n"+
184             " </field-descriptor>\n"+
185             " <field-descriptor\n"+
186             " name=\"attrC\"\n"+
187             " column=\"attrC\"\n"+
188             " jdbc-type=\"INTEGER\"\n"+
189             " access=\"anonymous\"\n"+
190             " >\n"+
191             " </field-descriptor>\n"+
192             "</class-descriptor>\n"+
193             "<class-descriptor\n"+
194             " class=\"test.B\"\n"+
195             " table=\"B\"\n"+
196             ">\n"+
197             " <extent-class class-ref=\"test.C\"/>\n"+
198             " <field-descriptor\n"+
199             " name=\"attrB\"\n"+
200             " column=\"attrB\"\n"+
201             " jdbc-type=\"INTEGER\"\n"+
202             " >\n"+
203             " </field-descriptor>\n"+
204             " <field-descriptor\n"+
205             " name=\"attrA\"\n"+
206             " column=\"attrA\"\n"+
207             " jdbc-type=\"INTEGER\"\n"+
208             " >\n"+
209             " </field-descriptor>\n"+
210             " <field-descriptor\n"+
211             " name=\"attrC\"\n"+
212             " column=\"attrC\"\n"+
213             " jdbc-type=\"INTEGER\"\n"+
214             " access=\"anonymous\"\n"+
215             " >\n"+
216             " </field-descriptor>\n"+
217             "</class-descriptor>\n"+
218             "<class-descriptor\n"+
219             " class=\"test.C\"\n"+
220             " table=\"C\"\n"+
221             ">\n"+
222             " <field-descriptor\n"+
223             " name=\"attrB\"\n"+
224             " column=\"attrB\"\n"+
225             " jdbc-type=\"INTEGER\"\n"+
226             " >\n"+
227             " </field-descriptor>\n"+
228             " <field-descriptor\n"+
229             " name=\"attrC\"\n"+
230             " column=\"attrC\"\n"+
231             " jdbc-type=\"INTEGER\"\n"+
232             " access=\"anonymous\"\n"+
233             " >\n"+
234             " </field-descriptor>\n"+
235             " <field-descriptor\n"+
236             " name=\"attrA\"\n"+
237             " column=\"attrA\"\n"+
238             " jdbc-type=\"INTEGER\"\n"+
239             " >\n"+
240             " </field-descriptor>\n"+
241             "</class-descriptor>",
242             runOjbXDoclet(OJB_DEST_FILE));
243         assertEqualsTorqueSchemaFile(
244             "<database name=\"ojbtest\">\n"+
245             " <table name=\"A\">\n"+
246             " <column name=\"attrB\"\n"+
247             " javaName=\"attrB\"\n"+
248             " type=\"INTEGER\"\n"+
249             " />\n"+
250             " <column name=\"attrA\"\n"+
251             " javaName=\"attrA\"\n"+
252             " type=\"INTEGER\"\n"+
253             " />\n"+
254             " <column name=\"attrC\"\n"+
255             " javaName=\"attrC\"\n"+
256             " type=\"INTEGER\"\n"+
257             " />\n"+
258             " </table>\n"+
259             " <table name=\"B\">\n"+
260             " <column name=\"attrB\"\n"+
261             " javaName=\"attrB\"\n"+
262             " type=\"INTEGER\"\n"+
263             " />\n"+
264             " <column name=\"attrA\"\n"+
265             " javaName=\"attrA\"\n"+
266             " type=\"INTEGER\"\n"+
267             " />\n"+
268             " <column name=\"attrC\"\n"+
269             " javaName=\"attrC\"\n"+
270             " type=\"INTEGER\"\n"+
271             " />\n"+
272             " </table>\n"+
273             " <table name=\"C\">\n"+
274             " <column name=\"attrB\"\n"+
275             " javaName=\"attrB\"\n"+
276             " type=\"INTEGER\"\n"+
277             " />\n"+
278             " <column name=\"attrC\"\n"+
279             " javaName=\"attrC\"\n"+
280             " type=\"INTEGER\"\n"+
281             " />\n"+
282             " <column name=\"attrA\"\n"+
283             " javaName=\"attrA\"\n"+
284             " type=\"INTEGER\"\n"+
285             " />\n"+
286             " </table>\n"+
287             "</database>",
288             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
289     }
290
291     // Test: invalid value
292
public void testId3()
293     {
294         addClass(
295             "test.A",
296             "package test;\n"+
297             "/** @ojb.class */\n"+
298             "public class A {\n"+
299             "/** @ojb.field id=\"3\" */\n"+
300             " private int attrA;\n"+
301             "/** @ojb.field id=\"1\" */\n"+
302             " private int attrB;\n"+
303             "/** @ojb.field id=\"2\" */\n"+
304             " private int attrC;\n"+
305             "}\n");
306         addClass(
307             "test.B",
308             "package test;\n"+
309             "/** @ojb.class\n"+
310             " * @ojb.modify-inherited name=\"attrB\"\n"+
311             " * id=\"a\"\n"+
312             " */\n"+
313             "public class B extends A {}\n");
314
315         assertNull(runOjbXDoclet(OJB_DEST_FILE));
316         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
317     }
318
319     // Test: changing id attribute of inherited field
320
public void testId4()
321     {
322         addClass(
323             "test.A",
324             "package test;\n"+
325             "/** @ojb.class */\n"+
326             "public class A {\n"+
327             "/** @ojb.field id=\"3\" */\n"+
328             " private int attrA;\n"+
329             "/** @ojb.field id=\"1\" */\n"+
330             " private int attrB;\n"+
331             "/** @ojb.field id=\"2\" */\n"+
332             " private int attrC;\n"+
333             "}\n");
334         addClass(
335             "test.B",
336             "package test;\n"+
337             "/** @ojb.class\n"+
338             " * @ojb.modify-inherited name=\"attrB\"\n"+
339             " * id=\"4\"\n"+
340             " */\n"+
341             "public class B extends A {}\n");
342         addClass(
343             "test.C",
344             "package test;\n"+
345             "/** @ojb.class */\n"+
346             "public class C extends B {}\n");
347
348         assertEqualsOjbDescriptorFile(
349             "<class-descriptor\n"+
350             " class=\"test.A\"\n"+
351             " table=\"A\"\n"+
352             ">\n"+
353             " <extent-class class-ref=\"test.B\"/>\n"+
354             " <field-descriptor\n"+
355             " name=\"attrB\"\n"+
356             " column=\"attrB\"\n"+
357             " jdbc-type=\"INTEGER\"\n"+
358             " >\n"+
359             " </field-descriptor>\n"+
360             " <field-descriptor\n"+
361             " name=\"attrC\"\n"+
362             " column=\"attrC\"\n"+
363             " jdbc-type=\"INTEGER\"\n"+
364             " >\n"+
365             " </field-descriptor>\n"+
366             " <field-descriptor\n"+
367             " name=\"attrA\"\n"+
368             " column=\"attrA\"\n"+
369             " jdbc-type=\"INTEGER\"\n"+
370             " >\n"+
371             " </field-descriptor>\n"+
372             "</class-descriptor>\n"+
373             "<class-descriptor\n"+
374             " class=\"test.B\"\n"+
375             " table=\"B\"\n"+
376             ">\n"+
377             " <extent-class class-ref=\"test.C\"/>\n"+
378             " <field-descriptor\n"+
379             " name=\"attrC\"\n"+
380             " column=\"attrC\"\n"+
381             " jdbc-type=\"INTEGER\"\n"+
382             " >\n"+
383             " </field-descriptor>\n"+
384             " <field-descriptor\n"+
385             " name=\"attrA\"\n"+
386             " column=\"attrA\"\n"+
387             " jdbc-type=\"INTEGER\"\n"+
388             " >\n"+
389             " </field-descriptor>\n"+
390             " <field-descriptor\n"+
391             " name=\"attrB\"\n"+
392             " column=\"attrB\"\n"+
393             " jdbc-type=\"INTEGER\"\n"+
394             " >\n"+
395             " </field-descriptor>\n"+
396             "</class-descriptor>\n"+
397             "<class-descriptor\n"+
398             " class=\"test.C\"\n"+
399             " table=\"C\"\n"+
400             ">\n"+
401             " <field-descriptor\n"+
402             " name=\"attrC\"\n"+
403             " column=\"attrC\"\n"+
404             " jdbc-type=\"INTEGER\"\n"+
405             " >\n"+
406             " </field-descriptor>\n"+
407             " <field-descriptor\n"+
408             " name=\"attrA\"\n"+
409             " column=\"attrA\"\n"+
410             " jdbc-type=\"INTEGER\"\n"+
411             " >\n"+
412             " </field-descriptor>\n"+
413             " <field-descriptor\n"+
414             " name=\"attrB\"\n"+
415             " column=\"attrB\"\n"+
416             " jdbc-type=\"INTEGER\"\n"+
417             " >\n"+
418             " </field-descriptor>\n"+
419             "</class-descriptor>",
420             runOjbXDoclet(OJB_DEST_FILE));
421         assertEqualsTorqueSchemaFile(
422             "<database name=\"ojbtest\">\n"+
423             " <table name=\"A\">\n"+
424             " <column name=\"attrB\"\n"+
425             " javaName=\"attrB\"\n"+
426             " type=\"INTEGER\"\n"+
427             " />\n"+
428             " <column name=\"attrC\"\n"+
429             " javaName=\"attrC\"\n"+
430             " type=\"INTEGER\"\n"+
431             " />\n"+
432             " <column name=\"attrA\"\n"+
433             " javaName=\"attrA\"\n"+
434             " type=\"INTEGER\"\n"+
435             " />\n"+
436             " </table>\n"+
437             " <table name=\"B\">\n"+
438             " <column name=\"attrC\"\n"+
439             " javaName=\"attrC\"\n"+
440             " type=\"INTEGER\"\n"+
441             " />\n"+
442             " <column name=\"attrA\"\n"+
443             " javaName=\"attrA\"\n"+
444             " type=\"INTEGER\"\n"+
445             " />\n"+
446             " <column name=\"attrB\"\n"+
447             " javaName=\"attrB\"\n"+
448             " type=\"INTEGER\"\n"+
449             " />\n"+
450             " </table>\n"+
451             " <table name=\"C\">\n"+
452             " <column name=\"attrC\"\n"+
453             " javaName=\"attrC\"\n"+
454             " type=\"INTEGER\"\n"+
455             " />\n"+
456             " <column name=\"attrA\"\n"+
457             " javaName=\"attrA\"\n"+
458             " type=\"INTEGER\"\n"+
459             " />\n"+
460             " <column name=\"attrB\"\n"+
461             " javaName=\"attrB\"\n"+
462             " type=\"INTEGER\"\n"+
463             " />\n"+
464             " </table>\n"+
465             "</database>",
466             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
467     }
468 }
469
Popular Tags