KickJava   Java API By Example, From Geeks To Geeks.

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


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

23 public class ClassTagTableAttributeTests extends OjbTestBase
24 {
25     public ClassTagTableAttributeTests(String JavaDoc name)
26     {
27         super(name);
28     }
29
30     // Test of table: empty value
31
public void testTable1()
32     {
33         addClass(
34             "test.A",
35             "package test;\n"+
36             "/** @ojb.class table=\"\" */\n"+
37             "public class A {}\n");
38
39         addClass(
40             "test.A",
41             "package test;\n"+
42             "/** @ojb.class */\n"+
43             "public class A {}\n");
44
45         assertEqualsOjbDescriptorFile(
46             "<class-descriptor\n"+
47             " class=\"test.A\"\n"+
48             " table=\"A\"\n"+
49             ">\n"+
50             "</class-descriptor>",
51             runOjbXDoclet(OJB_DEST_FILE));
52         assertEqualsTorqueSchemaFile(
53             "<database name=\"ojbtest\">\n"+
54             " <table name=\"A\">\n"+
55             " </table>\n"+
56             "</database>",
57             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
58     }
59
60     // Test of table: normal use, no sub- or base classes
61
public void testTable2()
62     {
63         addClass(
64             "test.A",
65             "package test;\n"+
66             "/** @ojb.class table=\"TABLE_A\" */\n"+
67             "public class A {}\n");
68
69         assertEqualsOjbDescriptorFile(
70             "<class-descriptor\n"+
71             " class=\"test.A\"\n"+
72             " table=\"TABLE_A\"\n"+
73             ">\n"+
74             "</class-descriptor>",
75             runOjbXDoclet(OJB_DEST_FILE));
76         assertEqualsTorqueSchemaFile(
77             "<database name=\"ojbtest\">\n"+
78             " <table name=\"TABLE_A\">\n"+
79             " </table>\n"+
80             "</database>",
81             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
82     }
83
84     // Test of table: normal use with remote base- and subclass
85
public void testTable3()
86     {
87         addClass(
88             "test.A",
89             "package test;\n"+
90             "/** @ojb.class */\n"+
91             "public class A {}\n");
92         addClass(
93             "test.B",
94             "package test;\n"+
95             "public class B extends A {}\n");
96         addClass(
97             "test.C",
98             "package test;\n"+
99             "/** @ojb.class table=\"C_TABLE\" */\n"+
100             "public class C extends B {}\n");
101         addClass(
102             "test.D",
103             "package test;\n"+
104             "public class D extends C {}\n");
105         addClass(
106             "test.E",
107             "package test;\n"+
108             "/** @ojb.class */\n"+
109             "public class E extends D {}\n");
110
111         assertEqualsOjbDescriptorFile(
112             "<class-descriptor\n"+
113             " class=\"test.A\"\n"+
114             " table=\"A\"\n"+
115             ">\n"+
116             " <extent-class class-ref=\"test.C\"/>\n"+
117             "</class-descriptor>\n"+
118             "<class-descriptor\n"+
119             " class=\"test.C\"\n"+
120             " table=\"C_TABLE\"\n"+
121             ">\n"+
122             " <extent-class class-ref=\"test.E\"/>\n"+
123             "</class-descriptor>\n"+
124             "<class-descriptor\n"+
125             " class=\"test.E\"\n"+
126             " table=\"E\"\n"+
127             ">\n"+
128             "</class-descriptor>",
129             runOjbXDoclet(OJB_DEST_FILE));
130         assertEqualsTorqueSchemaFile(
131             "<database name=\"ojbtest\">\n"+
132             " <table name=\"A\">\n"+
133             " </table>\n"+
134             " <table name=\"C_TABLE\">\n"+
135             " </table>\n"+
136             " <table name=\"E\">\n"+
137             " </table>\n"+
138             "</database>",
139             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
140     }
141
142     // Test of table: multi-mapped table with two unrelated classes
143
public void testTable4()
144     {
145         addClass(
146             "test.A",
147             "package test;\n"+
148             "/** @ojb.class table=\"TABLE\" */\n"+
149             "public class A {\n"+
150             " /** @ojb.field */\n"+
151             " private int aid;\n"+
152             "}\n");
153         addClass(
154             "test.B",
155             "package test;\n"+
156             "/** @ojb.class table=\"TABLE\" */\n"+
157             "public class B {\n"+
158             " /** @ojb.field */\n"+
159             " private int bid;\n"+
160             "}\n");
161
162         assertEqualsOjbDescriptorFile(
163             "<class-descriptor\n"+
164             " class=\"test.A\"\n"+
165             " table=\"TABLE\"\n"+
166             ">\n"+
167             " <field-descriptor\n"+
168             " name=\"aid\"\n"+
169             " column=\"aid\"\n"+
170             " jdbc-type=\"INTEGER\"\n"+
171             " >\n"+
172             " </field-descriptor>\n"+
173             "</class-descriptor>\n"+
174             "<class-descriptor\n"+
175             " class=\"test.B\"\n"+
176             " table=\"TABLE\"\n"+
177             ">\n"+
178             " <field-descriptor\n"+
179             " name=\"bid\"\n"+
180             " column=\"bid\"\n"+
181             " jdbc-type=\"INTEGER\"\n"+
182             " >\n"+
183             " </field-descriptor>\n"+
184             "</class-descriptor>\n",
185             runOjbXDoclet(OJB_DEST_FILE));
186         assertEqualsTorqueSchemaFile(
187             "<database name=\"ojbtest\">\n"+
188             " <table name=\"TABLE\">\n"+
189             " <column name=\"aid\"\n"+
190             " javaName=\"aid\"\n"+
191             " type=\"INTEGER\"\n"+
192             " />\n"+
193             " <column name=\"bid\"\n"+
194             " javaName=\"bid\"\n"+
195             " type=\"INTEGER\"\n"+
196             " />\n"+
197             " </table>\n"+
198             "</database>",
199             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
200     }
201
202     // Test of table: multi-mapped table with three related classes
203
public void testTable5()
204     {
205         addClass(
206             "test.A",
207             "package test;\n"+
208             "/** @ojb.class table=\"TABLE\" */\n"+
209             "public class A {\n"+
210             " /** @ojb.field */\n"+
211             " private int aid;\n"+
212             "}\n");
213         addClass(
214             "test.B",
215             "package test;\n"+
216             "/** @ojb.class table=\"TABLE\" */\n"+
217             "public class B extends A {\n"+
218             " /** @ojb.field */\n"+
219             " private int bid;\n"+
220             "}\n");
221         addClass(
222             "test.C",
223             "package test;\n"+
224             "public class C extends A {\n"+
225             " /** @ojb.field */\n"+
226             " private int cid;\n"+
227             "}\n");
228         addClass(
229             "test.D",
230             "package test;\n"+
231             "/** @ojb.class table=\"TABLE\" */\n"+
232             "public class D extends C {\n"+
233             " /** @ojb.field */\n"+
234             " private int did;\n"+
235             "}\n");
236
237         assertEqualsOjbDescriptorFile(
238             "<class-descriptor\n"+
239             " class=\"test.A\"\n"+
240             " table=\"TABLE\"\n"+
241             ">\n"+
242             " <extent-class class-ref=\"test.B\"/>\n"+
243             " <extent-class class-ref=\"test.D\"/>\n"+
244             " <field-descriptor\n"+
245             " name=\"aid\"\n"+
246             " column=\"aid\"\n"+
247             " jdbc-type=\"INTEGER\"\n"+
248             " >\n"+
249             " </field-descriptor>\n"+
250             "</class-descriptor>\n"+
251             "<class-descriptor\n"+
252             " class=\"test.B\"\n"+
253             " table=\"TABLE\"\n"+
254             ">\n"+
255             " <field-descriptor\n"+
256             " name=\"aid\"\n"+
257             " column=\"aid\"\n"+
258             " jdbc-type=\"INTEGER\"\n"+
259             " >\n"+
260             " </field-descriptor>\n"+
261             " <field-descriptor\n"+
262             " name=\"bid\"\n"+
263             " column=\"bid\"\n"+
264             " jdbc-type=\"INTEGER\"\n"+
265             " >\n"+
266             " </field-descriptor>\n"+
267             "</class-descriptor>\n"+
268             "<class-descriptor\n"+
269             " class=\"test.D\"\n"+
270             " table=\"TABLE\"\n"+
271             ">\n"+
272             " <field-descriptor\n"+
273             " name=\"aid\"\n"+
274             " column=\"aid\"\n"+
275             " jdbc-type=\"INTEGER\"\n"+
276             " >\n"+
277             " </field-descriptor>\n"+
278             " <field-descriptor\n"+
279             " name=\"cid\"\n"+
280             " column=\"cid\"\n"+
281             " jdbc-type=\"INTEGER\"\n"+
282             " >\n"+
283             " </field-descriptor>\n"+
284             " <field-descriptor\n"+
285             " name=\"did\"\n"+
286             " column=\"did\"\n"+
287             " jdbc-type=\"INTEGER\"\n"+
288             " >\n"+
289             " </field-descriptor>\n"+
290             "</class-descriptor>\n",
291             runOjbXDoclet(OJB_DEST_FILE));
292         assertEqualsTorqueSchemaFile(
293             "<database name=\"ojbtest\">\n"+
294             " <table name=\"TABLE\">\n"+
295             " <column name=\"aid\"\n"+
296             " javaName=\"aid\"\n"+
297             " type=\"INTEGER\"\n"+
298             " />\n"+
299             " <column name=\"bid\"\n"+
300             " javaName=\"bid\"\n"+
301             " type=\"INTEGER\"\n"+
302             " />\n"+
303             " <column name=\"cid\"\n"+
304             " javaName=\"cid\"\n"+
305             " type=\"INTEGER\"\n"+
306             " />\n"+
307             " <column name=\"did\"\n"+
308             " javaName=\"did\"\n"+
309             " type=\"INTEGER\"\n"+
310             " />\n"+
311             " </table>\n"+
312             "</database>",
313             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
314     }
315
316 }
317
Popular Tags