KickJava   Java API By Example, From Geeks To Geeks.

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


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

23 public class FieldTagColumnDocumentationAttributeTests extends OjbTestBase
24 {
25     public FieldTagColumnDocumentationAttributeTests(String JavaDoc name)
26     {
27         super(name);
28     }
29
30     // Test: column-documentation attribute with no value
31
public void testColumnDocumentation1()
32     {
33         addClass(
34             "test.A",
35             "package test;\n"+
36             "/** @ojb.class */\n"+
37             "public class A {\n"+
38             "/** @ojb.field column-documentation=\"\" */\n"+
39             " private int attr;\n"+
40             "}\n");
41
42         assertEqualsOjbDescriptorFile(
43             "<class-descriptor\n"+
44             " class=\"test.A\"\n"+
45             " table=\"A\"\n"+
46             ">\n"+
47             " <field-descriptor\n"+
48             " name=\"attr\"\n"+
49             " column=\"attr\"\n"+
50             " jdbc-type=\"INTEGER\"\n"+
51             " >\n"+
52             " </field-descriptor>\n"+
53             "</class-descriptor>",
54             runOjbXDoclet(OJB_DEST_FILE));
55         assertEqualsTorqueSchemaFile(
56             "<database name=\"ojbtest\">\n"+
57             " <table name=\"A\">\n"+
58             " <column name=\"attr\"\n"+
59             " javaName=\"attr\"\n"+
60             " type=\"INTEGER\"\n"+
61             " />\n"+
62             " </table>\n"+
63             "</database>",
64             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
65     }
66
67     // Test: column-documentation attribute with value
68
public void testColumnDocumentation2()
69     {
70         addClass(
71             "test.A",
72             "package test;\n"+
73             "/** @ojb.class */\n"+
74             "public class A {\n"+
75             "/** @ojb.field column-documentation=\"Some documentation\" */\n"+
76             " private int attr;\n"+
77             "}\n");
78
79         assertEqualsOjbDescriptorFile(
80             "<class-descriptor\n"+
81             " class=\"test.A\"\n"+
82             " table=\"A\"\n"+
83             ">\n"+
84             " <field-descriptor\n"+
85             " name=\"attr\"\n"+
86             " column=\"attr\"\n"+
87             " jdbc-type=\"INTEGER\"\n"+
88             " >\n"+
89             " </field-descriptor>\n"+
90             "</class-descriptor>",
91             runOjbXDoclet(OJB_DEST_FILE));
92         assertEqualsTorqueSchemaFile(
93             "<database name=\"ojbtest\">\n"+
94             " <table name=\"A\">\n"+
95             " <column name=\"attr\"\n"+
96             " javaName=\"attr\"\n"+
97             " type=\"INTEGER\"\n"+
98             " description=\"Some documentation\""+
99             " />\n"+
100             " </table>\n"+
101             "</database>",
102             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
103     }
104
105     // Test: inherited column-documentation attribute with value
106
public void testColumnDocumentation3()
107     {
108         addClass(
109             "test.A",
110             "package test;\n"+
111             "/** @ojb.class */\n"+
112             "public class A {\n"+
113             "/** @ojb.field column-documentation=\"Some documentation\" */\n"+
114             " private int attr;\n"+
115             "}\n");
116         addClass(
117             "test.B",
118             "package test;\n"+
119             "/** @ojb.class */\n"+
120             "public class B extends A {}\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.B\"/>\n"+
128             " <field-descriptor\n"+
129             " name=\"attr\"\n"+
130             " column=\"attr\"\n"+
131             " jdbc-type=\"INTEGER\"\n"+
132             " >\n"+
133             " </field-descriptor>\n"+
134             "</class-descriptor>\n"+
135             "<class-descriptor\n"+
136             " class=\"test.B\"\n"+
137             " table=\"B\"\n"+
138             ">\n"+
139             " <field-descriptor\n"+
140             " name=\"attr\"\n"+
141             " column=\"attr\"\n"+
142             " jdbc-type=\"INTEGER\"\n"+
143             " >\n"+
144             " </field-descriptor>\n"+
145             "</class-descriptor>",
146             runOjbXDoclet(OJB_DEST_FILE));
147         assertEqualsTorqueSchemaFile(
148             "<database name=\"ojbtest\">\n"+
149             " <table name=\"A\">\n"+
150             " <column name=\"attr\"\n"+
151             " javaName=\"attr\"\n"+
152             " type=\"INTEGER\"\n"+
153             " description=\"Some documentation\""+
154             " />\n"+
155             " </table>\n"+
156             " <table name=\"B\">\n"+
157             " <column name=\"attr\"\n"+
158             " javaName=\"attr\"\n"+
159             " type=\"INTEGER\"\n"+
160             " description=\"Some documentation\""+
161             " />\n"+
162             " </table>\n"+
163             "</database>",
164             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
165     }
166
167     // Test: documentation attributes with value
168
public void testColumnDocumentation4()
169     {
170         addClass(
171             "test.A",
172             "package test;\n"+
173             "/** @ojb.class */\n"+
174             "public class A {\n"+
175             "/** @ojb.field documentation=\"Some other documentation\"\n"+
176             " * column-documentation=\"Some documentation\"\n"+
177             " */\n"+
178             " private int attr;\n"+
179             "}\n");
180
181         assertEqualsOjbDescriptorFile(
182             "<class-descriptor\n"+
183             " class=\"test.A\"\n"+
184             " table=\"A\"\n"+
185             ">\n"+
186             " <field-descriptor\n"+
187             " name=\"attr\"\n"+
188             " column=\"attr\"\n"+
189             " jdbc-type=\"INTEGER\"\n"+
190             " >\n"+
191             " <documentation>Some other documentation</documentation>\n"+
192             " </field-descriptor>\n"+
193             "</class-descriptor>",
194             runOjbXDoclet(OJB_DEST_FILE));
195         assertEqualsTorqueSchemaFile(
196             "<database name=\"ojbtest\">\n"+
197             " <table name=\"A\">\n"+
198             " <column name=\"attr\"\n"+
199             " javaName=\"attr\"\n"+
200             " type=\"INTEGER\"\n"+
201             " description=\"Some documentation\""+
202             " />\n"+
203             " </table>\n"+
204             "</database>",
205             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
206     }
207
208     // Test: two different classes map to the same table
209
public void testColumnDocumentation5()
210     {
211         addClass(
212             "test.A",
213             "package test;\n"+
214             "/** @ojb.class */\n"+
215             "public class A {\n"+
216             "/** @ojb.field column-documentation=\"Some documentation\" */\n"+
217             " private int attr;\n"+
218             "}\n");
219         addClass(
220             "test.B",
221             "package test;\n"+
222             "/** @ojb.class table=\"A\" */\n"+
223             "public class B {\n"+
224             "/** @ojb.field documentation=\"Some other documentation\" */\n"+
225             " private int attr;\n"+
226             "}\n");
227
228         assertEqualsOjbDescriptorFile(
229             "<class-descriptor\n"+
230             " class=\"test.A\"\n"+
231             " table=\"A\"\n"+
232             ">\n"+
233             " <field-descriptor\n"+
234             " name=\"attr\"\n"+
235             " column=\"attr\"\n"+
236             " jdbc-type=\"INTEGER\"\n"+
237             " >\n"+
238             " </field-descriptor>\n"+
239             "</class-descriptor>\n"+
240             "<class-descriptor\n"+
241             " class=\"test.B\"\n"+
242             " table=\"A\"\n"+
243             ">\n"+
244             " <field-descriptor\n"+
245             " name=\"attr\"\n"+
246             " column=\"attr\"\n"+
247             " jdbc-type=\"INTEGER\"\n"+
248             " >\n"+
249             " <documentation>Some other documentation</documentation>\n"+
250             " </field-descriptor>\n"+
251             "</class-descriptor>",
252             runOjbXDoclet(OJB_DEST_FILE));
253         assertEqualsTorqueSchemaFile(
254             "<database name=\"ojbtest\">\n"+
255             " <table name=\"A\">\n"+
256             " <column name=\"attr\"\n"+
257             " javaName=\"attr\"\n"+
258             " type=\"INTEGER\"\n"+
259             " description=\"Some documentation\""+
260             " />\n"+
261             " </table>\n"+
262             "</database>",
263             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
264     }
265 }
266
Popular Tags