KickJava   Java API By Example, From Geeks To Geeks.

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


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