KickJava   Java API By Example, From Geeks To Geeks.

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


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

23 public class ReferenceTagDocumentationAttributeTests extends OjbTestBase
24 {
25     public ReferenceTagDocumentationAttributeTests(String JavaDoc name)
26     {
27         super(name);
28     }
29
30     // Test: documentation attribute with no value
31
public void testDocumentation1()
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 int attrKey;\n"+
40             "/** @ojb.reference foreignkey=\"attrKey\"\n"+
41             " * documentation=\"\"\n"+
42             " */\n"+
43             " private test.B attr;\n"+
44             "}\n");
45         addClass(
46             "test.B",
47             "package test;\n"+
48             "/** @ojb.class */\n"+
49             "public class B {\n"+
50             "/** @ojb.field primarykey=\"true\" */\n"+
51             " private int id;\n"+
52             "}\n");
53
54         assertEqualsOjbDescriptorFile(
55             "<class-descriptor\n"+
56             " class=\"test.A\"\n"+
57             " table=\"A\"\n"+
58             ">\n"+
59             " <field-descriptor\n"+
60             " name=\"attrKey\"\n"+
61             " column=\"attrKey\"\n"+
62             " jdbc-type=\"INTEGER\"\n"+
63             " >\n"+
64             " </field-descriptor>\n"+
65             " <reference-descriptor\n"+
66             " name=\"attr\"\n"+
67             " class-ref=\"test.B\"\n"+
68             " >\n"+
69             " <foreignkey field-ref=\"attrKey\"/>\n"+
70             " </reference-descriptor>\n"+
71             "</class-descriptor>\n"+
72             "<class-descriptor\n"+
73             " class=\"test.B\"\n"+
74             " table=\"B\"\n"+
75             ">\n"+
76             " <field-descriptor\n"+
77             " name=\"id\"\n"+
78             " column=\"id\"\n"+
79             " jdbc-type=\"INTEGER\"\n"+
80             " primarykey=\"true\"\n"+
81             " >\n"+
82             " </field-descriptor>\n"+
83             "</class-descriptor>",
84             runOjbXDoclet(OJB_DEST_FILE));
85         assertEqualsTorqueSchemaFile(
86             "<database name=\"ojbtest\">\n"+
87             " <table name=\"A\">\n"+
88             " <column name=\"attrKey\"\n"+
89             " javaName=\"attrKey\"\n"+
90             " type=\"INTEGER\"\n"+
91             " />\n"+
92             " <foreign-key foreignTable=\"B\">\n"+
93             " <reference local=\"attrKey\" foreign=\"id\"/>\n"+
94             " </foreign-key>\n"+
95             " </table>\n"+
96             " <table name=\"B\">\n"+
97             " <column name=\"id\"\n"+
98             " javaName=\"id\"\n"+
99             " type=\"INTEGER\"\n"+
100             " primaryKey=\"true\"\n"+
101             " required=\"true\"\n"+
102             " />\n"+
103             " </table>\n"+
104             "</database>",
105             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
106     }
107
108     // Test: documentation attribute with value
109
public void testDocumentation2()
110     {
111         addClass(
112             "test.A",
113             "package test;\n"+
114             "/** @ojb.class */\n"+
115             "public class A {\n"+
116             "/** @ojb.field */\n"+
117             " private int attrKey;\n"+
118             "/** @ojb.reference foreignkey=\"attrKey\"\n"+
119             " * documentation=\"Some important documentation\"\n"+
120             " */\n"+
121             " private test.B attr;\n"+
122             "}\n");
123         addClass(
124             "test.B",
125             "package test;\n"+
126             "/** @ojb.class */\n"+
127             "public class B {\n"+
128             "/** @ojb.field primarykey=\"true\" */\n"+
129             " private int id;\n"+
130             "}\n");
131
132         assertEqualsOjbDescriptorFile(
133             "<class-descriptor\n"+
134             " class=\"test.A\"\n"+
135             " table=\"A\"\n"+
136             ">\n"+
137             " <field-descriptor\n"+
138             " name=\"attrKey\"\n"+
139             " column=\"attrKey\"\n"+
140             " jdbc-type=\"INTEGER\"\n"+
141             " >\n"+
142             " </field-descriptor>\n"+
143             " <reference-descriptor\n"+
144             " name=\"attr\"\n"+
145             " class-ref=\"test.B\"\n"+
146             " >\n"+
147             " <documentation>Some important documentation</documentation>\n"+
148             " <foreignkey field-ref=\"attrKey\"/>\n"+
149             " </reference-descriptor>\n"+
150             "</class-descriptor>\n"+
151             "<class-descriptor\n"+
152             " class=\"test.B\"\n"+
153             " table=\"B\"\n"+
154             ">\n"+
155             " <field-descriptor\n"+
156             " name=\"id\"\n"+
157             " column=\"id\"\n"+
158             " jdbc-type=\"INTEGER\"\n"+
159             " primarykey=\"true\"\n"+
160             " >\n"+
161             " </field-descriptor>\n"+
162             "</class-descriptor>",
163             runOjbXDoclet(OJB_DEST_FILE));
164         assertEqualsTorqueSchemaFile(
165             "<database name=\"ojbtest\">\n"+
166             " <table name=\"A\">\n"+
167             " <column name=\"attrKey\"\n"+
168             " javaName=\"attrKey\"\n"+
169             " type=\"INTEGER\"\n"+
170             " />\n"+
171             " <foreign-key foreignTable=\"B\">\n"+
172             " <reference local=\"attrKey\" foreign=\"id\"/>\n"+
173             " </foreign-key>\n"+
174             " </table>\n"+
175             " <table name=\"B\">\n"+
176             " <column name=\"id\"\n"+
177             " javaName=\"id\"\n"+
178             " type=\"INTEGER\"\n"+
179             " primaryKey=\"true\"\n"+
180             " required=\"true\"\n"+
181             " />\n"+
182             " </table>\n"+
183             "</database>",
184             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
185     }
186
187     // Test: inherited documentation attribute with value
188
public void testDocumentation3()
189     {
190         addClass(
191             "test.A",
192             "package test;\n"+
193             "/** @ojb.class */\n"+
194             "public class A {\n"+
195             "/** @ojb.field */\n"+
196             " private int attrKey;\n"+
197             "/** @ojb.reference foreignkey=\"attrKey\"\n"+
198             " * documentation=\"Some really important documentation\"\n"+
199             " */\n"+
200             " private test.B attr;\n"+
201             "}\n");
202         addClass(
203             "test.B",
204             "package test;\n"+
205             "/** @ojb.class */\n"+
206             "public class B {\n"+
207             "/** @ojb.field primarykey=\"true\" */\n"+
208             " private int id;\n"+
209             "}\n");
210         addClass(
211             "test.C",
212             "package test;\n"+
213             "/** @ojb.class */\n"+
214             "public class C extends A {}\n");
215
216         assertEqualsOjbDescriptorFile(
217             "<class-descriptor\n"+
218             " class=\"test.A\"\n"+
219             " table=\"A\"\n"+
220             ">\n"+
221             " <extent-class class-ref=\"test.C\"/>\n"+
222             " <field-descriptor\n"+
223             " name=\"attrKey\"\n"+
224             " column=\"attrKey\"\n"+
225             " jdbc-type=\"INTEGER\"\n"+
226             " >\n"+
227             " </field-descriptor>\n"+
228             " <reference-descriptor\n"+
229             " name=\"attr\"\n"+
230             " class-ref=\"test.B\"\n"+
231             " >\n"+
232             " <documentation>Some really important documentation</documentation>\n"+
233             " <foreignkey field-ref=\"attrKey\"/>\n"+
234             " </reference-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=\"id\"\n"+
242             " column=\"id\"\n"+
243             " jdbc-type=\"INTEGER\"\n"+
244             " primarykey=\"true\"\n"+
245             " >\n"+
246             " </field-descriptor>\n"+
247             "</class-descriptor>\n"+
248             "<class-descriptor\n"+
249             " class=\"test.C\"\n"+
250             " table=\"C\"\n"+
251             ">\n"+
252             " <field-descriptor\n"+
253             " name=\"attrKey\"\n"+
254             " column=\"attrKey\"\n"+
255             " jdbc-type=\"INTEGER\"\n"+
256             " >\n"+
257             " </field-descriptor>\n"+
258             " <reference-descriptor\n"+
259             " name=\"attr\"\n"+
260             " class-ref=\"test.B\"\n"+
261             " >\n"+
262             " <documentation>Some really important documentation</documentation>\n"+
263             " <foreignkey field-ref=\"attrKey\"/>\n"+
264             " </reference-descriptor>\n"+
265             "</class-descriptor>\n",
266             runOjbXDoclet(OJB_DEST_FILE));
267         assertEqualsTorqueSchemaFile(
268             "<database name=\"ojbtest\">\n"+
269             " <table name=\"A\">\n"+
270             " <column name=\"attrKey\"\n"+
271             " javaName=\"attrKey\"\n"+
272             " type=\"INTEGER\"\n"+
273             " />\n"+
274             " <foreign-key foreignTable=\"B\">\n"+
275             " <reference local=\"attrKey\" foreign=\"id\"/>\n"+
276             " </foreign-key>\n"+
277             " </table>\n"+
278             " <table name=\"B\">\n"+
279             " <column name=\"id\"\n"+
280             " javaName=\"id\"\n"+
281             " type=\"INTEGER\"\n"+
282             " primaryKey=\"true\"\n"+
283             " required=\"true\"\n"+
284             " />\n"+
285             " </table>\n"+
286             " <table name=\"C\">\n"+
287             " <column name=\"attrKey\"\n"+
288             " javaName=\"attrKey\"\n"+
289             " type=\"INTEGER\"\n"+
290             " />\n"+
291             " <foreign-key foreignTable=\"B\">\n"+
292             " <reference local=\"attrKey\" foreign=\"id\"/>\n"+
293             " </foreign-key>\n"+
294             " </table>\n"+
295             "</database>",
296             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
297     }
298 }
299
Popular Tags