KickJava   Java API By Example, From Geeks To Geeks.

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


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

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