View Javadoc
1   /*
2    *
3    * The DbUnit Database Testing Framework
4    * Copyright (C)2002-2004, DbUnit.org
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 2.1 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Lesser General Public License for more details.
15   *
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with this library; if not, write to the Free Software
18   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   *
20   */
21  
22  package org.dbunit.ext.oracle;
23  
24  import org.dbunit.database.ExtendedMockSingleRowResultSet;
25  import org.dbunit.dataset.datatype.AbstractDataTypeTest;
26  import org.dbunit.dataset.datatype.DataType;
27  import org.dbunit.dataset.datatype.TypeCastException;
28  import org.dbunit.dataset.ITable;
29  
30  import java.math.BigDecimal;
31  import java.sql.Types;
32  
33  /**
34   * @author 
35   * @version
36   */
37  
38  public class OracleSdoGeometryDataTypeTest extends AbstractDataTypeTest
39  {
40      private final static DataType THIS_TYPE = OracleDataTypeFactory.ORACLE_SDO_GEOMETRY_TYPE;
41  
42      public OracleSdoGeometryDataTypeTest(String name)
43      {
44          super(name);
45      }
46  
47      /**
48       *
49       */
50      public void testToString() throws Exception
51      {
52          assertEquals("name", "SDO_GEOMETRY", THIS_TYPE.toString());
53      }
54  
55      /**
56       *
57       */
58      public void testGetTypeClass() throws Exception
59      {
60          assertEquals("class", org.dbunit.ext.oracle.OracleSdoGeometry.class, THIS_TYPE.getTypeClass());
61      }
62  
63      /**
64       *
65       */
66      public void testIsNumber() throws Exception
67      {
68          assertEquals("is number", false, THIS_TYPE.isNumber());
69      }
70  
71      public void testIsDateTime() throws Exception
72      {
73          assertEquals("is date/time", false, THIS_TYPE.isDateTime());
74      }
75  
76      public void testTypeCast() throws Exception
77      {
78          Object[] values = {
79              null,
80              new OracleSdoGeometry(null, null, null, null, null),
81              new OracleSdoGeometry(new BigDecimal(123), null, null, null, null),
82              new OracleSdoGeometry(new BigDecimal(123), new BigDecimal("45.6"), null, null, null),
83              new OracleSdoGeometry(null, null, new OracleSdoPointType(null, null, null), null, null),
84              new OracleSdoGeometry(null, null, new OracleSdoPointType(new BigDecimal(1), new BigDecimal(2), new BigDecimal(3)), null, null),
85              new OracleSdoGeometry(null, null, null, new OracleSdoElemInfoArray(), null),
86              new OracleSdoGeometry(null, null, null, null, new OracleSdoOrdinateArray()),
87              new OracleSdoGeometry(new BigDecimal(123), new BigDecimal("45.6"), 
88                  new OracleSdoPointType(new BigDecimal("-1234.564"), new BigDecimal("5.3403"), new BigDecimal(57)),
89                  new OracleSdoElemInfoArray(
90                      new BigDecimal [] { new BigDecimal(10), new BigDecimal(9), new BigDecimal(8), new BigDecimal(7) } ),
91                  new OracleSdoOrdinateArray(
92                      new BigDecimal [] { new BigDecimal(6), new BigDecimal(5), new BigDecimal(4), new BigDecimal(3) } )),
93              "NULL",
94              " NULL ",
95              "sdo_geometry(123, null, null, null, null)",
96              "sdo_gEOMEtry(123, null, null, null, null)",
97              "mdsys.sdo_geometry(123, 45.6, null, null, null)",
98              "mdsys.sdo_geometry(123, 45.6, sdo_point_type(null,null,null),null,null)",
99              "mdsys.sdo_geometry(123, 45.6, sdo_point_type(987.34,56.3,-123456),null,null)",
100             "mDSys.sdo_geometry(123, 45.6, mdsYS.sdo_point_type ( 987.34 , 56.3 , 0 ) ,null,null)",
101             "mDSys.sdo_geometry(123, 45.6, mdsYS.sdo_point_type ( 987.34 , 56.3 , 1 ) , sdo_elem_info_array(),null)",
102             "mDSys.sdo_geometry(123, 45.6, mdsYS.sdo_point_type ( 987.34 , 56.3 , 2 ) , mdsys.sdo_elem_info_array(null),null)",
103             "mDSys.sdo_geometry(123, 45.6, mdsYS.sdo_point_type ( 987.34 , 56.3 , 3 ) , sdo_elem_info_array(1,null,2,null,3,null),null)",
104             "sdo_geometry(123, 45.6, mdsys.sdo_point_type ( 987.34 , 56.3 , 3 ) , mdsys.sdo_elem_info_array(1,2) , sdo_ordinate_array())",
105             "sdo_geometry(123, 45.6, mdsys.sdo_point_type ( 987.34 , 56.3 , 3 ) , mdsys.sdo_elem_info_array(1,3) , sdo_ordinate_array(null))",
106             " sdo_geometry(123, 45.6, mdsys.sdo_point_type (null,null,null) , mdsys.sdo_elem_info_array( 1 , 4 ) , MDSYS.sdo_ordinate_array( 4,5 , null , 6 ) ) ",
107         };
108 
109         OracleSdoGeometry [] expected = {
110             null,
111             new OracleSdoGeometry(null, null, null, null, null),
112             new OracleSdoGeometry(new BigDecimal(123), null, null, null, null),
113             new OracleSdoGeometry(new BigDecimal(123), new BigDecimal("45.6"), null, null, null),
114             new OracleSdoGeometry(null, null, new OracleSdoPointType(null, null, null), null, null),
115             new OracleSdoGeometry(null, null, new OracleSdoPointType(new BigDecimal(1), new BigDecimal(2), new BigDecimal(3)), null, null),
116             new OracleSdoGeometry(null, null, null, new OracleSdoElemInfoArray(), null),
117             new OracleSdoGeometry(null, null, null, null, new OracleSdoOrdinateArray()),
118             new OracleSdoGeometry(new BigDecimal(123), new BigDecimal("45.6"), 
119                 new OracleSdoPointType(new BigDecimal("-1234.564"), new BigDecimal("5.3403"), new BigDecimal(57)),
120                 new OracleSdoElemInfoArray(
121                     new BigDecimal [] { new BigDecimal(10), new BigDecimal(9), new BigDecimal(8), new BigDecimal(7) } ),
122                 new OracleSdoOrdinateArray(
123                     new BigDecimal [] { new BigDecimal(6), new BigDecimal(5), new BigDecimal(4), new BigDecimal(3) } )),
124             null,
125             null,
126             new OracleSdoGeometry(new BigDecimal(123), null, null, null, null),
127             new OracleSdoGeometry(new BigDecimal(123), null, null, null, null),
128             new OracleSdoGeometry(new BigDecimal(123), new BigDecimal("45.6"), null, null, null),
129             new OracleSdoGeometry(new BigDecimal(123), new BigDecimal("45.6"), new OracleSdoPointType(), null, null),
130             new OracleSdoGeometry(new BigDecimal(123), new BigDecimal("45.6"), 
131                 new OracleSdoPointType(new BigDecimal("987.34"), new BigDecimal("56.3"), new BigDecimal("-123456")),
132                 null, null),
133             new OracleSdoGeometry(new BigDecimal(123), new BigDecimal("45.6"), 
134                 new OracleSdoPointType(new BigDecimal("987.34"), new BigDecimal("56.3"), new BigDecimal("0")),
135                 null, null),
136             new OracleSdoGeometry(new BigDecimal(123), new BigDecimal("45.6"), 
137                 new OracleSdoPointType(new BigDecimal("987.34"), new BigDecimal("56.3"), new BigDecimal("1")),
138                 new OracleSdoElemInfoArray(), null),
139             new OracleSdoGeometry(new BigDecimal(123), new BigDecimal("45.6"), 
140                 new OracleSdoPointType(new BigDecimal("987.34"), new BigDecimal("56.3"), new BigDecimal("2")),
141                 new OracleSdoElemInfoArray(new BigDecimal [] { null }), null),
142             new OracleSdoGeometry(new BigDecimal(123), new BigDecimal("45.6"), 
143                 new OracleSdoPointType(new BigDecimal("987.34"), new BigDecimal("56.3"), new BigDecimal("3")),
144                 new OracleSdoElemInfoArray(
145                     new BigDecimal [] { new BigDecimal(1), null, new BigDecimal(2), null, new BigDecimal(3), null }),
146                 null),
147             new OracleSdoGeometry(new BigDecimal(123), new BigDecimal("45.6"), 
148                 new OracleSdoPointType(new BigDecimal("987.34"), new BigDecimal("56.3"), new BigDecimal("3")),
149                 new OracleSdoElemInfoArray(
150                     new BigDecimal [] { new BigDecimal(1), new BigDecimal(2) }),
151                 new OracleSdoOrdinateArray()),
152             new OracleSdoGeometry(new BigDecimal(123), new BigDecimal("45.6"), 
153                 new OracleSdoPointType(new BigDecimal("987.34"), new BigDecimal("56.3"), new BigDecimal("3")),
154                 new OracleSdoElemInfoArray(
155                     new BigDecimal [] { new BigDecimal(1), new BigDecimal(3) }),
156                 new OracleSdoOrdinateArray(new BigDecimal [] { null })),
157             new OracleSdoGeometry(new BigDecimal(123), new BigDecimal("45.6"), 
158                 new OracleSdoPointType(null,null,null),
159                 new OracleSdoElemInfoArray(
160                     new BigDecimal [] { new BigDecimal(1), new BigDecimal(4) }),
161                 new OracleSdoOrdinateArray(new BigDecimal [] { new BigDecimal(4), new BigDecimal(5), null, new BigDecimal(6) })),
162         };
163 
164         assertEquals("actual vs expected count", values.length, expected.length);
165 
166         for (int i = 0; i < values.length; i++)
167         {
168             assertEquals("typecast " + i, expected[i],
169                     THIS_TYPE.typeCast(values[i]));
170         }
171     }
172 
173     public void testTypeCastNone() throws Exception
174     {
175         assertEquals("typecast", null, THIS_TYPE.typeCast(ITable.NO_VALUE));
176     }
177 
178     public void testTypeCastInvalid() throws Exception
179     {
180         Object[] values = {
181             new Object(),
182             "bla",
183             new java.util.Date(),
184             "sdo_geometry(12xya3, null, null, null, null)",
185             "sdo_geometry(, null, null, null, null)",
186             "sdo_geometry(1,2, X, null, null)",
187             "mdsys.sdo_geometry(123, 45.6, null, ABC, null)",
188             "mdsys.sdo_geometry(123, 45.6, sdo_point_type(null,OUCH,null),null,null)",
189             "mdsys.sdo_geometry(123, 45.6, sdo_point_type(987.34,56.3,-OUCH),null,null)",
190             "mDSys.sdo_geometry(123, 45.6, mdsYS.sdo_point_type ( 987.34 , 56.3 , 0 ) ,null,BAD)",
191             "mDSys.sdo_geometry(123, 45.6, mdsYS.sdo_point_type ( 987.34 , 56.3 , 1 ) , sdo_elem_info_array,null)",
192             "mDSys.sdo_geometry(123, 45.6, mdsYS.sdo_point_type ( 987.34 , 56.3 , 2 ) , mdsys.sdo_elem_info_array(OUCH),null)",
193             "mDSys.sdo_geometry(123, 45.6, mdsYS.sdo_point_type ( 56.3 , 3 ) , sdo_elem_info_array(1,null,2,null,3,null),null)",
194             " sdo_geometry(123, 45.6, mdsys.sdo_point_type (null,null,null) , mdsys.sdo_elem_info_array( 1 , 4 ) , MDSYS.sdo_ordinate_array( 4,5 , null , 6 ) , ) ",
195         };
196 
197         for (int i = 0; i < values.length; i++)
198         {
199             try
200             {
201                 THIS_TYPE.typeCast(values[i]);
202                 fail("Should throw TypeCastException");
203             }
204             catch (TypeCastException e)
205             {
206             }
207         }
208     }
209 
210     public void testCompareEquals() throws Exception
211     {
212         Object[] values1 = {
213             null,
214             new OracleSdoGeometry(null, null, null, null, null),
215             new OracleSdoGeometry(new BigDecimal(123), null, null, null, null),
216             new OracleSdoGeometry(new BigDecimal(123), new BigDecimal("45.6"), null, null, null),
217             new OracleSdoGeometry(null, null, new OracleSdoPointType(null, null, null), null, null),
218             new OracleSdoGeometry(null, null, new OracleSdoPointType(new BigDecimal(1), new BigDecimal(2), new BigDecimal(3)), null, null),
219             new OracleSdoGeometry(null, null, null, new OracleSdoElemInfoArray(), null),
220             new OracleSdoGeometry(null, null, null, null, new OracleSdoOrdinateArray()),
221             new OracleSdoGeometry(new BigDecimal(123), new BigDecimal("45.6"), 
222                 new OracleSdoPointType(new BigDecimal("-1234.564"), new BigDecimal("5.3403"), new BigDecimal(57)),
223                 new OracleSdoElemInfoArray(
224                     new BigDecimal [] { new BigDecimal(10), new BigDecimal(9), new BigDecimal(8), new BigDecimal(7) } ),
225                 new OracleSdoOrdinateArray(
226                     new BigDecimal [] { new BigDecimal(6), new BigDecimal(5), new BigDecimal(4), new BigDecimal(3) } )),
227             "NULL",
228             " NULL ",
229             "sdo_geometry(123, null, null, null, null)",
230             "sdo_gEOMEtry(123, null, null, null, null)",
231             "mdsys.sdo_geometry(123, 45.6, null, null, null)",
232             "mdsys.sdo_geometry(123, 45.6, sdo_point_type(null,null,null),null,null)",
233             "mdsys.sdo_geometry(123, 45.6, sdo_point_type(987.34,56.3,-123456),null,null)",
234             "mDSys.sdo_geometry(123, 45.6, mdsYS.sdo_point_type ( 987.34 , 56.3 , 0 ) ,null,null)",
235             "mDSys.sdo_geometry(123, 45.6, mdsYS.sdo_point_type ( 987.34 , 56.3 , 1 ) , sdo_elem_info_array(),null)",
236             "mDSys.sdo_geometry(123, 45.6, mdsYS.sdo_point_type ( 987.34 , 56.3 , 2 ) , mdsys.sdo_elem_info_array(null),null)",
237             "mDSys.sdo_geometry(123, 45.6, mdsYS.sdo_point_type ( 987.34 , 56.3 , 3 ) , sdo_elem_info_array(1,null,2,null,3,null),null)",
238             "sdo_geometry(123, 45.6, mdsys.sdo_point_type ( 987.34 , 56.3 , 3 ) , mdsys.sdo_elem_info_array(1,2) , sdo_ordinate_array())",
239             "sdo_geometry(123, 45.6, mdsys.sdo_point_type ( 987.34 , 56.3 , 3 ) , mdsys.sdo_elem_info_array(1,3) , sdo_ordinate_array(null))",
240             " sdo_geometry(123, 45.6, mdsys.sdo_point_type (null,null,null) , mdsys.sdo_elem_info_array( 1 , 4 ) , MDSYS.sdo_ordinate_array( 4,5 , null , 6 ) ) ",
241         };
242 
243         Object [] values2 = {
244             null,
245             new OracleSdoGeometry(null, null, null, null, null),
246             new OracleSdoGeometry(new BigDecimal(123), null, null, null, null),
247             new OracleSdoGeometry(new BigDecimal(123), new BigDecimal("45.6"), null, null, null),
248             new OracleSdoGeometry(null, null, new OracleSdoPointType(null, null, null), null, null),
249             new OracleSdoGeometry(null, null, new OracleSdoPointType(new BigDecimal(1), new BigDecimal(2), new BigDecimal(3)), null, null),
250             new OracleSdoGeometry(null, null, null, new OracleSdoElemInfoArray(), null),
251             new OracleSdoGeometry(null, null, null, null, new OracleSdoOrdinateArray()),
252             new OracleSdoGeometry(new BigDecimal(123), new BigDecimal("45.6"), 
253                 new OracleSdoPointType(new BigDecimal("-1234.564"), new BigDecimal("5.3403"), new BigDecimal(57)),
254                 new OracleSdoElemInfoArray(
255                     new BigDecimal [] { new BigDecimal(10), new BigDecimal(9), new BigDecimal(8), new BigDecimal(7) } ),
256                 new OracleSdoOrdinateArray(
257                     new BigDecimal [] { new BigDecimal(6), new BigDecimal(5), new BigDecimal(4), new BigDecimal(3) } )),
258             null,
259             null,
260             new OracleSdoGeometry(new BigDecimal(123), null, null, null, null),
261             new OracleSdoGeometry(new BigDecimal(123), null, null, null, null),
262             new OracleSdoGeometry(new BigDecimal(123), new BigDecimal("45.6"), null, null, null),
263             new OracleSdoGeometry(new BigDecimal(123), new BigDecimal("45.6"), new OracleSdoPointType(), null, null),
264             new OracleSdoGeometry(new BigDecimal(123), new BigDecimal("45.6"), 
265                 new OracleSdoPointType(new BigDecimal("987.34"), new BigDecimal("56.3"), new BigDecimal("-123456")),
266                 null, null),
267             new OracleSdoGeometry(new BigDecimal(123), new BigDecimal("45.6"), 
268                 new OracleSdoPointType(new BigDecimal("987.34"), new BigDecimal("56.3"), new BigDecimal("0")),
269                 null, null),
270             new OracleSdoGeometry(new BigDecimal(123), new BigDecimal("45.6"), 
271                 new OracleSdoPointType(new BigDecimal("987.34"), new BigDecimal("56.3"), new BigDecimal("1")),
272                 new OracleSdoElemInfoArray(), null),
273             new OracleSdoGeometry(new BigDecimal(123), new BigDecimal("45.6"), 
274                 new OracleSdoPointType(new BigDecimal("987.34"), new BigDecimal("56.3"), new BigDecimal("2")),
275                 new OracleSdoElemInfoArray(new BigDecimal [] { null }), null),
276             new OracleSdoGeometry(new BigDecimal(123), new BigDecimal("45.6"), 
277                 new OracleSdoPointType(new BigDecimal("987.34"), new BigDecimal("56.3"), new BigDecimal("3")),
278                 new OracleSdoElemInfoArray(
279                     new BigDecimal [] { new BigDecimal(1), null, new BigDecimal(2), null, new BigDecimal(3), null }),
280                 null),
281             new OracleSdoGeometry(new BigDecimal(123), new BigDecimal("45.6"), 
282                 new OracleSdoPointType(new BigDecimal("987.34"), new BigDecimal("56.3"), new BigDecimal("3")),
283                 new OracleSdoElemInfoArray(
284                     new BigDecimal [] { new BigDecimal(1), new BigDecimal(2) }),
285                 new OracleSdoOrdinateArray()),
286             new OracleSdoGeometry(new BigDecimal(123), new BigDecimal("45.6"), 
287                 new OracleSdoPointType(new BigDecimal("987.34"), new BigDecimal("56.3"), new BigDecimal("3")),
288                 new OracleSdoElemInfoArray(
289                     new BigDecimal [] { new BigDecimal(1), new BigDecimal(3) }),
290                 new OracleSdoOrdinateArray(new BigDecimal [] { null })),
291             new OracleSdoGeometry(new BigDecimal(123), new BigDecimal("45.6"), 
292                 new OracleSdoPointType(null,null,null),
293                 new OracleSdoElemInfoArray(
294                     new BigDecimal [] { new BigDecimal(1), new BigDecimal(4) }),
295                 new OracleSdoOrdinateArray(new BigDecimal [] { new BigDecimal(4), new BigDecimal(5), null, new BigDecimal(6) })),
296         };
297 
298         assertEquals("values count", values1.length, values2.length);
299 
300         for (int i = 0; i < values1.length; i++)
301         {
302             assertEquals("compare1 " + i, 0, THIS_TYPE.compare(values1[i], values2[i]));
303             assertEquals("compare2 " + i, 0, THIS_TYPE.compare(values2[i], values1[i]));
304         }
305     }
306 
307     public void testCompareInvalid() throws Exception
308     {
309         Object[] values1 = {
310             new Object(),
311             "bla",
312             new java.util.Date()
313         };
314         Object[] values2 = {
315             null,
316             null,
317             null
318         };
319 
320         assertEquals("values count", values1.length, values2.length);
321 
322         for (int i = 0; i < values1.length; i++)
323         {
324             try
325             {
326                 THIS_TYPE.compare(values1[i], values2[i]);
327                 fail("Should throw TypeCastException");
328             }
329             catch (TypeCastException e)
330             {
331             }
332 
333             try
334             {
335                 THIS_TYPE.compare(values2[i], values1[i]);
336                 fail("Should throw TypeCastException");
337             }
338             catch (TypeCastException e)
339             {
340             }
341         }
342     }
343 
344     public void testCompareDifferent() throws Exception
345     {
346         Object[] less = {
347             new OracleSdoGeometry(null, null, null, null, null),
348         };
349 
350         Object[] greater = {
351             new OracleSdoGeometry(new BigDecimal(1), new BigDecimal(2), null, null, null),
352         };
353 
354         assertEquals("values count", less.length, greater.length);
355 
356         for (int i = 0; i < less.length; i++)
357         {
358             try
359             {
360                 THIS_TYPE.compare(less[i], greater[i]);
361                 // OracleSdoGeometry objects are not Comparable
362                 fail("Should throw TypeCastException");
363             }
364             catch (TypeCastException e)
365             {
366             }
367         }
368      }
369 
370     public void testSqlType() throws Exception
371     {
372         assertEquals(Types.STRUCT, THIS_TYPE.getSqlType());
373     }
374 
375     public void testForObject() throws Exception
376     {
377         DataType actual = DataType.forObject(new OracleSdoGeometry());
378         assertEquals(DataType.UNKNOWN, actual);
379     }
380 
381     public void testAsString() throws Exception
382     {
383         // not supported until there is some way to render OracleSdoGeometry
384         // as strings
385         Object [] values = {
386         };
387 
388         Object [] expected = {
389         };
390 
391         assertEquals("actual vs expected count", values.length, expected.length);
392 
393         for (int i = 0; i < values.length; i++)
394         {
395             assertEquals("asString " + i, expected[i], DataType.asString(values[i]));
396         }
397 
398     }
399 
400     public void testGetSqlValue() throws Exception
401     {
402     }
403 }