KickJava   Java API By Example, From Geeks To Geeks.

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


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

23 public class FieldTagAttributesAttributeTests extends OjbTestBase
24 {
25     public FieldTagAttributesAttributeTests(String JavaDoc name)
26     {
27         super(name);
28     }
29
30     // Test: attributes attribute with no value
31
public void testAttributes1()
32     {
33         addClass(
34             "test.A",
35             "package test;\n"+
36             "/** @ojb.class */\n"+
37             "public class A {\n"+
38             "/** @ojb.field attributes=\"\" */\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: attributes attribute with one attribute pair
68
public void testAttributes2()
69     {
70         addClass(
71             "test.A",
72             "package test;\n"+
73             "/** @ojb.class */\n"+
74             "public class A {\n"+
75             "/** @ojb.field attributes=\"a=b\" */\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             " <attribute attribute-name=\"a\" attribute-value=\"b\"/>\n"+
90             " </field-descriptor>\n"+
91             "</class-descriptor>",
92             runOjbXDoclet(OJB_DEST_FILE));
93         assertEqualsTorqueSchemaFile(
94             "<database name=\"ojbtest\">\n"+
95             " <table name=\"A\">\n"+
96             " <column name=\"attr\"\n"+
97             " javaName=\"attr\"\n"+
98             " type=\"INTEGER\"\n"+
99             " />\n"+
100             " </table>\n"+
101             "</database>",
102             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
103     }
104
105     // Test: attributes attribute with one empty attribute
106
public void testAttributes3()
107     {
108         addClass(
109             "test.A",
110             "package test;\n"+
111             "/** @ojb.class */\n"+
112             "public class A {\n"+
113             "/** @ojb.field attributes=\"a=\" */\n"+
114             " private int attr;\n"+
115             "}\n");
116
117         assertEqualsOjbDescriptorFile(
118             "<class-descriptor\n"+
119             " class=\"test.A\"\n"+
120             " table=\"A\"\n"+
121             ">\n"+
122             " <field-descriptor\n"+
123             " name=\"attr\"\n"+
124             " column=\"attr\"\n"+
125             " jdbc-type=\"INTEGER\"\n"+
126             " >\n"+
127             " <attribute attribute-name=\"a\" attribute-value=\"\"/>\n"+
128             " </field-descriptor>\n"+
129             "</class-descriptor>",
130             runOjbXDoclet(OJB_DEST_FILE));
131         assertEqualsTorqueSchemaFile(
132             "<database name=\"ojbtest\">\n"+
133             " <table name=\"A\">\n"+
134             " <column name=\"attr\"\n"+
135             " javaName=\"attr\"\n"+
136             " type=\"INTEGER\"\n"+
137             " />\n"+
138             " </table>\n"+
139             "</database>",
140             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
141     }
142
143     // Test: attributes attribute with three attributes
144
public void testAttributes4()
145     {
146         addClass(
147             "test.A",
148             "package test;\n"+
149             "/** @ojb.class */\n"+
150             "public class A {\n"+
151             "/** @ojb.field attributes=\"a=b,c,d=e\" */\n"+
152             " private int attr;\n"+
153             "}\n");
154
155         assertEqualsOjbDescriptorFile(
156             "<class-descriptor\n"+
157             " class=\"test.A\"\n"+
158             " table=\"A\"\n"+
159             ">\n"+
160             " <field-descriptor\n"+
161             " name=\"attr\"\n"+
162             " column=\"attr\"\n"+
163             " jdbc-type=\"INTEGER\"\n"+
164             " >\n"+
165             " <attribute attribute-name=\"a\" attribute-value=\"b\"/>\n"+
166             " <attribute attribute-name=\"c\" attribute-value=\"\"/>\n"+
167             " <attribute attribute-name=\"d\" attribute-value=\"e\"/>\n"+
168             " </field-descriptor>\n"+
169             "</class-descriptor>",
170             runOjbXDoclet(OJB_DEST_FILE));
171         assertEqualsTorqueSchemaFile(
172             "<database name=\"ojbtest\">\n"+
173             " <table name=\"A\">\n"+
174             " <column name=\"attr\"\n"+
175             " javaName=\"attr\"\n"+
176             " type=\"INTEGER\"\n"+
177             " />\n"+
178             " </table>\n"+
179             "</database>",
180             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
181     }
182
183     // Test: inherited attributes attribute
184
public void testAttributes5()
185     {
186         addClass(
187             "test.A",
188             "package test;\n"+
189             "/** @ojb.class */\n"+
190             "public class A {\n"+
191             "/** @ojb.field attributes=\"a=b\" */\n"+
192             " private int attr;\n"+
193             "}\n");
194         addClass(
195             "test.B",
196             "package test;\n"+
197             "/** @ojb.class */\n"+
198             "public class B extends A {}\n");
199
200         assertEqualsOjbDescriptorFile(
201             "<class-descriptor\n"+
202             " class=\"test.A\"\n"+
203             " table=\"A\"\n"+
204             ">\n"+
205             " <extent-class class-ref=\"test.B\"/>\n"+
206             " <field-descriptor\n"+
207             " name=\"attr\"\n"+
208             " column=\"attr\"\n"+
209             " jdbc-type=\"INTEGER\"\n"+
210             " >\n"+
211             " <attribute attribute-name=\"a\" attribute-value=\"b\"/>\n"+
212             " </field-descriptor>\n"+
213             "</class-descriptor>\n"+
214             "<class-descriptor\n"+
215             " class=\"test.B\"\n"+
216             " table=\"B\"\n"+
217             ">\n"+
218             " <field-descriptor\n"+
219             " name=\"attr\"\n"+
220             " column=\"attr\"\n"+
221             " jdbc-type=\"INTEGER\"\n"+
222             " >\n"+
223             " <attribute attribute-name=\"a\" attribute-value=\"b\"/>\n"+
224             " </field-descriptor>\n"+
225             "</class-descriptor>",
226             runOjbXDoclet(OJB_DEST_FILE));
227         assertEqualsTorqueSchemaFile(
228             "<database name=\"ojbtest\">\n"+
229             " <table name=\"A\">\n"+
230             " <column name=\"attr\"\n"+
231             " javaName=\"attr\"\n"+
232             " type=\"INTEGER\"\n"+
233             " />\n"+
234             " </table>\n"+
235             " <table name=\"B\">\n"+
236             " <column name=\"attr\"\n"+
237             " javaName=\"attr\"\n"+
238             " type=\"INTEGER\"\n"+
239             " />\n"+
240             " </table>\n"+
241             "</database>",
242             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
243     }
244 }
245
Popular Tags