KickJava   Java API By Example, From Geeks To Geeks.

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


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

23 public class ModifyInheritedTagAttributesAttributeTests extends OjbTestBase
24 {
25     public ModifyInheritedTagAttributesAttributeTests(String JavaDoc name)
26     {
27         super(name);
28     }
29
30     // Test: modifying the attributes attribute of a field in a direct base class
31
public void testAttributes1()
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             " * attributes=\"a=b\"\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             " >\n"+
72             " <attribute attribute-name=\"a\" attribute-value=\"b\"/>\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 attributes attribute of a reference in an indirect base class
95
public void testAttributes2()
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             " * attributes=\"a=b\"\n"+
106             " */\n"+
107             " private B b;\n"+
108             "}");
109         addClass(
110             "test.B",
111             "package test;\n"+
112             "/** @ojb.class */\n" +
113             "public class B {\n"+
114             " /** @ojb.field primarykey=\"true\" */\n"+
115             " private int id;\n"+
116             "}");
117         addClass(
118             "test.C",
119             "package test;\n"+
120             "public class C extends A {}");
121         addClass(
122             "test.D",
123             "package test;\n"+
124             "/** @ojb.class */\n" +
125             "public class D extends C {}");
126         addClass(
127             "test.E",
128             "package test;\n"+
129             "/** @ojb.class\n" +
130             " * @ojb.modify-inherited name=\"b\"\n"+
131             " * attributes=\"b=c\"\n"+
132             " */\n"+
133             "public class E extends D {}\n");
134
135         assertEqualsOjbDescriptorFile(
136             "<class-descriptor\n"+
137             " class=\"test.A\"\n"+
138             " table=\"A\"\n"+
139             ">\n"+
140             " <extent-class class-ref=\"test.D\"/>\n"+
141             " <field-descriptor\n"+
142             " name=\"bid\"\n"+
143             " column=\"bid\"\n"+
144             " jdbc-type=\"INTEGER\"\n"+
145             " >\n"+
146             " </field-descriptor>\n"+
147             " <reference-descriptor\n"+
148             " name=\"b\"\n"+
149             " class-ref=\"test.B\"\n"+
150             " >\n"+
151             " <foreignkey field-ref=\"bid\"/>\n"+
152             " <attribute attribute-name=\"a\" attribute-value=\"b\"/>\n"+
153             " </reference-descriptor>\n"+
154             "</class-descriptor>\n"+
155             "<class-descriptor\n"+
156             " class=\"test.B\"\n"+
157             " table=\"B\"\n"+
158             ">\n"+
159             " <field-descriptor\n"+
160             " name=\"id\"\n"+
161             " column=\"id\"\n"+
162             " jdbc-type=\"INTEGER\"\n"+
163             " primarykey=\"true\"\n"+
164             " >\n"+
165             " </field-descriptor>\n"+
166             "</class-descriptor>\n"+
167             "<class-descriptor\n"+
168             " class=\"test.D\"\n"+
169             " table=\"D\"\n"+
170             ">\n"+
171             " <extent-class class-ref=\"test.E\"/>\n"+
172             " <field-descriptor\n"+
173             " name=\"bid\"\n"+
174             " column=\"bid\"\n"+
175             " jdbc-type=\"INTEGER\"\n"+
176             " >\n"+
177             " </field-descriptor>\n"+
178             " <reference-descriptor\n"+
179             " name=\"b\"\n"+
180             " class-ref=\"test.B\"\n"+
181             " >\n"+
182             " <foreignkey field-ref=\"bid\"/>\n"+
183             " <attribute attribute-name=\"a\" attribute-value=\"b\"/>\n"+
184             " </reference-descriptor>\n"+
185             "</class-descriptor>\n"+
186             "<class-descriptor\n"+
187             " class=\"test.E\"\n"+
188             " table=\"E\"\n"+
189             ">\n"+
190             " <field-descriptor\n"+
191             " name=\"bid\"\n"+
192             " column=\"bid\"\n"+
193             " jdbc-type=\"INTEGER\"\n"+
194             " >\n"+
195             " </field-descriptor>\n"+
196             " <reference-descriptor\n"+
197             " name=\"b\"\n"+
198             " class-ref=\"test.B\"\n"+
199             " >\n"+
200             " <foreignkey field-ref=\"bid\"/>\n"+
201             " <attribute attribute-name=\"b\" attribute-value=\"c\"/>\n"+
202             " </reference-descriptor>\n"+
203             "</class-descriptor>",
204             runOjbXDoclet(OJB_DEST_FILE));
205         assertEqualsTorqueSchemaFile(
206             "<database name=\"ojbtest\">\n"+
207             " <table name=\"A\">\n"+
208             " <column name=\"bid\"\n"+
209             " javaName=\"bid\"\n"+
210             " type=\"INTEGER\"\n"+
211             " />\n"+
212             " <foreign-key foreignTable=\"B\">\n"+
213             " <reference local=\"bid\" foreign=\"id\"/>\n"+
214             " </foreign-key>\n"+
215             " </table>\n"+
216             " <table name=\"B\">\n"+
217             " <column name=\"id\"\n"+
218             " javaName=\"id\"\n"+
219             " type=\"INTEGER\"\n"+
220             " primaryKey=\"true\"\n"+
221             " required=\"true\"\n"+
222             " />\n"+
223             " </table>\n"+
224             " <table name=\"D\">\n"+
225             " <column name=\"bid\"\n"+
226             " javaName=\"bid\"\n"+
227             " type=\"INTEGER\"\n"+
228             " />\n"+
229             " <foreign-key foreignTable=\"B\">\n"+
230             " <reference local=\"bid\" foreign=\"id\"/>\n"+
231             " </foreign-key>\n"+
232             " </table>\n"+
233             " <table name=\"E\">\n"+
234             " <column name=\"bid\"\n"+
235             " javaName=\"bid\"\n"+
236             " type=\"INTEGER\"\n"+
237             " />\n"+
238             " <foreign-key foreignTable=\"B\">\n"+
239             " <reference local=\"bid\" foreign=\"id\"/>\n"+
240             " </foreign-key>\n"+
241             " </table>\n"+
242             "</database>",
243             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
244     }
245
246     // Test: modifying the attributes attribute of a collection in an direct base class
247
public void testAttributes3()
248     {
249         addClass(
250             "test.A",
251             "package test;\n"+
252             "/** @ojb.class */\n" +
253             "public class A {\n"+
254             " /** @ojb.field primarykey=\"true\" */\n"+
255             " private int id;\n"+
256             " /** @ojb.collection element-class-ref=\"test.B\"\n"+
257             " * foreignkey=\"aid\"\n"+
258             " * attributes=\"a=b,c=d\"\n" +
259             " * database-foreignkey=\"false\"\n"+
260             " */\n"+
261             " private java.util.Collection bs;\n"+
262             "}");
263         addClass(
264             "test.B",
265             "package test;\n"+
266             "/** @ojb.class */\n" +
267             "public class B {\n"+
268             " /** @ojb.field */\n"+
269             " private int aid;\n"+
270             "}");
271         addClass(
272             "test.C",
273             "package test;\n"+
274             "/** @ojb.class\n" +
275             " * @ojb.modify-inherited name=\"bs\"\n"+
276             " * attributes=\"a=d\"\n"+
277             " */\n"+
278             "public class C extends A {}\n");
279         addClass(
280             "test.D",
281             "package test;\n"+
282             "/** @ojb.class */\n"+
283             "public class D extends C {}\n");
284
285         assertEqualsOjbDescriptorFile(
286             "<class-descriptor\n"+
287             " class=\"test.A\"\n"+
288             " table=\"A\"\n"+
289             ">\n"+
290             " <extent-class class-ref=\"test.C\"/>\n"+
291             " <field-descriptor\n"+
292             " name=\"id\"\n"+
293             " column=\"id\"\n"+
294             " jdbc-type=\"INTEGER\"\n"+
295             " primarykey=\"true\"\n"+
296             " >\n"+
297             " </field-descriptor>\n"+
298             " <collection-descriptor\n"+
299             " name=\"bs\"\n"+
300             " element-class-ref=\"test.B\"\n"+
301             " >\n"+
302             " <inverse-foreignkey field-ref=\"aid\"/>\n"+
303             " <attribute attribute-name=\"a\" attribute-value=\"b\"/>\n"+
304             " <attribute attribute-name=\"c\" attribute-value=\"d\"/>\n"+
305             " </collection-descriptor>\n"+
306             "</class-descriptor>\n"+
307             "<class-descriptor\n"+
308             " class=\"test.B\"\n"+
309             " table=\"B\"\n"+
310             ">\n"+
311             " <field-descriptor\n"+
312             " name=\"aid\"\n"+
313             " column=\"aid\"\n"+
314             " jdbc-type=\"INTEGER\"\n"+
315             " >\n"+
316             " </field-descriptor>\n"+
317             "</class-descriptor>\n"+
318             "<class-descriptor\n"+
319             " class=\"test.C\"\n"+
320             " table=\"C\"\n"+
321             ">\n"+
322             " <extent-class class-ref=\"test.D\"/>\n"+
323             " <field-descriptor\n"+
324             " name=\"id\"\n"+
325             " column=\"id\"\n"+
326             " jdbc-type=\"INTEGER\"\n"+
327             " primarykey=\"true\"\n"+
328             " >\n"+
329             " </field-descriptor>\n"+
330             " <collection-descriptor\n"+
331             " name=\"bs\"\n"+
332             " element-class-ref=\"test.B\"\n"+
333             " >\n"+
334             " <inverse-foreignkey field-ref=\"aid\"/>\n"+
335             " <attribute attribute-name=\"a\" attribute-value=\"d\"/>\n"+
336             " </collection-descriptor>\n"+
337             "</class-descriptor>\n"+
338             "<class-descriptor\n"+
339             " class=\"test.D\"\n"+
340             " table=\"D\"\n"+
341             ">\n"+
342             " <field-descriptor\n"+
343             " name=\"id\"\n"+
344             " column=\"id\"\n"+
345             " jdbc-type=\"INTEGER\"\n"+
346             " primarykey=\"true\"\n"+
347             " >\n"+
348             " </field-descriptor>\n"+
349             " <collection-descriptor\n"+
350             " name=\"bs\"\n"+
351             " element-class-ref=\"test.B\"\n"+
352             " >\n"+
353             " <inverse-foreignkey field-ref=\"aid\"/>\n"+
354             " <attribute attribute-name=\"a\" attribute-value=\"d\"/>\n"+
355             " </collection-descriptor>\n"+
356             "</class-descriptor>",
357             runOjbXDoclet(OJB_DEST_FILE));
358         assertEqualsTorqueSchemaFile(
359             "<database name=\"ojbtest\">\n"+
360             " <table name=\"A\">\n"+
361             " <column name=\"id\"\n"+
362             " javaName=\"id\"\n"+
363             " type=\"INTEGER\"\n"+
364             " primaryKey=\"true\"\n"+
365             " required=\"true\"\n"+
366             " />\n"+
367             " </table>\n"+
368             " <table name=\"B\">\n"+
369             " <column name=\"aid\"\n"+
370             " javaName=\"aid\"\n"+
371             " type=\"INTEGER\"\n"+
372             " />\n"+
373             " </table>\n"+
374             " <table name=\"C\">\n"+
375             " <column name=\"id\"\n"+
376             " javaName=\"id\"\n"+
377             " type=\"INTEGER\"\n"+
378             " primaryKey=\"true\"\n"+
379             " required=\"true\"\n"+
380             " />\n"+
381             " </table>\n"+
382             " <table name=\"D\">\n"+
383             " <column name=\"id\"\n"+
384             " javaName=\"id\"\n"+
385             " type=\"INTEGER\"\n"+
386             " primaryKey=\"true\"\n"+
387             " required=\"true\"\n"+
388             " />\n"+
389             " </table>\n"+
390             "</database>",
391             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
392     }
393
394     // Test: modifying the attributes attribute of an anonymous field in a direct base class
395
public void testAttributes4()
396     {
397         addClass(
398             "test.A",
399             "package test;\n"+
400             "/** @ojb.class\n"+
401             " * @ojb.field name=\"attr\"\n"+
402             " * jdbc-type=\"INTEGER\"\n"+
403             " */\n" +
404             "public class A {}");
405         addClass(
406             "test.B",
407             "package test;\n"+
408             "/** @ojb.class\n" +
409             " * @ojb.modify-inherited name=\"attr\"\n"+
410             " * attributes=\"a=b\"\n"+
411             " */\n"+
412             "public class B extends A {}\n");
413
414         assertEqualsOjbDescriptorFile(
415             "<class-descriptor\n"+
416             " class=\"test.A\"\n"+
417             " table=\"A\"\n"+
418             ">\n"+
419             " <extent-class class-ref=\"test.B\"/>\n"+
420             " <field-descriptor\n"+
421             " name=\"attr\"\n"+
422             " column=\"attr\"\n"+
423             " jdbc-type=\"INTEGER\"\n"+
424             " access=\"anonymous\"\n"+
425             " >\n"+
426             " </field-descriptor>\n"+
427             "</class-descriptor>\n"+
428             "<class-descriptor\n"+
429             " class=\"test.B\"\n"+
430             " table=\"B\"\n"+
431             ">\n"+
432             " <field-descriptor\n"+
433             " name=\"attr\"\n"+
434             " column=\"attr\"\n"+
435             " jdbc-type=\"INTEGER\"\n"+
436             " access=\"anonymous\"\n"+
437             " >\n"+
438             " <attribute attribute-name=\"a\" attribute-value=\"b\"/>\n"+
439             " </field-descriptor>\n"+
440             "</class-descriptor>",
441             runOjbXDoclet(OJB_DEST_FILE));
442         assertEqualsTorqueSchemaFile(
443             "<database name=\"ojbtest\">\n"+
444             " <table name=\"A\">\n"+
445             " <column name=\"attr\"\n"+
446             " javaName=\"attr\"\n"+
447             " type=\"INTEGER\"\n"+
448             " />\n"+
449             " </table>\n"+
450             " <table name=\"B\">\n"+
451             " <column name=\"attr\"\n"+
452             " javaName=\"attr\"\n"+
453             " type=\"INTEGER\"\n"+
454             " />\n"+
455             " </table>\n"+
456             "</database>",
457             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
458     }
459
460
461     // Test: removing the attributes attribute of a field in a direct base class
462
public void testAttributes5()
463     {
464         addClass(
465             "test.A",
466             "package test;\n"+
467             "/** @ojb.class */\n" +
468             "public class A {\n"+
469             " /** @ojb.field attributes=\"a=b\" */\n"+
470             " private int attr;\n"+
471             "}");
472         addClass(
473             "test.B",
474             "package test;\n"+
475             "/** @ojb.class\n" +
476             " * @ojb.modify-inherited name=\"attr\"\n"+
477             " * attributes=\"\"\n"+
478             " */\n"+
479             "public class B extends A {}\n");
480
481         assertEqualsOjbDescriptorFile(
482             "<class-descriptor\n"+
483             " class=\"test.A\"\n"+
484             " table=\"A\"\n"+
485             ">\n"+
486             " <extent-class class-ref=\"test.B\"/>\n"+
487             " <field-descriptor\n"+
488             " name=\"attr\"\n"+
489             " column=\"attr\"\n"+
490             " jdbc-type=\"INTEGER\"\n"+
491             " >\n"+
492             " <attribute attribute-name=\"a\" attribute-value=\"b\"/>\n"+
493             " </field-descriptor>\n"+
494             "</class-descriptor>\n"+
495             "<class-descriptor\n"+
496             " class=\"test.B\"\n"+
497             " table=\"B\"\n"+
498             ">\n"+
499             " <field-descriptor\n"+
500             " name=\"attr\"\n"+
501             " column=\"attr\"\n"+
502             " jdbc-type=\"INTEGER\"\n"+
503             " >\n"+
504             " </field-descriptor>\n"+
505             "</class-descriptor>",
506             runOjbXDoclet(OJB_DEST_FILE));
507         assertEqualsTorqueSchemaFile(
508             "<database name=\"ojbtest\">\n"+
509             " <table name=\"A\">\n"+
510             " <column name=\"attr\"\n"+
511             " javaName=\"attr\"\n"+
512             " type=\"INTEGER\"\n"+
513             " />\n"+
514             " </table>\n"+
515             " <table name=\"B\">\n"+
516             " <column name=\"attr\"\n"+
517             " javaName=\"attr\"\n"+
518             " type=\"INTEGER\"\n"+
519             " />\n"+
520             " </table>\n"+
521             "</database>",
522             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
523     }
524 }
525
Popular Tags