KickJava   Java API By Example, From Geeks To Geeks.

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


1 package xdoclet.modules.ojb.tests;
2
3 /* Copyright 2002-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 length attribute.
20  * Note that the XDoclet OJB module does not check the value of length
21  * because it may be database dependent what can be put in there.
22  *
23  * @author <a HREF="mailto:tomdz@users.sourceforge.net">Thomas Dudziak (tomdz@users.sourceforge.net)</a>
24  */

25 public class ModifyInheritedTagLengthAttributeTests extends OjbTestBase
26 {
27     public ModifyInheritedTagLengthAttributeTests(String JavaDoc name)
28     {
29         super(name);
30     }
31
32     // Test: removing length attribute of inherited field that has jdbc type without length
33
// Note that the XDoclet OJB module does not check whether the jdbc type really supports a length
34
public void testLength1()
35     {
36         addClass(
37             "test.A",
38             "package test;\n"+
39             "/** @ojb.class */\n"+
40             "public class A {\n"+
41             "/** @ojb.field length=\"32\" */\n"+
42             " private int attr;\n"+
43             "}\n");
44         addClass(
45             "test.B",
46             "package test;\n"+
47             "/** @ojb.class\n"+
48             " * @ojb.modify-inherited name=\"attr\"\n"+
49             " * length=\"\"\n"+
50             " */\n"+
51             "public class B extends A {}\n");
52
53         assertEqualsOjbDescriptorFile(
54             "<class-descriptor\n"+
55             " class=\"test.A\"\n"+
56             " table=\"A\"\n"+
57             ">\n"+
58             " <extent-class class-ref=\"test.B\"/>\n"+
59             " <field-descriptor\n"+
60             " name=\"attr\"\n"+
61             " column=\"attr\"\n"+
62             " jdbc-type=\"INTEGER\"\n"+
63             " length=\"32\"\n"+
64             " >\n"+
65             " </field-descriptor>\n"+
66             "</class-descriptor>\n"+
67             "<class-descriptor\n"+
68             " class=\"test.B\"\n"+
69             " table=\"B\"\n"+
70             ">\n"+
71             " <field-descriptor\n"+
72             " name=\"attr\"\n"+
73             " column=\"attr\"\n"+
74             " jdbc-type=\"INTEGER\"\n"+
75             " >\n"+
76             " </field-descriptor>\n"+
77             "</class-descriptor>",
78             runOjbXDoclet(OJB_DEST_FILE));
79         assertEqualsTorqueSchemaFile(
80             "<database name=\"ojbtest\">\n"+
81             " <table name=\"A\">\n"+
82             " <column name=\"attr\"\n"+
83             " javaName=\"attr\"\n"+
84             " type=\"INTEGER\"\n"+
85             " size=\"32\"\n"+
86             " />\n"+
87             " </table>\n"+
88             " <table name=\"B\">\n"+
89             " <column name=\"attr\"\n"+
90             " javaName=\"attr\"\n"+
91             " type=\"INTEGER\"\n"+
92             " />\n"+
93             " </table>\n"+
94             "</database>",
95             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
96     }
97
98     // Test: removing length attribute of inherited field that has jdbc type with default length
99
public void testLength2()
100     {
101         addClass(
102             "test.A",
103             "package test;\n"+
104             "/** @ojb.class */\n"+
105             "public class A {\n"+
106             "/** @ojb.field length=\"32\" */\n"+
107             " private String attr;\n"+
108             "}\n");
109         addClass(
110             "test.B",
111             "package test;\n"+
112             "/** @ojb.class\n"+
113             " * @ojb.modify-inherited name=\"attr\"\n"+
114             " * length=\"\"\n"+
115             " */\n"+
116             "public class B extends A {}\n");
117
118         assertEqualsOjbDescriptorFile(
119             "<class-descriptor\n"+
120             " class=\"test.A\"\n"+
121             " table=\"A\"\n"+
122             ">\n"+
123             " <extent-class class-ref=\"test.B\"/>\n"+
124             " <field-descriptor\n"+
125             " name=\"attr\"\n"+
126             " column=\"attr\"\n"+
127             " jdbc-type=\"VARCHAR\"\n"+
128             " length=\"32\"\n"+
129             " >\n"+
130             " </field-descriptor>\n"+
131             "</class-descriptor>\n"+
132             "<class-descriptor\n"+
133             " class=\"test.B\"\n"+
134             " table=\"B\"\n"+
135             ">\n"+
136             " <field-descriptor\n"+
137             " name=\"attr\"\n"+
138             " column=\"attr\"\n"+
139             " jdbc-type=\"VARCHAR\"\n"+
140             " length=\"254\"\n"+
141             " >\n"+
142             " </field-descriptor>\n"+
143             "</class-descriptor>",
144             runOjbXDoclet(OJB_DEST_FILE));
145         assertEqualsTorqueSchemaFile(
146             "<database name=\"ojbtest\">\n"+
147             " <table name=\"A\">\n"+
148             " <column name=\"attr\"\n"+
149             " javaName=\"attr\"\n"+
150             " type=\"VARCHAR\"\n"+
151             " size=\"32\"\n"+
152             " />\n"+
153             " </table>\n"+
154             " <table name=\"B\">\n"+
155             " <column name=\"attr\"\n"+
156             " javaName=\"attr\"\n"+
157             " type=\"VARCHAR\"\n"+
158             " size=\"254\"\n"+
159             " />\n"+
160             " </table>\n"+
161             "</database>",
162             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
163     }
164
165     // Test: setting length attribute of remotely inherited field that has jdbc type with default length
166
public void testLength3()
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 String attr;\n"+
175             "}\n");
176         addClass(
177             "test.B",
178             "package test;\n"+
179             "public class B extends A {}\n");
180         addClass(
181             "test.C",
182             "package test;\n"+
183             "/** @ojb.class\n"+
184             " * @ojb.modify-inherited name=\"attr\"\n"+
185             " * length=\"32\"\n"+
186             " */\n"+
187             "public class C extends B {}\n");
188
189         assertEqualsOjbDescriptorFile(
190             "<class-descriptor\n"+
191             " class=\"test.A\"\n"+
192             " table=\"A\"\n"+
193             ">\n"+
194             " <extent-class class-ref=\"test.C\"/>\n"+
195             " <field-descriptor\n"+
196             " name=\"attr\"\n"+
197             " column=\"attr\"\n"+
198             " jdbc-type=\"VARCHAR\"\n"+
199             " length=\"254\"\n"+
200             " >\n"+
201             " </field-descriptor>\n"+
202             "</class-descriptor>\n"+
203             "<class-descriptor\n"+
204             " class=\"test.C\"\n"+
205             " table=\"C\"\n"+
206             ">\n"+
207             " <field-descriptor\n"+
208             " name=\"attr\"\n"+
209             " column=\"attr\"\n"+
210             " jdbc-type=\"VARCHAR\"\n"+
211             " length=\"32\"\n"+
212             " >\n"+
213             " </field-descriptor>\n"+
214             "</class-descriptor>",
215             runOjbXDoclet(OJB_DEST_FILE));
216         assertEqualsTorqueSchemaFile(
217             "<database name=\"ojbtest\">\n"+
218             " <table name=\"A\">\n"+
219             " <column name=\"attr\"\n"+
220             " javaName=\"attr\"\n"+
221             " type=\"VARCHAR\"\n"+
222             " size=\"254\"\n"+
223             " />\n"+
224             " </table>\n"+
225             " <table name=\"C\">\n"+
226             " <column name=\"attr\"\n"+
227             " javaName=\"attr\"\n"+
228             " type=\"VARCHAR\"\n"+
229             " size=\"32\"\n"+
230             " />\n"+
231             " </table>\n"+
232             "</database>",
233             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
234     }
235
236     // Test: changing length attribute of inherited field that has jdbc type without length
237
// Note that the XDoclet OJB module does not check whether the jdbc type really supports a length
238
public void testLength4()
239     {
240         addClass(
241             "test.A",
242             "package test;\n"+
243             "/** @ojb.class */\n"+
244             "public class A {\n"+
245             "/** @ojb.field length=\"32\" */\n"+
246             " private int attr;\n"+
247             "}\n");
248         addClass(
249             "test.B",
250             "package test;\n"+
251             "/** @ojb.class\n"+
252             " * @ojb.modify-inherited name=\"attr\"\n"+
253             " * length=\"16\"\n"+
254             " */\n"+
255             "public class B extends A {}\n");
256
257         assertEqualsOjbDescriptorFile(
258             "<class-descriptor\n"+
259             " class=\"test.A\"\n"+
260             " table=\"A\"\n"+
261             ">\n"+
262             " <extent-class class-ref=\"test.B\"/>\n"+
263             " <field-descriptor\n"+
264             " name=\"attr\"\n"+
265             " column=\"attr\"\n"+
266             " jdbc-type=\"INTEGER\"\n"+
267             " length=\"32\"\n"+
268             " >\n"+
269             " </field-descriptor>\n"+
270             "</class-descriptor>\n"+
271             "<class-descriptor\n"+
272             " class=\"test.B\"\n"+
273             " table=\"B\"\n"+
274             ">\n"+
275             " <field-descriptor\n"+
276             " name=\"attr\"\n"+
277             " column=\"attr\"\n"+
278             " jdbc-type=\"INTEGER\"\n"+
279             " length=\"16\"\n"+
280             " >\n"+
281             " </field-descriptor>\n"+
282             "</class-descriptor>",
283             runOjbXDoclet(OJB_DEST_FILE));
284         assertEqualsTorqueSchemaFile(
285             "<database name=\"ojbtest\">\n"+
286             " <table name=\"A\">\n"+
287             " <column name=\"attr\"\n"+
288             " javaName=\"attr\"\n"+
289             " type=\"INTEGER\"\n"+
290             " size=\"32\"\n"+
291             " />\n"+
292             " </table>\n"+
293             " <table name=\"B\">\n"+
294             " <column name=\"attr\"\n"+
295             " javaName=\"attr\"\n"+
296             " type=\"INTEGER\"\n"+
297             " size=\"16\"\n"+
298             " />\n"+
299             " </table>\n"+
300             "</database>",
301             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
302     }
303 }
304
Popular Tags