KickJava   Java API By Example, From Geeks To Geeks.

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


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

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