KickJava   Java API By Example, From Geeks To Geeks.

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


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

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