KickJava   Java API By Example, From Geeks To Geeks.

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


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 indexed attribute.
20  * See also the tests for the ojb.index tag.
21  *
22  * @author <a HREF="mailto:tomdz@users.sourceforge.net">Thomas Dudziak (tomdz@users.sourceforge.net)</a>
23  */

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