KickJava   Java API By Example, From Geeks To Geeks.

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


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.field tag placed in the class javadoc comment.
20  *
21  * @author <a HREF="mailto:tomdz@apache.org">Thomas Dudziak</a>
22  */

23 public class AnonymousFieldTagTests extends OjbTestBase
24 {
25     public AnonymousFieldTagTests(String JavaDoc name)
26     {
27         super(name);
28     }
29
30     /**
31      * Test: no sub- or baseclass
32      */

33     public void testSimple1()
34     {
35         addClass(
36             "test.A",
37             "package test;\n"+
38             "/** @ojb.class\n" +
39             " * @ojb.field name=\"attr\"\n"+
40             " * jdbc-type=\"INTEGER\"\n"+
41             " */\n"+
42             "public class A {}\n");
43
44         assertEqualsOjbDescriptorFile(
45             "<class-descriptor\n"+
46             " class=\"test.A\"\n"+
47             " table=\"A\"\n"+
48             ">\n"+
49             " <field-descriptor\n"+
50             " name=\"attr\"\n"+
51             " column=\"attr\"\n"+
52             " jdbc-type=\"INTEGER\"\n"+
53             " access=\"anonymous\"\n"+
54             " >\n"+
55             " </field-descriptor>\n"+
56             "</class-descriptor>",
57             runOjbXDoclet(OJB_DEST_FILE));
58         assertEqualsTorqueSchemaFile(
59             "<database name=\"ojbtest\">\n"+
60             " <table name=\"A\">\n"+
61             " <column name=\"attr\"\n"+
62             " javaName=\"attr\"\n"+
63             " type=\"INTEGER\"\n"+
64             " />\n"+
65             " </table>\n"+
66             "</database>",
67             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
68     }
69
70     /**
71      * Test: in non-persistent class with a persistent subclass
72      */

73     public void testSimple2()
74     {
75         addClass(
76             "test.A",
77             "package test;\n"+
78             "/** @ojb.field name=\"attr\"\n"+
79             " * jdbc-type=\"INTEGER\""+
80             " */\n"+
81             "public class A {}\n");
82         addClass(
83             "test.B",
84             "package test;\n"+
85             "/** @ojb.class */\n"+
86             "public class B extends A {}\n");
87
88         assertEqualsOjbDescriptorFile(
89             "<class-descriptor\n"+
90             " class=\"test.B\"\n"+
91             " table=\"B\"\n"+
92             ">\n"+
93             " <field-descriptor\n"+
94             " name=\"attr\"\n"+
95             " column=\"attr\"\n"+
96             " jdbc-type=\"INTEGER\"\n"+
97             " access=\"anonymous\"\n"+
98             " >\n"+
99             " </field-descriptor>\n"+
100             "</class-descriptor>",
101             runOjbXDoclet(OJB_DEST_FILE));
102         assertEqualsTorqueSchemaFile(
103             "<database name=\"ojbtest\">\n"+
104             " <table name=\"B\">\n"+
105             " <column name=\"attr\"\n"+
106             " javaName=\"attr\"\n"+
107             " type=\"INTEGER\"\n"+
108             " />\n"+
109             " </table>\n"+
110             "</database>",
111             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
112     }
113
114     /**
115      * Test: persistent inherited field has same name
116      */

117     public void testSimple3()
118     {
119         addClass(
120             "test.A",
121             "package test;\n"+
122             "/** @ojb.class */\n"+
123             "public class A {\n"+
124             " /** @ojb.field */\n"+
125             " private int attr;\n"+
126             "}\n");
127         addClass(
128             "test.B",
129             "package test;\n"+
130             "/** @ojb.class\n" +
131             " * @ojb.field name=\"attr\"\n"+
132             " * jdbc-type=\"INTEGER\""+
133             " */\n"+
134             "public class B extends A {}\n");
135
136         assertNull(runOjbXDoclet(OJB_DEST_FILE));
137         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
138     }
139
140     /**
141      * Test: persistent collection in subclass has same name
142      */

143     public void testSimple4()
144     {
145         addClass(
146             "test.A",
147             "package test;\n"+
148             "/** @ojb.class\n" +
149             " * @ojb.field name=\"attr\"\n"+
150             " * jdbc-type=\"INTEGER\""+
151             " */\n"+
152             "public class A {\n"+
153             " /** @ojb.field primarykey=\"true\" */\n"+
154             " private int id;\n"+
155             "}\n");
156         addClass(
157             "test.B",
158             "package test;\n"+
159             "/** @ojb.class */\n" +
160             "public class B extends A {\n"+
161             " /** @ojb.collection element-class-ref=\"test.C\"\n"+
162             " * foreignkey=\"aid\"\n"+
163             " */\n"+
164             " private java.util.List attr;\n"+
165             "}");
166         addClass(
167             "test.C",
168             "package test;\n"+
169             "/** @ojb.class */\n"+
170             "public class C {\n"+
171             " /** @ojb.field */\n"+
172             " private int aid;\n"+
173             "}\n");
174
175         assertNull(runOjbXDoclet(OJB_DEST_FILE));
176         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
177     }
178
179     /**
180      * Test: two anonymous fields with the same name
181      */

182     public void testSimple5()
183     {
184         addClass(
185             "test.A",
186             "package test;\n"+
187             "/** @ojb.class\n" +
188             " * @ojb.field name=\"attr\"\n"+
189             " * jdbc-type=\"INTEGER\""+
190             " * @ojb.field name=\"attr\"\n"+
191             " * jdbc-type=\"VARCHAR\""+
192             " */\n"+
193             "public class A {}\n");
194
195         assertEqualsOjbDescriptorFile(
196             "<class-descriptor\n"+
197             " class=\"test.A\"\n"+
198             " table=\"A\"\n"+
199             ">\n"+
200             " <field-descriptor\n"+
201             " name=\"attr\"\n"+
202             " column=\"attr\"\n"+
203             " jdbc-type=\"INTEGER\"\n"+
204             " access=\"anonymous\"\n"+
205             " >\n"+
206             " </field-descriptor>\n"+
207             "</class-descriptor>",
208             runOjbXDoclet(OJB_DEST_FILE));
209         assertEqualsTorqueSchemaFile(
210             "<database name=\"ojbtest\">\n"+
211             " <table name=\"A\">\n"+
212             " <column name=\"attr\"\n"+
213             " javaName=\"attr\"\n"+
214             " type=\"INTEGER\"\n"+
215             " />\n"+
216             " </table>\n"+
217             "</database>",
218             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
219     }
220
221     /**
222      * Test: anonymous field in a remote base class with the same name
223      */

224     public void testSimple6()
225     {
226         addClass(
227             "test.A",
228             "package test;\n"+
229             "/** @ojb.class\n" +
230             " * @ojb.field name=\"attr\"\n"+
231             " * jdbc-type=\"INTEGER\""+
232             " */\n"+
233             "public class A {}\n");
234         addClass(
235             "test.B",
236             "package test;\n"+
237             "public class B extends A {}\n");
238         addClass(
239             "test.C",
240             "package test;\n"+
241             "/** @ojb.class\n" +
242             " * @ojb.field name=\"attr\"\n"+
243             " * jdbc-type=\"VARCHAR\""+
244             " */\n"+
245             "public class C extends B {}\n");
246
247         assertNull(runOjbXDoclet(OJB_DEST_FILE));
248         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
249     }
250
251     /**
252      * Test: missing name attribute
253      */

254     public void testSimple7()
255     {
256         addClass(
257             "test.A",
258             "package test;\n"+
259             "/** @ojb.class\n" +
260             " * @ojb.field column=\"attr\"\n"+
261             " * jdbc-type=\"INTEGER\""+
262             " */\n"+
263             "public class A {}\n");
264
265         assertNull(runOjbXDoclet(OJB_DEST_FILE));
266         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
267     }
268
269     /**
270      * Test: empty name attribute
271      */

272     public void testSimple8()
273     {
274         addClass(
275             "test.A",
276             "package test;\n"+
277             "/** @ojb.class\n" +
278             " * @ojb.field name=\"\"\n"+
279             " * jdbc-type=\"INTEGER\""+
280             " */\n"+
281             "public class A {}\n");
282
283         assertNull(runOjbXDoclet(OJB_DEST_FILE));
284         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
285     }
286
287     /**
288      * Test: there exists a persistent field with same name
289      */

290     public void testSimple9()
291     {
292         addClass(
293             "test.A",
294             "package test;\n"+
295             "/** @ojb.class\n" +
296             " * @ojb.field name=\"attr\"\n"+
297             " * jdbc-type=\"INTEGER\""+
298             " */\n"+
299             "public class A {\n"+
300             " /** @ojb.field */\n"+
301             " private int attr;\n"+
302             "}\n");
303
304         assertNull(runOjbXDoclet(OJB_DEST_FILE));
305         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
306     }
307 }
308
Popular Tags