KickJava   Java API By Example, From Geeks To Geeks.

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


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

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