KickJava   Java API By Example, From Geeks To Geeks.

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


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

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