KickJava   Java API By Example, From Geeks To Geeks.

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


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

23 public class FieldTagLockingAttributeTests extends OjbTestBase
24 {
25     public FieldTagLockingAttributeTests(String JavaDoc name)
26     {
27         super(name);
28     }
29
30     // Test: locking attribute with no value
31
public void testLocking1()
32     {
33         addClass(
34             "test.A",
35             "package test;\n"+
36             "/** @ojb.class */\n"+
37             "public class A {\n"+
38             "/** @ojb.field locking=\"\" */\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: locking attribute with invalid value
47
public void testLocking2()
48     {
49         addClass(
50             "test.A",
51             "package test;\n"+
52             "/** @ojb.class */\n"+
53             "public class A {\n"+
54             "/** @ojb.field locking=\"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: locking attribute with 'true' value
63
public void testLocking3()
64     {
65         addClass(
66             "test.A",
67             "package test;\n"+
68             "/** @ojb.class */\n"+
69             "public class A {\n"+
70             "/** @ojb.field column=\"ATTR_COLUMN\"\n"+
71             " * locking=\"true\"\n"+
72             " */\n"+
73             " private int attr;\n"+
74             "}\n");
75
76         assertEqualsOjbDescriptorFile(
77             "<class-descriptor\n"+
78             " class=\"test.A\"\n"+
79             " table=\"A\"\n"+
80             ">\n"+
81             " <field-descriptor\n"+
82             " name=\"attr\"\n"+
83             " column=\"ATTR_COLUMN\"\n"+
84             " jdbc-type=\"INTEGER\"\n"+
85             " locking=\"true\"\n"+
86             " >\n"+
87             " </field-descriptor>\n"+
88             "</class-descriptor>",
89             runOjbXDoclet(OJB_DEST_FILE));
90         assertEqualsTorqueSchemaFile(
91             "<database name=\"ojbtest\">\n"+
92             " <table name=\"A\">\n"+
93             " <column name=\"ATTR_COLUMN\"\n"+
94             " javaName=\"attr\"\n"+
95             " type=\"INTEGER\"\n"+
96             " />\n"+
97             " </table>\n"+
98             "</database>",
99             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
100     }
101
102     // Test: locking attribute with 'false' value
103
public void testLocking4()
104     {
105         addClass(
106             "test.A",
107             "package test;\n"+
108             "/** @ojb.class */\n"+
109             "public class A {\n"+
110             "/** @ojb.field locking=\"false\" */\n"+
111             " private int attr;\n"+
112             "}\n");
113
114         assertEqualsOjbDescriptorFile(
115             "<class-descriptor\n"+
116             " class=\"test.A\"\n"+
117             " table=\"A\"\n"+
118             ">\n"+
119             " <field-descriptor\n"+
120             " name=\"attr\"\n"+
121             " column=\"attr\"\n"+
122             " jdbc-type=\"INTEGER\"\n"+
123             " locking=\"false\"\n"+
124             " >\n"+
125             " </field-descriptor>\n"+
126             "</class-descriptor>",
127             runOjbXDoclet(OJB_DEST_FILE));
128         assertEqualsTorqueSchemaFile(
129             "<database name=\"ojbtest\">\n"+
130             " <table name=\"A\">\n"+
131             " <column name=\"attr\"\n"+
132             " javaName=\"attr\"\n"+
133             " type=\"INTEGER\"\n"+
134             " />\n"+
135             " </table>\n"+
136             "</database>",
137             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
138     }
139
140     // Test: inherited locking attribute with 'true' value
141
public void testLocking5()
142     {
143         addClass(
144             "test.A",
145             "package test;\n"+
146             "/** @ojb.class */\n"+
147             "public class A {\n"+
148             "/** @ojb.field locking=\"true\" */\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             " locking=\"true\"\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             " locking=\"true\"\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             " />\n"+
195             " </table>\n"+
196             " <table name=\"C\">\n"+
197             " <column name=\"attr\"\n"+
198             " javaName=\"attr\"\n"+
199             " type=\"INTEGER\"\n"+
200             " />\n"+
201             " </table>\n"+
202             "</database>",
203             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
204     }
205 }
206
Popular Tags