KickJava   Java API By Example, From Geeks To Geeks.

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


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

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