Source Code Cross Referenced for SDOOnlineTest.java in  » GIS » GeoTools-2.4.1 » org » geotools » data » oracle » sdo » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » GIS » GeoTools 2.4.1 » org.geotools.data.oracle.sdo 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2003-2006, Geotools Project Managment Committee (PMC)
005:         *    (C) 2003  Refractions Research Inc.
006:         *    
007:         *    This library is free software; you can redistribute it and/or
008:         *    modify it under the terms of the GNU Lesser General Public
009:         *    License as published by the Free Software Foundation; either
010:         *    version 2.1 of the License, or (at your option) any later version.
011:         *
012:         *    This library is distributed in the hope that it will be useful,
013:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         *    Lesser General Public License for more details.
016:         *
017:         *    Refractions Research Inc. Can be found on the web at:
018:         *    http://www.refractions.net/
019:         */
020:        package org.geotools.data.oracle.sdo;
021:
022:        import java.sql.SQLException;
023:
024:        import oracle.sql.Datum;
025:        import oracle.sql.STRUCT;
026:
027:        import org.geotools.data.oracle.OracleTestFixture;
028:
029:        import com.vividsolutions.jts.geom.Geometry;
030:
031:        import junit.framework.TestCase;
032:
033:        /**
034:         * @author jgarnett
035:         *
036:         * TODO To change the template for this generated type comment go to
037:         * Window - Preferences - Java - Code Style - Code Templates
038:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/oracle-spatial/src/test/java/org/geotools/data/oracle/sdo/SDOOnlineTest.java $
039:         */
040:        public class SDOOnlineTest extends TestCase {
041:            GeometryFixture fixture;
042:            OracleTestFixture oracle;
043:            GeometryConverter converter;
044:
045:            /**
046:             * Constructor for GeometryToJTSTest.
047:             * @param arg0
048:             */
049:            public SDOOnlineTest(String arg0) {
050:                super (arg0);
051:            }
052:
053:            /*
054:             * @see TestCase#setUp()
055:             */
056:            protected void setUp() throws Exception {
057:                super .setUp();
058:                fixture = new GeometryFixture();
059:                oracle = new OracleTestFixture();
060:                converter = new GeometryConverter(oracle.connection);
061:            }
062:
063:            /*
064:             * @see TestCase#tearDown()
065:             */
066:            protected void tearDown() throws Exception {
067:                oracle.close();
068:                super .tearDown();
069:            }
070:
071:            final public void testGType() throws SQLException {
072:                assertEquals(2003, SDO.gType(fixture.rectangle));
073:            }
074:
075:            final public void testGTypeD() {
076:                assertEquals(2, SDO.D(fixture.rectangle));
077:            }
078:
079:            final public void testGTypeL() {
080:                assertEquals(0, SDO.L(fixture.rectangle));
081:            }
082:
083:            final public void testGTypeTT() {
084:                assertEquals(03, SDO.TT(fixture.rectangle));
085:            }
086:
087:            final public void testSRID() throws SQLException {
088:                assertEquals(-1, SDO.SRID(fixture.rectangle));
089:            }
090:
091:            final public void testElemInfo() throws SQLException {
092:                int elemInfo[] = SDO.elemInfo(fixture.rectangle);
093:                assertEquals(1, elemInfo[0]);
094:                assertEquals(1003, elemInfo[1]);
095:                assertEquals(3, elemInfo[2]);
096:            }
097:
098:            final public void testElemInfoStartingOffset() {
099:                assertEquals(1, SDO.elemInfoStartingOffset(fixture.rectangle));
100:            }
101:
102:            final public void testElemInfoEType() {
103:                assertEquals(1003, SDO.elemInfoEType(fixture.rectangle));
104:            }
105:
106:            final public void testGeometryElemInfoInterpretation() {
107:                assertEquals(3, SDO.elemInfoInterpretation(fixture.rectangle));
108:            }
109:
110:            final public void testOrdinates() throws SQLException {
111:                double ords[] = SDO.ordinates(fixture.rectangle);
112:                assertEquals("length", 4, ords.length);
113:                assertEquals("x1", 1, ords[0], 0.00001);
114:                assertEquals("y1", 1, ords[1], 0.00001);
115:                assertEquals("x2", 5, ords[2], 0.00001);
116:                assertEquals("y2", 7, ords[3], 0.00001);
117:            }
118:
119:            final public void testDecodePoint() throws SQLException {
120:                if (oracle.connection == null)
121:                    return;
122:                STRUCT datum = converter.toSDO(fixture.point);
123:                Geometry geom = (Geometry) converter.asGeometry(datum);
124:
125:                assertEquals(fixture.point, geom);
126:            }
127:
128:            final public void testDecodeLine() throws SQLException {
129:                if (oracle.connection == null)
130:                    return;
131:                STRUCT datum = converter.toSDO(fixture.lineString);
132:                Geometry geom = (Geometry) converter.asGeometry(datum);
133:
134:                assertEquals(fixture.lineString, geom);
135:            }
136:
137:            final public void testDecodeRectangle() throws SQLException {
138:                if (oracle.connection == null)
139:                    return;
140:                STRUCT datum = converter.toSDO(fixture.rectangle);
141:                Geometry geom = (Geometry) converter.asGeometry(datum);
142:
143:                assertEquals(fixture.rectangle, geom);
144:            }
145:
146:            final public void testDecodePolygon() throws SQLException {
147:                if (oracle.connection == null)
148:                    return;
149:                STRUCT datum = converter.toSDO(fixture.polygon);
150:                Geometry geom = (Geometry) converter.asGeometry(datum);
151:
152:                assertEquals(fixture.polygon, geom);
153:            }
154:
155:            /**
156:             * Polygon examples used to illustrate compound encoding.</p>
157:             * <code><pre>
158:             *   5,13+-------------+   11,13
159:             *      /               \
160:             * 2,11+                 \
161:             *     | 7,10+----+10,10  \
162:             *     |     |    |       +13,9
163:             *     |     |    |       |
164:             *     |     |    |       |
165:             *     |  7,5+----+10,5   +13,5
166:             *  2,4+                  /
167:             *      \                /
168:             *   4,3+---------------+10,3
169:             * </pre></code>
170:             * <p>
171:             * A Polygon with expected encoding:</p>
172:             * <ul>
173:             * <li><b>SDO_GTYPE:</b><code>2003</code><br/>
174:             *     2 dimensional polygon, 3 for polygon
175:             *     </li>
176:             * <li><b>SDO_SRID:</b><code>NULL</code></li>
177:             * <li><b>SDO_POINT:</b>NULL></li>
178:             * <li><b>SDO_ELEM_INFO:</b><code>(1,1003,1,19,2003,1)</code><br/>
179:             *     Two triplets
180:             *     <ul>
181:             *     <li>(1,1003,1): exterior polygon ring starting at 1
182:             *         </li>
183:             *         
184:             *     <li>(19,2003,1): interior polygon ring starting at 19
185:             *         </li>
186:             *     </ul>
187:             *     </li>
188:             * <li><b>SDO_ORDINATES:</b>
189:             *     <code><pre>
190:             *        (2,4, 4,3, 10,3, 13,5, 13,9, 11,13, 5,13, 2,11, 2,4,
191:             *         7,5, 7,10, 10,10, 10,5, 7,5)
192:             *     </code><pre/>
193:             *     </li> 
194:             * </ul>
195:             * <p>
196:             * SQL:</p>
197:             * <code><pre>
198:             * MDSYS.SDO_GEOMETRY(
199:             *   2003,
200:             *   NULL,
201:             *   NULL,
202:             *   MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,1, 19,2003,1),
203:             *   MDSYS.SDO_ORDINATE_ARRAY(2,4, 4,3, 10,3, 13,5, 13,9, 11,13, 5,13, 2,11, 2,4,
204:             *       7,5, 7,10, 10,10, 10,5, 7,5)
205:             * )
206:             * </pre></code> 
207:             */
208:            final public void testPolygonEncoding() throws SQLException {
209:                if (oracle.connection == null)
210:                    return;
211:
212:                Geometry g = fixture.polygonWithHole;
213:                STRUCT datum = converter.toSDO(g);
214:
215:                assertEquals(2003, SDO.gType(g));
216:                assertEquals(-1, SDO.SRID(g));
217:                assertNull(SDO.point(g));
218:
219:                int elemInfo[] = SDO.elemInfo(g);
220:                assertEquals("elemInfo", new int[] { 1, 1003, 1, // polygon
221:                        19, 2003, 1 }, // hole
222:                        elemInfo);
223:
224:                double ords[] = SDO.ordinates(g);
225:                double expt[] = new double[] { 2, 4, 4, 3, 10, 3, 13, 5, 13, 9,
226:                        11, 13, 5, 13, 2, 11, 2, 4, // ring
227:                        7, 5, 7, 10, 10, 10, 10, 5, 7, 5 }; // hole
228:                assertEquals("ords", expt, ords);
229:                Geometry geom = (Geometry) converter.asGeometry(datum);
230:
231:                assertEquals(fixture.polygonWithHole, geom);
232:            }
233:
234:            final public void testDecodePolygonWithHole() throws SQLException {
235:                if (oracle.connection == null)
236:                    return;
237:
238:                STRUCT datum = converter.toSDO(fixture.polygonWithHole);
239:                Geometry geom = (Geometry) converter.asGeometry(datum);
240:
241:                assertEquals(fixture.polygonWithHole, geom);
242:            }
243:
244:            final public void testDecodeMultiPoint() throws SQLException {
245:                if (oracle.connection == null)
246:                    return;
247:
248:                STRUCT datum = converter.toSDO(fixture.multiPoint);
249:                Geometry geom = (Geometry) converter.asGeometry(datum);
250:
251:                assertEquals(fixture.multiPoint, geom);
252:            }
253:
254:            final public void testDecodeMultiLine() throws SQLException {
255:                if (oracle.connection == null)
256:                    return;
257:
258:                STRUCT datum = converter.toSDO(fixture.multiLineString);
259:                Geometry geom = (Geometry) converter.asGeometry(datum);
260:
261:                assertNotNull(geom);
262:                assertEquals(fixture.multiLineString, geom);
263:            }
264:
265:            final public void testDecodeMultiPolygon() throws SQLException {
266:                if (oracle.connection == null)
267:                    return;
268:
269:                STRUCT datum = converter.toSDO(fixture.multiPolygon);
270:
271:                System.out.println(fixture.multiPolygon);
272:                //System.out.println( Data.toString( datum ) );
273:
274:                Geometry geom = (Geometry) converter.asGeometry(datum);
275:
276:                //spatial.trace( "origional", fixture.multiPolygon );
277:                //spatial.trace( "tansmorgify", geom );
278:
279:                assertEquals(fixture.multiPolygon, geom);
280:            }
281:
282:            final public void testDecodeMultiPolygonWithHole()
283:                    throws SQLException {
284:                if (oracle.connection == null)
285:                    return;
286:
287:                STRUCT datum = converter.toSDO(fixture.multiPolygonWithHole);
288:
289:                Geometry geom = (Geometry) converter.asGeometry(datum);
290:
291:                assertNotNull(geom);
292:                assertTrue(geom.isValid());
293:
294:                assertFalse(fixture.multiPolygonWithHole.equalsExact(geom));
295:                assertTrue(fixture.multiPolygonWithHole.equals(geom));
296:            }
297:
298:            final public void testGeometryCollection() throws SQLException {
299:                if (oracle.connection == null)
300:                    return;
301:
302:                STRUCT datum = converter.toSDO(fixture.geometryCollection);
303:
304:                Geometry geom = (Geometry) converter.asGeometry(datum);
305:
306:                assertNotNull(geom);
307:                assertTrue(fixture.geometryCollection.isValid());
308:                assertTrue(geom.isValid());
309:                assertEquals(fixture.geometryCollection, geom);
310:            }
311:
312:            // 
313:            // Geometry Comparison
314:            //
315:            //
316:            protected void assertEquals(Geometry expected, Geometry actual) {
317:                assertEquals(null, expected, actual);
318:            }
319:
320:            protected void assertEquals(String message, Geometry expected,
321:                    Geometry actual) {
322:                if (expected == null && actual == null)
323:                    return;
324:                if (message == null)
325:                    message = "";
326:                assertNotNull(message + "(expected)", expected);
327:                assertNotNull(message + "(actual)", actual);
328:                assertNotNull(message + "(expected)", expected);
329:                assertTrue(message, expected.equalsExact(actual));
330:            }
331:
332:            protected void assertEquals(String message, int[] expected,
333:                    int actual[]) {
334:                if (expected == null && actual == null)
335:                    return;
336:                if (message == null)
337:                    message = "array";
338:                assertNotNull(message, expected);
339:                assertNotNull(message, actual);
340:                assertEquals(expected.length, actual.length);
341:                for (int i = 0; i < expected.length; i++) {
342:                    assertEquals(message + ":" + i, expected[i], actual[i]);
343:                }
344:            }
345:
346:            protected void assertEquals(String message, double[] expected,
347:                    double actual[]) {
348:                if (expected == null && actual == null)
349:                    return;
350:                if (message == null)
351:                    message = "array";
352:                assertNotNull(message, expected);
353:                assertNotNull(message, actual);
354:                assertEquals(expected.length, actual.length);
355:                for (int i = 0; i < expected.length; i++) {
356:                    assertEquals(message + ":" + i, expected[i], actual[i], 0.0);
357:                }
358:            }
359:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.