KickJava   Java API By Example, From Geeks To Geeks.

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


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

23 public class FieldTagNullableAttributeTests extends OjbTestBase
24 {
25     public FieldTagNullableAttributeTests(String JavaDoc name)
26     {
27         super(name);
28     }
29
30     // Test: nullable attribute with no value
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 nullable=\"\" */\n"+
39             " private int attr;\n"+
40             "}\n");
41
42         assertNull(runOjbXDoclet(OJB_DEST_FILE));
43         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
44     }
45
46     // Test: nullable attribute with invalid value
47
public void testNullable2()
48     {
49         addClass(
50             "test.A",
51             "package test;\n"+
52             "/** @ojb.class */\n"+
53             "public class A {\n"+
54             "/** @ojb.field nullable=\"yes\" */\n"+
55             " private int attr;\n"+
56             "}\n");
57
58         assertNull(runOjbXDoclet(OJB_DEST_FILE));
59         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
60     }
61
62     // Test: nullable attribute with 'true' value
63
public void testNullable3()
64     {
65         addClass(
66             "test.A",
67             "package test;\n"+
68             "/** @ojb.class */\n"+
69             "public class A {\n"+
70             "/** @ojb.field nullable=\"true\"\n"+
71             " */\n"+
72             " private int attr;\n"+
73             "}\n");
74
75         assertEqualsOjbDescriptorFile(
76             "<class-descriptor\n"+
77             " class=\"test.A\"\n"+
78             " table=\"A\"\n"+
79             ">\n"+
80             " <field-descriptor\n"+
81             " name=\"attr\"\n"+
82             " column=\"attr\"\n"+
83             " jdbc-type=\"INTEGER\"\n"+
84             " nullable=\"true\"\n"+
85             " >\n"+
86             " </field-descriptor>\n"+
87             "</class-descriptor>",
88             runOjbXDoclet(OJB_DEST_FILE));
89         assertEqualsTorqueSchemaFile(
90             "<database name=\"ojbtest\">\n"+
91             " <table name=\"A\">\n"+
92             " <column name=\"attr\"\n"+
93             " javaName=\"attr\"\n"+
94             " type=\"INTEGER\"\n"+
95             " />\n"+
96             " </table>\n"+
97             "</database>",
98             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
99     }
100
101     // Test: nullable attribute with 'false' value
102
public void testNullable4()
103     {
104         addClass(
105             "test.A",
106             "package test;\n"+
107             "/** @ojb.class */\n"+
108             "public class A {\n"+
109             "/** @ojb.field nullable=\"false\" */\n"+
110             " private int attr;\n"+
111             "}\n");
112
113         assertEqualsOjbDescriptorFile(
114             "<class-descriptor\n"+
115             " class=\"test.A\"\n"+
116             " table=\"A\"\n"+
117             ">\n"+
118             " <field-descriptor\n"+
119             " name=\"attr\"\n"+
120             " column=\"attr\"\n"+
121             " jdbc-type=\"INTEGER\"\n"+
122             " nullable=\"false\"\n"+
123             " >\n"+
124             " </field-descriptor>\n"+
125             "</class-descriptor>",
126             runOjbXDoclet(OJB_DEST_FILE));
127         assertEqualsTorqueSchemaFile(
128             "<database name=\"ojbtest\">\n"+
129             " <table name=\"A\">\n"+
130             " <column name=\"attr\"\n"+
131             " javaName=\"attr\"\n"+
132             " type=\"INTEGER\"\n"+
133             " required=\"true\"\n"+
134             " />\n"+
135             " </table>\n"+
136             "</database>",
137             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
138     }
139
140     // Test: inherited nullable attribute with 'false' value
141
public void testNullable5()
142     {
143         addClass(
144             "test.A",
145             "package test;\n"+
146             "/** @ojb.class */\n"+
147             "public class A {\n"+
148             "/** @ojb.field nullable=\"false\" */\n"+
149             " private int attr;\n"+
150             "}\n");
151         addClass(
152             "test.B",
153             "package test;\n"+
154             "public class B extends A {}\n");
155         addClass(
156             "test.C",
157             "package test;\n"+
158             "/** @ojb.class */\n"+
159             "public class C extends B {}\n");
160
161         assertEqualsOjbDescriptorFile(
162             "<class-descriptor\n"+
163             " class=\"test.A\"\n"+
164             " table=\"A\"\n"+
165             ">\n"+
166             " <extent-class class-ref=\"test.C\"/>\n"+
167             " <field-descriptor\n"+
168             " name=\"attr\"\n"+
169             " column=\"attr\"\n"+
170             " jdbc-type=\"INTEGER\"\n"+
171             " nullable=\"false\"\n"+
172             " >\n"+
173             " </field-descriptor>\n"+
174             "</class-descriptor>\n"+
175             "<class-descriptor\n"+
176             " class=\"test.C\"\n"+
177             " table=\"C\"\n"+
178             ">\n"+
179             " <field-descriptor\n"+
180             " name=\"attr\"\n"+
181             " column=\"attr\"\n"+
182             " jdbc-type=\"INTEGER\"\n"+
183             " nullable=\"false\"\n"+
184             " >\n"+
185             " </field-descriptor>\n"+
186             "</class-descriptor>",
187             runOjbXDoclet(OJB_DEST_FILE));
188         assertEqualsTorqueSchemaFile(
189             "<database name=\"ojbtest\">\n"+
190             " <table name=\"A\">\n"+
191             " <column name=\"attr\"\n"+
192             " javaName=\"attr\"\n"+
193             " type=\"INTEGER\"\n"+
194             " required=\"true\"\n"+
195             " />\n"+
196             " </table>\n"+
197             " <table name=\"C\">\n"+
198             " <column name=\"attr\"\n"+
199             " javaName=\"attr\"\n"+
200             " type=\"INTEGER\"\n"+
201             " required=\"true\"\n"+
202             " />\n"+
203             " </table>\n"+
204             "</database>",
205             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
206     }
207 }
208
Popular Tags