KickJava   Java API By Example, From Geeks To Geeks.

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


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

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