KickJava   Java API By Example, From Geeks To Geeks.

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


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

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