KickJava   Java API By Example, From Geeks To Geeks.

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


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

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