KickJava   Java API By Example, From Geeks To Geeks.

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


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