1 /* 2 * Copyright (c) 2016 Vivid Solutions. 3 * 4 * All rights reserved. This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * and Eclipse Distribution License v. 1.0 which accompanies this distribution. 7 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html 8 * and the Eclipse Distribution License is available at 9 * 10 * http://www.eclipse.org/org/documents/edl-v10.php. 11 */ 12 package org.locationtech.jts.io.oracle; 13 14 import java.sql.SQLException; 15 16 import org.locationtech.jts.generator.GridGenerator; 17 import org.locationtech.jts.generator.PointGenerator; 18 import org.locationtech.jts.geom.*; 19 import org.locationtech.jts.io.oracle.OraReader; 20 import org.locationtech.jts.io.oracle.OraWriter; 21 22 import oracle.sql.STRUCT; 23 24 25 /** 26 * 27 * Does round trip testing by creating the oracle object, then decoding it. 28 * 29 * These tests do not include insert / delete / select operations. 30 * 31 * @author David Zwiers, Vivid Solutions. 32 */ 33 public class StaticPointTest extends ConnectedTestCase { 34 35 /** 36 * @param arg 37 */ StaticPointTest(String arg)38 public StaticPointTest(String arg) { 39 super(arg); 40 } 41 42 /** 43 * Round Trip test for a single point 44 * @throws SQLException 45 */ testSinglePointRoundTrip()46 public void testSinglePointRoundTrip() throws SQLException{ 47 PointGenerator pg = new PointGenerator(); 48 pg.setGeometryFactory(geometryFactory); 49 pg.setBoundingBox(new Envelope(0,10,0,10)); 50 51 Point pt = (Point) pg.create(); 52 53 OraWriter ow = new OraWriter(); 54 STRUCT st = ow.write(pt, getConnection()); 55 56 OraReader or = new OraReader(); 57 Point pt2 = (Point) or.read(st); 58 59 // System.out.println((pt==null?"NULL":pt.toString())); 60 // System.out.println((pt2==null?"NULL":pt2.toString())); 61 assertTrue("The input Point is not the same as the output Point",pt.equals(pt2)); 62 } 63 64 /** 65 * Round Trip test for a 100 non overlapping points 66 * @throws SQLException 67 */ testGridPointsRoundTrip()68 public void testGridPointsRoundTrip() throws SQLException{ 69 GridGenerator grid = new GridGenerator(); 70 grid.setGeometryFactory(geometryFactory); 71 grid.setBoundingBox(new Envelope(0,10,0,10)); 72 grid.setNumberColumns(10); 73 grid.setNumberRows(10); 74 75 Point[] pt = new Point[100]; 76 STRUCT[] st = new STRUCT[100]; 77 78 PointGenerator pg = new PointGenerator(); 79 pg.setGeometryFactory(geometryFactory); 80 OraWriter ow = new OraWriter(); 81 82 int i=0; 83 while(grid.canCreate() && i<100){ 84 pg.setBoundingBox(grid.createEnv()); 85 pt[i] = (Point) pg.create(); 86 st[i] = ow.write(pt[i], getConnection()); 87 i++; 88 } 89 90 OraReader or = new OraReader(); 91 i=0; 92 while(i<100 && pt[i] != null){ 93 Point pt2 = (Point) or.read(st[i]); 94 // System.out.println((pt[i]==null?"NULL":pt[i].toString())); 95 // System.out.println((pt2==null?"NULL":pt2.toString())); 96 assertTrue("The input Point is not the same as the output Point",pt[i].equals(pt2)); 97 i++; 98 } 99 } 100 101 /** 102 * Round Trip test for a 8 overlapping points (4 distinct points) 103 * @throws SQLException 104 */ testOverlappingPointsRoundTrip()105 public void testOverlappingPointsRoundTrip() throws SQLException{ 106 GridGenerator grid = new GridGenerator(); 107 grid.setGeometryFactory(geometryFactory); 108 grid.setBoundingBox(new Envelope(0,10,0,10)); 109 grid.setNumberColumns(2); 110 grid.setNumberRows(2); 111 112 Point[] pt = new Point[4]; 113 STRUCT[] st = new STRUCT[8]; 114 115 PointGenerator pg = new PointGenerator(); 116 pg.setGeometryFactory(geometryFactory); 117 OraWriter ow = new OraWriter(); 118 119 int i=0; 120 while(grid.canCreate() && i<8){ 121 pg.setBoundingBox(grid.createEnv()); 122 pt[i] = (Point) pg.create(); 123 st[i] = ow.write(pt[i], getConnection()); 124 i++; 125 } 126 for(int j=0;j<4;j++){ 127 if(pt[j]!=null) 128 st[i++] = ow.write(pt[j], getConnection()); 129 } 130 131 OraReader or = new OraReader(); 132 i=0; 133 while(i<8 && pt[i%4] != null){ 134 Point pt2 = (Point) or.read(st[i]); 135 // System.out.println((pt[i]==null?"NULL":pt[i].toString())); 136 // System.out.println((pt2==null?"NULL":pt2.toString())); 137 assertTrue("The input Point is not the same as the output Point",pt[i%4].equals(pt2)); 138 i++; 139 } 140 } 141 } 142