1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.dbforms.config;
25
26 import org.dbforms.util.AbstractTestCase;
27
28
29
30 /***
31 * Description of the Class
32 *
33 * @author epugh
34 * @created May 3, 2002
35 */
36 public class TestField extends AbstractTestCase {
37 /***
38 * DOCUMENT ME!
39 *
40 * @throws Exception DOCUMENT ME!
41 */
42 public void testGetSetAutoInc() throws Exception {
43 Field f = new Field();
44 f.setAutoInc("true");
45 assertTrue("Field should be autoinc", f.hasAutoIncSet());
46 }
47
48
49 /***
50 * DOCUMENT ME!
51 *
52 * @throws Exception DOCUMENT ME!
53 */
54 public void testGetSetAutoInc2() throws Exception {
55 Field f = new Field();
56 f.setAutoInc("YES");
57 assertTrue("Field should be autoinc", f.hasAutoIncSet());
58 }
59
60
61 /***
62 * DOCUMENT ME!
63 *
64 * @throws Exception DOCUMENT ME!
65 */
66 public void testGetSetId() throws Exception {
67 Field f = new Field();
68 f.setId(10);
69 assertTrue("Field id should be 10", f.getId() == 10);
70 }
71
72
73 /***
74 * DOCUMENT ME!
75 *
76 * @throws Exception DOCUMENT ME!
77 */
78 public void testGetSetName() throws Exception {
79 Field f = new Field();
80 f.setName("FIELDNAME");
81 assertTrue("Field name should be FIELDNAME",
82 f.getName().equals("FIELDNAME"));
83 }
84
85
86 /***
87 * DOCUMENT ME!
88 *
89 * @throws Exception DOCUMENT ME!
90 */
91 public void testSortable() throws Exception {
92 Field f = new Field();
93 f.setSortable("true");
94 assertTrue("Should be True", f.hasSortableSet());
95 f.setSortable("TRUE");
96 assertTrue("Should be True", f.hasSortableSet());
97 f.setSortable("yes");
98 assertTrue("Should be True", f.hasSortableSet());
99 f.setSortable("FALSE");
100 assertTrue("Should be false", !f.hasSortableSet());
101 f.setSortable("NO");
102 assertTrue("Should be false", !f.hasSortableSet());
103 }
104
105
106 /***
107 * DOCUMENT ME!
108 *
109 * @throws Exception DOCUMENT ME!
110 */
111 public void testType() throws Exception {
112 Field f = new Field();
113 f.setFieldType("int");
114 assertTrue("Should be FieldTypes.INTEGER",
115 f.getType() == FieldTypes.INTEGER);
116 f.setFieldType("smallint");
117 assertTrue("Should be FieldTypes.INTEGER",
118 f.getType() == FieldTypes.INTEGER);
119 f.setFieldType("tinyint");
120 assertTrue("Should be FieldTypes.INTEGER",
121 f.getType() == FieldTypes.INTEGER);
122 f.setFieldType("TINYINT");
123 assertTrue("Should be FieldTypes.INTEGER",
124 f.getType() == FieldTypes.INTEGER);
125
126 f.setFieldType("NUMERIC");
127 assertTrue("Should be FieldTypes.NUMERIC",
128 f.getType() == FieldTypes.NUMERIC);
129 f.setFieldType("NUMBER");
130 assertTrue("Should be FieldTypes.NUMERIC",
131 f.getType() == FieldTypes.NUMERIC);
132
133 f.setFieldType("char");
134 assertTrue("Should be FieldTypes.CHAR", f.getType() == FieldTypes.CHAR);
135 f.setFieldType("text");
136 assertTrue("Should be FieldTypes.CHAR", f.getType() == FieldTypes.CHAR);
137
138 f.setFieldType("varchar");
139 assertTrue("Should be FieldTypes.VARCHAR", f.getType() == FieldTypes.VARCHAR);
140 f.setFieldType("longchar");
141 assertTrue("Should be FieldTypes.VARCHAR", f.getType() == FieldTypes.VARCHAR);
142 f.setFieldType("nvarchar");
143 assertTrue("Should be FieldTypes.VARCHAR", f.getType() == FieldTypes.VARCHAR);
144
145 f.setFieldType("long varchar");
146 assertTrue("Should be FieldTypes.LONGVARCHAR", f.getType() == FieldTypes.LONGVARCHAR);
147
148 f.setFieldType("date");
149 assertTrue("Should be FieldTypes.DATE", f.getType() == FieldTypes.DATE);
150
151 f.setFieldType("timestamp");
152 assertTrue("Should be FieldTypes.TIMESTAMP",
153 f.getType() == FieldTypes.TIMESTAMP);
154
155 f.setFieldType("time");
156 assertTrue("Should be FieldTypes.TIME", f.getType() == FieldTypes.TIME);
157
158 f.setFieldType("double");
159 assertTrue("Should be FieldTypes.DOUBLE", f.getType() == FieldTypes.DOUBLE);
160 f.setFieldType("float");
161 assertTrue("Should be FieldTypes.DOUBLE", f.getType() == FieldTypes.DOUBLE);
162
163 f.setFieldType("real");
164 assertTrue("Should be FieldTypes.FLOAT", f.getType() == FieldTypes.FLOAT);
165
166 f.setFieldType("blob");
167 assertTrue("Should be FieldTypes.BLOB", f.getType() == FieldTypes.BLOB);
168 f.setFieldType("image");
169 assertTrue("Should be FieldTypes.BLOB", f.getType() == FieldTypes.BLOB);
170
171 f.setFieldType("diskblob");
172 assertTrue("Should be FieldTypes.DISKBLOB",
173 f.getType() == FieldTypes.DISKBLOB);
174 }
175
176
177 /***
178 * DOCUMENT ME!
179 *
180 * @throws Exception DOCUMENT ME!
181 */
182 public void testType2() throws Exception {
183 Field f = new Field();
184 f.setTypeByObject(new java.lang.Integer(0));
185 assertTrue("Should be FieldTypes.INTEGER",
186 f.getType() == FieldTypes.INTEGER);
187 f.setTypeByObject(new java.lang.Long(0));
188 assertTrue("Should be FieldTypes.INTEGER",
189 f.getType() == FieldTypes.INTEGER);
190 f.setTypeByObject("");
191 assertTrue("Should be FieldTypes.CHAR", f.getType() == FieldTypes.CHAR);
192 f.setTypeByObject(new java.math.BigDecimal(0));
193 assertTrue("Should be FieldTypes.NUMERIC",
194 f.getType() == FieldTypes.NUMERIC);
195 f.setTypeByObject(new java.sql.Date(0));
196 assertTrue("Should be FieldTypes.DATE", f.getType() == FieldTypes.DATE);
197 f.setTypeByObject(new java.sql.Time(0));
198 assertTrue("Should be FieldTypes.TIME", f.getType() == FieldTypes.TIME);
199 f.setTypeByObject(new java.sql.Timestamp(0));
200 assertTrue("Should be FieldTypes.TIMESTAMP",
201 f.getType() == FieldTypes.TIMESTAMP);
202 f.setTypeByObject(new java.lang.Double(0));
203 assertTrue("Should be FieldTypes.DOUBLE", f.getType() == FieldTypes.DOUBLE);
204 f.setTypeByObject(new java.lang.Float(0));
205 assertTrue("Should be FieldTypes.FLOAT", f.getType() == FieldTypes.FLOAT);
206 }
207 }