HHH-6511 Adds Postgis integration tests.
The integration tests now make us of the matrix testing set-up.
This commit is contained in:
parent
0c0a5e2af0
commit
f114ca2944
|
@ -1,12 +1,13 @@
|
|||
apply plugin: 'java'
|
||||
apply plugin: org.hibernate.build.gradle.testing.matrix.MatrixTestingPlugin
|
||||
|
||||
dependencies {
|
||||
compile( project( ':hibernate-core' ) )
|
||||
compile( [group: 'com.vividsolutions', name: 'jts', version: '1.11'] ) {
|
||||
transitive = false
|
||||
}
|
||||
compile( [group: 'org.postgis', name: 'postgis-jdbc', version: '1.1.6'] )
|
||||
compile( [group: 'postgresql', name: 'postgresql', version: '8.1-407.jdbc3'] )
|
||||
compile( [group: 'org.postgis', name: 'postgis-jdbc', version: '1.5.3'] )
|
||||
compile( [group: 'postgresql', name: 'postgresql', version: '8.4-701.jdbc4'] )
|
||||
|
||||
|
||||
compile( libraries.dom4j ) {
|
||||
|
@ -22,6 +23,8 @@ dependencies {
|
|||
testCompile( [group: 'commons-dbcp', name: 'commons-dbcp', version: '1.4'])
|
||||
testCompile([group: 'com.oracle.jdbc', name:'ojdbc6', version:'11.1.0.7.0'])
|
||||
testCompile([group: 'com.microsoft', name: 'sqljdbc', version: '2.0'])
|
||||
|
||||
matrixRuntime( 'jaxen:jaxen:1.1' )
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
|
@ -31,4 +34,13 @@ sourceSets {
|
|||
setSrcDirs( ['src/test/java','src/test/resources'] )
|
||||
}
|
||||
}
|
||||
matrix {
|
||||
java {
|
||||
srcDir 'src/matrix/java'
|
||||
}
|
||||
resources {
|
||||
srcDir 'src/matrix/resources'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.test;
|
||||
package org.hibernate.spatial.integration;
|
||||
|
||||
import java.sql.Blob;
|
||||
import java.sql.Connection;
|
|
@ -23,23 +23,7 @@
|
|||
* For more information, visit: http://www.hibernate.spatial.org/
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.test;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringWriter;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import javax.sql.DataSource;
|
||||
package org.hibernate.spatial.integration;
|
||||
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
import com.vividsolutions.jts.io.ParseException;
|
||||
|
@ -47,6 +31,13 @@ import org.apache.commons.dbcp.BasicDataSource;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.io.*;
|
||||
import java.sql.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* <p>Unit testsuite-suite support class.</p>
|
||||
*
|
|
@ -39,7 +39,7 @@
|
|||
*/
|
||||
|
||||
|
||||
package org.hibernate.spatial.test;
|
||||
package org.hibernate.spatial.integration;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
|
@ -23,7 +23,7 @@
|
|||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.test;
|
||||
package org.hibernate.spatial.integration;
|
||||
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
import com.vividsolutions.jts.io.ParseException;
|
|
@ -23,7 +23,7 @@
|
|||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.test;
|
||||
package org.hibernate.spatial.integration;
|
||||
|
||||
import com.vividsolutions.jts.geom.Coordinate;
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
|
@ -23,7 +23,7 @@
|
|||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.test;
|
||||
package org.hibernate.spatial.integration;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
|
@ -23,7 +23,7 @@
|
|||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.test;
|
||||
package org.hibernate.spatial.integration;
|
||||
|
||||
/**
|
||||
* <code>SQLExpressoinTemplate</code>s generate database-specific
|
|
@ -0,0 +1,16 @@
|
|||
package org.hibernate.spatial.integration;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.testing.Skip;
|
||||
|
||||
/**
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
* creation-date: 1/13/12
|
||||
*/
|
||||
public class SpatialDialectMatcher implements Skip.Matcher {
|
||||
@Override
|
||||
public boolean isMatch() {
|
||||
return !(Dialect.getDialect() instanceof SpatialDialect);
|
||||
}
|
||||
}
|
|
@ -1,28 +1,21 @@
|
|||
package org.hibernate.spatial;
|
||||
package org.hibernate.spatial.integration;
|
||||
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.spatial.test.AbstractExpectationsFactory;
|
||||
import org.hibernate.spatial.test.DataSourceUtils;
|
||||
import org.hibernate.spatial.test.GeometryEquality;
|
||||
import org.hibernate.spatial.test.TestData;
|
||||
import org.hibernate.spatial.test.TestSupport;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Karel Maesen, Geovise BVBA
|
|
@ -23,7 +23,7 @@
|
|||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.test;
|
||||
package org.hibernate.spatial.integration;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Collection;
|
|
@ -23,7 +23,7 @@
|
|||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.test;
|
||||
package org.hibernate.spatial.integration;
|
||||
|
||||
/**
|
||||
* A <code>TestDataElement</code> captures the information necessary to build a testsuite-suite geometry.
|
|
@ -23,7 +23,7 @@
|
|||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.test;
|
||||
package org.hibernate.spatial.integration;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
|
@ -1,4 +1,4 @@
|
|||
package org.hibernate.spatial.test;
|
||||
package org.hibernate.spatial.integration;
|
||||
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
|
|
@ -23,24 +23,27 @@
|
|||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial;
|
||||
package org.hibernate.spatial.integration;
|
||||
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
import org.hibernate.testing.Skip;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
|
||||
/**
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
*/
|
||||
@Skip(condition = SpatialDialectMatcher.class,message = "No Spatial Dialect")
|
||||
public class TestSpatialFunctions extends SpatialFunctionalTestCase {
|
||||
|
||||
private static Logger LOGGER = LoggerFactory.getLogger( TestSpatialFunctions.class );
|
||||
|
@ -57,6 +60,7 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
public void testSpatialFunctions() throws Exception {
|
||||
if (! (getDialect() instanceof SpatialDialect)) return;
|
||||
dimension();
|
||||
astext();
|
||||
asbinary();
|
|
@ -23,26 +23,28 @@
|
|||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
package org.hibernate.spatial.integration;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.criterion.Criterion;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
import org.hibernate.spatial.criterion.SpatialRestrictions;
|
||||
import org.hibernate.spatial.test.GeomEntity;
|
||||
import org.hibernate.testing.Skip;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@Skip(condition = SpatialDialectMatcher.class,message = "No Spatial Dialect")
|
||||
public class TestSpatialRestrictions extends SpatialFunctionalTestCase {
|
||||
|
||||
private static Logger LOGGER = LoggerFactory.getLogger( TestSpatialRestrictions.class );
|
||||
|
@ -64,6 +66,7 @@ public class TestSpatialRestrictions extends SpatialFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
public void testRestrictions() throws Exception {
|
||||
if (! (getDialect() instanceof SpatialDialect)) return;
|
||||
within();
|
||||
filter();
|
||||
contains();
|
|
@ -23,23 +23,22 @@
|
|||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
package org.hibernate.spatial.integration;
|
||||
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
import com.vividsolutions.jts.io.ParseException;
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.testing.Skip;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.spatial.test.GeomEntity;
|
||||
import org.hibernate.spatial.test.TestDataElement;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
@ -49,6 +48,7 @@ import static org.junit.Assert.assertTrue;
|
|||
* This testsuite-suite class verifies whether the <code>Geometry</code>s retrieved
|
||||
* are equal to the <code>Geometry</code>s stored.
|
||||
*/
|
||||
@Skip(condition = SpatialDialectMatcher.class,message = "No Spatial Dialect")
|
||||
public class TestStoreRetrieve extends SpatialFunctionalTestCase {
|
||||
|
||||
private static Logger LOGGER = LoggerFactory.getLogger( TestStoreRetrieve.class );
|
||||
|
@ -61,6 +61,7 @@ public class TestStoreRetrieve extends SpatialFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
public void testStoreRetrieve() throws ParseException {
|
||||
if (! (getDialect() instanceof SpatialDialect)) return;
|
||||
Map<Integer, GeomEntity> stored = new HashMap<Integer, GeomEntity>();
|
||||
//check whether we retrieve exactly what we store
|
||||
storeTestObjects( stored );
|
|
@ -1,4 +1,4 @@
|
|||
package org.hibernate.spatial.test;
|
||||
package org.hibernate.spatial.integration;
|
||||
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
|
@ -1,7 +1,6 @@
|
|||
package org.hibernate.spatial;
|
||||
package org.hibernate.spatial.integration;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.spatial.test.TestSupport;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -44,20 +43,20 @@ public class TestSupportFactories {
|
|||
private static String getSupportFactoryClassName(Dialect dialect) {
|
||||
String canonicalName = dialect.getClass().getCanonicalName();
|
||||
if ( "org.hibernate.spatial.dialect.postgis.PostgisDialect".equals( canonicalName ) ) {
|
||||
return "org.hibernate.spatial.dialect.postgis.PostgisTestSupport";
|
||||
return "org.hibernate.spatial.integration.dialects.postgis.PostgisTestSupport";
|
||||
}
|
||||
// if ("org.hibernate.spatial.geodb.GeoDBDialect".equals(canonicalName)) {
|
||||
// return "org.hibernate.spatial.geodb.GeoDBSupport";
|
||||
// }
|
||||
if ("org.hibernate.spatial.dialect.sqlserver.SqlServer2008SpatialDialect".equals(canonicalName)) {
|
||||
return "org.hibernate.spatial.dialect.sqlserver.SQLServerTestSupport";
|
||||
return "org.hibernate.spatial.integration.dialects.sqlserver.SQLServerTestSupport";
|
||||
}
|
||||
// if ("org.hibernatespatial.mysql.MySQLSpatialDialect".equals(canonicalName) ||
|
||||
// "org.hibernatespatial.mysql.MySQLSpatialInnoDBDialect".equals(canonicalName)) {
|
||||
// return "org.hibernatespatial.mysql.MySQLTestSupport";
|
||||
// }
|
||||
if ( "org.hibernate.spatial.dialect.oracle.OracleSpatial10gDialect".equals( canonicalName ) ) {
|
||||
return "org.hibernate.spatial.dialect.oracle.OracleSDOTestSupport";
|
||||
return "org.hibernate.spatial.integration.dialects.oracle.OracleSDOTestSupport";
|
||||
}
|
||||
throw new IllegalArgumentException( "Dialect not known in test suite" );
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.hibernatespatial.oracle;
|
||||
package org.hibernate.spatial.integration.dialects.oracle;
|
||||
|
||||
import java.sql.Array;
|
||||
import java.sql.Blob;
|
|
@ -1,11 +1,11 @@
|
|||
package org.hibernate.spatial.dialect.oracle;
|
||||
package org.hibernate.spatial.integration.dialects.oracle;
|
||||
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.spatial.test.AbstractExpectationsFactory;
|
||||
import org.hibernate.spatial.test.DataSourceUtils;
|
||||
import org.hibernate.spatial.test.SQLExpressionTemplate;
|
||||
import org.hibernate.spatial.test.TestData;
|
||||
import org.hibernate.spatial.test.TestSupport;
|
||||
import org.hibernate.spatial.integration.AbstractExpectationsFactory;
|
||||
import org.hibernate.spatial.integration.DataSourceUtils;
|
||||
import org.hibernate.spatial.integration.SQLExpressionTemplate;
|
||||
import org.hibernate.spatial.integration.TestData;
|
||||
import org.hibernate.spatial.integration.TestSupport;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
/**
|
|
@ -23,12 +23,12 @@
|
|||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.dialect.oracle;
|
||||
package org.hibernate.spatial.integration.dialects.oracle;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.hibernate.spatial.test.DataSourceUtils;
|
||||
import org.hibernate.spatial.test.SQLExpressionTemplate;
|
||||
import org.hibernate.spatial.integration.DataSourceUtils;
|
||||
import org.hibernate.spatial.integration.SQLExpressionTemplate;
|
||||
|
||||
|
||||
public class SDODataSourceUtils extends DataSourceUtils {
|
|
@ -23,14 +23,15 @@
|
|||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.dialect.oracle;
|
||||
package org.hibernate.spatial.integration.dialects.oracle;
|
||||
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
import com.vividsolutions.jts.geom.Point;
|
||||
|
||||
import org.hibernate.spatial.test.AbstractExpectationsFactory;
|
||||
import org.hibernate.spatial.test.DataSourceUtils;
|
||||
import org.hibernate.spatial.test.NativeSQLStatement;
|
||||
import org.hibernate.spatial.dialect.oracle.SDOGeometryValueExtractor;
|
||||
import org.hibernate.spatial.integration.AbstractExpectationsFactory;
|
||||
import org.hibernate.spatial.integration.DataSourceUtils;
|
||||
import org.hibernate.spatial.integration.NativeSQLStatement;
|
||||
|
||||
/**
|
||||
* Expectations factory for Oracle 10g (SDOGeometry).
|
|
@ -23,10 +23,10 @@
|
|||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.dialect.oracle;
|
||||
package org.hibernate.spatial.integration.dialects.oracle;
|
||||
|
||||
import org.hibernate.spatial.test.SQLExpressionTemplate;
|
||||
import org.hibernate.spatial.test.TestDataElement;
|
||||
import org.hibernate.spatial.integration.SQLExpressionTemplate;
|
||||
import org.hibernate.spatial.integration.TestDataElement;
|
||||
|
||||
public class SDOGeometryExpressionTemplate implements SQLExpressionTemplate {
|
||||
|
|
@ -23,10 +23,10 @@
|
|||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.dialect.oracle;
|
||||
package org.hibernate.spatial.integration.dialects.oracle;
|
||||
|
||||
|
||||
import org.hibernate.spatial.test.TestDataElement;
|
||||
import org.hibernate.spatial.integration.TestDataElement;
|
||||
|
||||
/**
|
||||
* A specialised subclass for SDOGeometry test objects
|
|
@ -23,14 +23,14 @@
|
|||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.dialect.oracle;
|
||||
package org.hibernate.spatial.integration.dialects.oracle;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.dom4j.Element;
|
||||
|
||||
import org.hibernate.spatial.test.TestDataElement;
|
||||
import org.hibernate.spatial.test.TestDataReader;
|
||||
import org.hibernate.spatial.integration.TestDataElement;
|
||||
import org.hibernate.spatial.integration.TestDataReader;
|
||||
|
||||
|
||||
public class SDOTestDataReader extends TestDataReader {
|
|
@ -23,14 +23,15 @@
|
|||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.dialect.postgis;
|
||||
package org.hibernate.spatial.integration.dialects.postgis;
|
||||
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
import com.vividsolutions.jts.geom.Point;
|
||||
|
||||
import org.hibernate.spatial.test.AbstractExpectationsFactory;
|
||||
import org.hibernate.spatial.test.DataSourceUtils;
|
||||
import org.hibernate.spatial.test.NativeSQLStatement;
|
||||
import org.hibernate.spatial.dialect.postgis.PGGeometryValueExtractor;
|
||||
import org.hibernate.spatial.integration.AbstractExpectationsFactory;
|
||||
import org.hibernate.spatial.integration.DataSourceUtils;
|
||||
import org.hibernate.spatial.integration.NativeSQLStatement;
|
||||
|
||||
/**
|
||||
* This class provides the expected return values to the testsuite-suite classes in this package.
|
|
@ -23,10 +23,10 @@
|
|||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.dialect.postgis;
|
||||
package org.hibernate.spatial.integration.dialects.postgis;
|
||||
|
||||
import org.hibernate.spatial.test.SQLExpressionTemplate;
|
||||
import org.hibernate.spatial.test.TestDataElement;
|
||||
import org.hibernate.spatial.integration.SQLExpressionTemplate;
|
||||
import org.hibernate.spatial.integration.TestDataElement;
|
||||
|
||||
/**
|
||||
* The template for postgis insert SQL
|
|
@ -1,11 +1,11 @@
|
|||
package org.hibernate.spatial.dialect.postgis;
|
||||
package org.hibernate.spatial.integration.dialects.postgis;
|
||||
|
||||
|
||||
import org.hibernate.spatial.test.AbstractExpectationsFactory;
|
||||
import org.hibernate.spatial.test.DataSourceUtils;
|
||||
import org.hibernate.spatial.test.SQLExpressionTemplate;
|
||||
import org.hibernate.spatial.test.TestData;
|
||||
import org.hibernate.spatial.test.TestSupport;
|
||||
import org.hibernate.spatial.integration.AbstractExpectationsFactory;
|
||||
import org.hibernate.spatial.integration.DataSourceUtils;
|
||||
import org.hibernate.spatial.integration.SQLExpressionTemplate;
|
||||
import org.hibernate.spatial.integration.TestData;
|
||||
import org.hibernate.spatial.integration.TestSupport;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
/**
|
||||
|
@ -29,7 +29,7 @@ public class PostgisTestSupport extends TestSupport {
|
|||
|
||||
@Override
|
||||
public SQLExpressionTemplate getSQLExpressionTemplate() {
|
||||
return new org.hibernate.spatial.dialect.postgis.PostgisExpressionTemplate();
|
||||
return new PostgisExpressionTemplate();
|
||||
}
|
||||
|
||||
|
|
@ -23,10 +23,10 @@
|
|||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.dialect.sqlserver;
|
||||
package org.hibernate.spatial.integration.dialects.sqlserver;
|
||||
|
||||
import org.hibernate.spatial.test.SQLExpressionTemplate;
|
||||
import org.hibernate.spatial.test.TestDataElement;
|
||||
import org.hibernate.spatial.integration.SQLExpressionTemplate;
|
||||
import org.hibernate.spatial.integration.TestDataElement;
|
||||
|
||||
/**
|
||||
* @author Karel Maesen, Geovise BVBA
|
|
@ -1,9 +1,9 @@
|
|||
package org.hibernate.spatial.dialect.sqlserver;
|
||||
package org.hibernate.spatial.integration.dialects.sqlserver;
|
||||
|
||||
import org.hibernate.spatial.test.DataSourceUtils;
|
||||
import org.hibernate.spatial.test.SQLExpressionTemplate;
|
||||
import org.hibernate.spatial.test.TestData;
|
||||
import org.hibernate.spatial.test.TestSupport;
|
||||
import org.hibernate.spatial.integration.DataSourceUtils;
|
||||
import org.hibernate.spatial.integration.SQLExpressionTemplate;
|
||||
import org.hibernate.spatial.integration.TestData;
|
||||
import org.hibernate.spatial.integration.TestSupport;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
/**
|
|
@ -23,15 +23,15 @@
|
|||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.dialect.sqlserver;
|
||||
package org.hibernate.spatial.integration.dialects.sqlserver;
|
||||
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
import com.vividsolutions.jts.geom.Point;
|
||||
|
||||
import org.hibernate.spatial.dialect.sqlserver.convertors.Decoders;
|
||||
import org.hibernate.spatial.test.AbstractExpectationsFactory;
|
||||
import org.hibernate.spatial.test.DataSourceUtils;
|
||||
import org.hibernate.spatial.test.NativeSQLStatement;
|
||||
import org.hibernate.spatial.integration.AbstractExpectationsFactory;
|
||||
import org.hibernate.spatial.integration.DataSourceUtils;
|
||||
import org.hibernate.spatial.integration.NativeSQLStatement;
|
||||
|
||||
|
||||
/**
|
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* $Id: AbstractConvertorTest.java 278 2010-12-18 14:03:32Z maesenka $
|
||||
*
|
||||
* This file is part of Hibernate Spatial, an extension to the
|
||||
* hibernate ORM solution for geographic data.
|
||||
*
|
||||
* Copyright © 2007-2010 Geovise BVBA
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
package org.hibernate.spatial.integration.dialects.sqlserver.convertors;
|
||||
|
||||
/**
|
||||
* @author Karel Maesen, Geovise BVBA.
|
||||
* Date: Nov 2, 2009
|
||||
*/
|
||||
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
import org.hibernate.spatial.dialect.sqlserver.convertors.Decoders;
|
||||
import org.hibernate.spatial.dialect.sqlserver.convertors.Encoders;
|
||||
import org.hibernate.spatial.dialect.sqlserver.convertors.OpenGisType;
|
||||
import org.hibernate.spatial.integration.DataSourceUtils;
|
||||
import org.hibernate.spatial.integration.SpatialFunctionalTestCase;
|
||||
import org.hibernate.spatial.integration.TestData;
|
||||
import org.hibernate.spatial.integration.TestSupport;
|
||||
import org.hibernate.spatial.integration.dialects.sqlserver.SQLServerExpressionTemplate;
|
||||
import org.hibernate.spatial.integration.dialects.sqlserver.SQLServerTestSupport;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Karel Maesen, Geovise BVBA.
|
||||
* Date: Nov 2, 2009
|
||||
*/
|
||||
public abstract class AbstractConvertorTest extends SpatialFunctionalTestCase {
|
||||
|
||||
private DataSourceUtils dataSourceUtils;
|
||||
|
||||
private final static TestSupport support = new SQLServerTestSupport();
|
||||
|
||||
Map<Integer, Geometry> decodedGeoms;
|
||||
Map<Integer, Object> rawResults;
|
||||
Map<Integer, byte[]> encodedGeoms;
|
||||
Map<Integer, Geometry> expectedGeoms;
|
||||
|
||||
|
||||
public void beforeClass() {
|
||||
dataSourceUtils = new DataSourceUtils(
|
||||
"sqlserver/hibernate-spatial-sqlserver-test.properties",
|
||||
new SQLServerExpressionTemplate()
|
||||
);
|
||||
try {
|
||||
String sql = dataSourceUtils.parseSqlIn("sqlserver/create-sqlserver-test-schema.sql");
|
||||
dataSourceUtils.executeStatement(sql);
|
||||
TestData testData = support.createTestData(null);
|
||||
dataSourceUtils.insertTestData(testData);
|
||||
}catch(SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void afterClass() {
|
||||
try {
|
||||
String sql = dataSourceUtils.parseSqlIn("sqlserver/drop-sqlserver-test-schema.sql");
|
||||
dataSourceUtils.executeStatement(sql);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void doDecoding(OpenGisType type) {
|
||||
rawResults = dataSourceUtils.rawDbObjects(type.toString());
|
||||
TestData testData = support.createTestData(null);
|
||||
expectedGeoms = dataSourceUtils.expectedGeoms(type.toString(), testData);
|
||||
decodedGeoms = new HashMap<Integer, Geometry>();
|
||||
|
||||
for (Integer id : rawResults.keySet()) {
|
||||
Geometry geometry = Decoders.decode((byte[]) rawResults.get(id));
|
||||
decodedGeoms.put(id, geometry);
|
||||
}
|
||||
}
|
||||
|
||||
public void doEncoding() {
|
||||
encodedGeoms = new HashMap<Integer, byte[]>();
|
||||
for (Integer id : decodedGeoms.keySet()) {
|
||||
Geometry geom = decodedGeoms.get(id);
|
||||
byte[] bytes = Encoders.encode(geom);
|
||||
encodedGeoms.put(id, bytes);
|
||||
}
|
||||
}
|
||||
|
||||
public void test_encoding() {
|
||||
for (Integer id : encodedGeoms.keySet()) {
|
||||
assertTrue(
|
||||
"Wrong encoding for case " + id,
|
||||
Arrays.equals((byte[]) rawResults.get(id), encodedGeoms.get(id))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public void test_decoding() {
|
||||
for (Integer id : decodedGeoms.keySet()) {
|
||||
Geometry expected = expectedGeoms.get(id);
|
||||
Geometry received = decodedGeoms.get(id);
|
||||
assertTrue("Wrong decoding for case " + id, expected.equalsExact(received));
|
||||
}
|
||||
}
|
||||
|
||||
//TODO -- add logger.
|
||||
@Override
|
||||
protected Logger getLogger() {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
}
|
|
@ -23,9 +23,13 @@
|
|||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.dialect.sqlserver.convertors;
|
||||
package org.hibernate.spatial.integration.dialects.sqlserver.convertors;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.hibernate.spatial.dialect.sqlserver.SqlServer2008SpatialDialect;
|
||||
import org.hibernate.spatial.dialect.sqlserver.convertors.OpenGisType;
|
||||
import org.hibernate.testing.AfterClassOnce;
|
||||
import org.hibernate.testing.BeforeClassOnce;
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
|
@ -35,11 +39,13 @@ import org.junit.Test;
|
|||
* Time: 5:33:19 PM
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
@RequiresDialect(value=SqlServer2008SpatialDialect.class)
|
||||
public class GeometryCollectionConvertorTest extends AbstractConvertorTest {
|
||||
|
||||
@Before
|
||||
@BeforeClassOnce
|
||||
public void setUp() {
|
||||
doDecoding( OpenGisType.GEOMETRYCOLLECTION );
|
||||
super.beforeClass();
|
||||
doDecoding(OpenGisType.GEOMETRYCOLLECTION);
|
||||
doEncoding();
|
||||
}
|
||||
|
||||
|
@ -53,4 +59,9 @@ public class GeometryCollectionConvertorTest extends AbstractConvertorTest {
|
|||
super.test_decoding();
|
||||
}
|
||||
|
||||
@AfterClassOnce
|
||||
public void afterClass(){
|
||||
super.afterClass();
|
||||
}
|
||||
|
||||
}
|
|
@ -23,22 +23,25 @@
|
|||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.dialect.sqlserver.convertors;
|
||||
package org.hibernate.spatial.integration.dialects.sqlserver.convertors;
|
||||
|
||||
import com.vividsolutions.jts.geom.Coordinate;
|
||||
import com.vividsolutions.jts.geom.LineString;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.spatial.dialect.sqlserver.SqlServer2008SpatialDialect;
|
||||
import org.hibernate.spatial.dialect.sqlserver.convertors.OpenGisType;
|
||||
import org.hibernate.spatial.mgeom.MCoordinate;
|
||||
import org.hibernate.testing.BeforeClassOnce;
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.junit.Test;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RequiresDialect(SqlServer2008SpatialDialect.class)
|
||||
public class LineStringConvertorTest extends AbstractConvertorTest {
|
||||
|
||||
@Before
|
||||
@BeforeClassOnce
|
||||
public void setUp() {
|
||||
doDecoding( OpenGisType.LINESTRING );
|
||||
doEncoding();
|
|
@ -23,14 +23,18 @@
|
|||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.dialect.sqlserver.convertors;
|
||||
package org.hibernate.spatial.integration.dialects.sqlserver.convertors;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.hibernate.spatial.dialect.sqlserver.SqlServer2008SpatialDialect;
|
||||
import org.hibernate.spatial.dialect.sqlserver.convertors.OpenGisType;
|
||||
import org.hibernate.testing.BeforeClassOnce;
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.junit.Test;
|
||||
|
||||
@RequiresDialect(SqlServer2008SpatialDialect.class)
|
||||
public class MultiLineStringConvertorTest extends AbstractConvertorTest {
|
||||
|
||||
@Before
|
||||
@BeforeClassOnce
|
||||
public void setUp() {
|
||||
doDecoding( OpenGisType.MULTILINESTRING );
|
||||
doEncoding();
|
|
@ -23,14 +23,18 @@
|
|||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.dialect.sqlserver.convertors;
|
||||
package org.hibernate.spatial.integration.dialects.sqlserver.convertors;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.hibernate.spatial.dialect.sqlserver.SqlServer2008SpatialDialect;
|
||||
import org.hibernate.spatial.dialect.sqlserver.convertors.OpenGisType;
|
||||
import org.hibernate.testing.BeforeClassOnce;
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.junit.Test;
|
||||
|
||||
@RequiresDialect(SqlServer2008SpatialDialect.class)
|
||||
public class MultiPointConvertorTest extends AbstractConvertorTest {
|
||||
|
||||
@Before
|
||||
@BeforeClassOnce
|
||||
public void setUp() {
|
||||
doDecoding( OpenGisType.MULTIPOINT );
|
||||
doEncoding();
|
|
@ -23,14 +23,18 @@
|
|||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.dialect.sqlserver.convertors;
|
||||
package org.hibernate.spatial.integration.dialects.sqlserver.convertors;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.hibernate.spatial.dialect.sqlserver.SqlServer2008SpatialDialect;
|
||||
import org.hibernate.spatial.dialect.sqlserver.convertors.OpenGisType;
|
||||
import org.hibernate.testing.BeforeClassOnce;
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.junit.Test;
|
||||
|
||||
@RequiresDialect(SqlServer2008SpatialDialect.class)
|
||||
public class MultiPolygonConvertorTest extends AbstractConvertorTest {
|
||||
|
||||
@Before
|
||||
@BeforeClassOnce
|
||||
public void setUp() {
|
||||
doDecoding( OpenGisType.MULTIPOLYGON );
|
||||
doEncoding();
|
|
@ -23,14 +23,16 @@
|
|||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.dialect.sqlserver.convertors;
|
||||
package org.hibernate.spatial.integration.dialects.sqlserver.convertors;
|
||||
|
||||
import com.vividsolutions.jts.geom.Coordinate;
|
||||
import com.vividsolutions.jts.geom.Point;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.spatial.dialect.sqlserver.SqlServer2008SpatialDialect;
|
||||
import org.hibernate.spatial.dialect.sqlserver.convertors.OpenGisType;
|
||||
import org.hibernate.spatial.mgeom.MCoordinate;
|
||||
import org.hibernate.testing.BeforeClassOnce;
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.junit.Test;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
|
@ -38,9 +40,10 @@ import static junit.framework.Assert.assertEquals;
|
|||
* @author Karel Maesen, Geovise BVBA.
|
||||
* Date: Nov 2, 2009
|
||||
*/
|
||||
@RequiresDialect(SqlServer2008SpatialDialect.class)
|
||||
public class PointConvertorTest extends AbstractConvertorTest {
|
||||
|
||||
@Before
|
||||
@BeforeClassOnce
|
||||
public void setup() {
|
||||
doDecoding( OpenGisType.POINT );
|
||||
doEncoding();
|
|
@ -23,15 +23,19 @@
|
|||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.dialect.sqlserver.convertors;
|
||||
package org.hibernate.spatial.integration.dialects.sqlserver.convertors;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.hibernate.spatial.dialect.sqlserver.SqlServer2008SpatialDialect;
|
||||
import org.hibernate.spatial.dialect.sqlserver.convertors.OpenGisType;
|
||||
import org.hibernate.testing.BeforeClassOnce;
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.junit.Test;
|
||||
|
||||
@RequiresDialect(SqlServer2008SpatialDialect.class)
|
||||
public class PolygonConvertorTest extends AbstractConvertorTest {
|
||||
|
||||
|
||||
@Before
|
||||
@BeforeClassOnce
|
||||
public void setUp() {
|
||||
doDecoding( OpenGisType.POLYGON );
|
||||
doEncoding();
|
|
@ -0,0 +1,42 @@
|
|||
<?xml version="1.0"?>
|
||||
<!--
|
||||
~ $Id: GeomEntity.hbm.xml 242 2010-09-22 20:40:07Z maesenka $
|
||||
~
|
||||
~ This file is part of Hibernate Spatial, an extension to the
|
||||
~ hibernate ORM solution for geographic data.
|
||||
~
|
||||
~ Copyright © 2007-2010 Geovise BVBA
|
||||
~
|
||||
~ This library is free software; you can redistribute it and/or
|
||||
~ modify it under the terms of the GNU Lesser General Public
|
||||
~ License as published by the Free Software Foundation; either
|
||||
~ version 2.1 of the License, or (at your option) any later version.
|
||||
~
|
||||
~ This library is distributed in the hope that it will be useful,
|
||||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
~ Lesser General Public License for more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU Lesser General Public
|
||||
~ License along with this library; if not, write to the Free Software
|
||||
~ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
~
|
||||
~ For more information, visit: http://www.hibernatespatial.org/
|
||||
-->
|
||||
|
||||
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
" http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<hibernate-mapping>
|
||||
<class name="org.hibernate.spatial.integration.GeomEntity" table="GEOMTEST">
|
||||
<id name="id" type="integer">
|
||||
<generator class="assigned"/>
|
||||
</id>
|
||||
<property name="type" type="string">
|
||||
<column name="type" length="50"/>
|
||||
</property>
|
||||
<property name="geom" type="org.hibernate.spatial.GeometryType">
|
||||
<column name="geom"/>
|
||||
</property>
|
||||
</class>
|
||||
</hibernate-mapping>
|
|
@ -0,0 +1,9 @@
|
|||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.Target=System.out
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
|
||||
|
||||
|
||||
log4j.rootLogger=info, stdout
|
||||
|
||||
log4j.logger.org.hibernate.spatial=debug
|
|
@ -26,7 +26,7 @@
|
|||
*
|
||||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
package org.hibernate.spatial.test;
|
||||
package org.hibernate.spatial;
|
||||
|
||||
import com.vividsolutions.jts.geom.Coordinate;
|
||||
import org.junit.Test;
|
|
@ -1,4 +1,4 @@
|
|||
package org.hibernate.spatial.dialect.postgis.unittests;
|
||||
package org.hibernate.spatial.dialect.postgis;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
|
@ -1,132 +0,0 @@
|
|||
/*
|
||||
* $Id: AbstractConvertorTest.java 278 2010-12-18 14:03:32Z maesenka $
|
||||
*
|
||||
* This file is part of Hibernate Spatial, an extension to the
|
||||
* hibernate ORM solution for geographic data.
|
||||
*
|
||||
* Copyright © 2007-2010 Geovise BVBA
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.dialect.sqlserver.convertors;
|
||||
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Karel Maesen, Geovise BVBA.
|
||||
* Date: Nov 2, 2009
|
||||
*/
|
||||
public class AbstractConvertorTest {
|
||||
|
||||
private final static String TEST_DATA = "sqlserver/sqlserver-2008-test-data.ser";
|
||||
|
||||
List<ConvertorTestData> testData = readTestData();
|
||||
Map<Integer, Geometry> decodedGeoms = new HashMap<Integer, Geometry>();
|
||||
Map<Integer, Object> rawResults;
|
||||
Map<Integer, byte[]> encodedGeoms;
|
||||
Map<Integer, Geometry> expectedGeoms;
|
||||
|
||||
|
||||
|
||||
public List<ConvertorTestData> readTestData(){
|
||||
InputStream in = this.getClass().getClassLoader().getResourceAsStream(TEST_DATA);
|
||||
if (in == null) {
|
||||
throw new RuntimeException("Can't find file " + TEST_DATA);
|
||||
}
|
||||
try {
|
||||
ObjectInputStream oin = new ObjectInputStream(in);
|
||||
return (List<ConvertorTestData>)oin.readObject();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
// nothing to do
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void doDecoding(OpenGisType type) {
|
||||
List<ConvertorTestData> testData = readTestData();
|
||||
rawResults = toRawResults(testData, type.toString());
|
||||
expectedGeoms = toExpected(testData, type.toString());
|
||||
for ( Integer id : rawResults.keySet() ) {
|
||||
Geometry geometry = Decoders.decode( (byte[]) rawResults.get( id ) );
|
||||
decodedGeoms.put( id, geometry );
|
||||
}
|
||||
}
|
||||
|
||||
private Map<Integer, Geometry> toExpected(List<ConvertorTestData> testData, String type) {
|
||||
Map<Integer, Geometry> result = new HashMap<Integer, Geometry>();
|
||||
for (ConvertorTestData item : testData) {
|
||||
if (! item.type.equals(type)) continue;
|
||||
result.put(item.id, item.geometry);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Map<Integer, Object> toRawResults(List<ConvertorTestData> testData, String type) {
|
||||
Map<Integer, Object> result = new HashMap<Integer, Object>();
|
||||
for (ConvertorTestData item : testData) {
|
||||
if (! item.type.equals(type)) continue;
|
||||
result.put(item.id, item.bytes);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void doEncoding() {
|
||||
encodedGeoms = new HashMap<Integer, byte[]>();
|
||||
for ( Integer id : decodedGeoms.keySet() ) {
|
||||
Geometry geom = decodedGeoms.get( id );
|
||||
byte[] bytes = Encoders.encode( geom );
|
||||
encodedGeoms.put( id, bytes );
|
||||
}
|
||||
}
|
||||
|
||||
public void test_encoding() {
|
||||
for ( Integer id : encodedGeoms.keySet() ) {
|
||||
assertTrue(
|
||||
"Wrong encoding for case " + id,
|
||||
Arrays.equals( (byte[]) rawResults.get( id ), encodedGeoms.get( id ) )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public void test_decoding() {
|
||||
for ( Integer id : decodedGeoms.keySet() ) {
|
||||
Geometry expected = expectedGeoms.get( id );
|
||||
Geometry received = decodedGeoms.get( id );
|
||||
assertTrue( "Wrong decoding for case " + id, expected.equalsExact( received ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
package org.hibernate.spatial.dialect.sqlserver.convertors;
|
||||
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
* creation-date: 1/11/12
|
||||
*/
|
||||
public class ConvertorTestData implements Serializable {
|
||||
public Integer id;
|
||||
public String type;
|
||||
public Geometry geometry;
|
||||
public byte[] bytes;
|
||||
}
|
|
@ -1,134 +0,0 @@
|
|||
package org.hibernate.spatial.dialect.sqlserver.convertors;
|
||||
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
import org.hibernate.spatial.dialect.sqlserver.SQLServerExpressionTemplate;
|
||||
import org.hibernate.spatial.dialect.sqlserver.SQLServerTestSupport;
|
||||
import org.hibernate.spatial.test.DataSourceUtils;
|
||||
import org.hibernate.spatial.test.TestData;
|
||||
import org.hibernate.spatial.test.TestSupport;
|
||||
|
||||
import java.io.*;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A simple utitlity to generate the binary geometry objects by inserting spatial objects into a SQL Server 2008 instance,
|
||||
* and reading back the results.
|
||||
*
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
* creation-date: 1/11/12
|
||||
*/
|
||||
public class SpatialObjectGenerator {
|
||||
|
||||
private final static String TEST_DATA = "sqlserver-2008-test-data.ser";
|
||||
|
||||
private final static DataSourceUtils dataSourceUtils = new DataSourceUtils(
|
||||
"sqlserver/hibernate-spatial-sqlserver-test.properties",
|
||||
new SQLServerExpressionTemplate()
|
||||
);
|
||||
|
||||
private final static TestSupport support = new SQLServerTestSupport();
|
||||
|
||||
private final static String[] TYPES;
|
||||
|
||||
static {
|
||||
TYPES = new String[OpenGisType.values().length];
|
||||
int i = 0;
|
||||
for (OpenGisType type : OpenGisType.values()) {
|
||||
TYPES[i++] = type.toString();
|
||||
}
|
||||
}
|
||||
|
||||
private final TestData testData = support.createTestData(null);
|
||||
|
||||
public static void main(String[] argv) {
|
||||
File outFile = createOutputFile(argv);
|
||||
SpatialObjectGenerator generator = new SpatialObjectGenerator();
|
||||
try {
|
||||
generator.prepare();
|
||||
List<ConvertorTestData> result = generator.generateTestDataObjects();
|
||||
writeTo(outFile, result);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
|
||||
} finally{
|
||||
try {
|
||||
generator.discard();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void writeTo(File outFile, List<ConvertorTestData> result) {
|
||||
FileOutputStream fos = null;
|
||||
ObjectOutputStream out = null;
|
||||
|
||||
try {
|
||||
fos = new FileOutputStream(outFile);
|
||||
out = new ObjectOutputStream(fos);
|
||||
out.writeObject(result);
|
||||
out.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
System.out.printf("Wrote %d objects to %s.", result.size(), outFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
private static File createOutputFile(String[] argv) {
|
||||
String tmpDir = System.getProperty("java.io.tmpdir");
|
||||
File outFile = new File(tmpDir, TEST_DATA);
|
||||
if (argv.length > 0) {
|
||||
outFile = new File(argv[1]);
|
||||
}
|
||||
return outFile;
|
||||
}
|
||||
|
||||
|
||||
public void prepare() throws IOException, SQLException {
|
||||
String sql = dataSourceUtils.parseSqlIn("sqlserver/create-sqlserver-test-schema.sql");
|
||||
dataSourceUtils.executeStatement(sql);
|
||||
dataSourceUtils.insertTestData(testData);
|
||||
}
|
||||
|
||||
public List<ConvertorTestData> generateTestDataObjects() {
|
||||
List<ConvertorTestData> result = new ArrayList<ConvertorTestData>();
|
||||
for (String type : TYPES) {
|
||||
addTestObjectForType(type, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void addTestObjectForType(String type, List<ConvertorTestData> result) {
|
||||
Map<Integer, Object> rawResults = dataSourceUtils.rawDbObjects(type.toString());
|
||||
Map<Integer, Geometry> geometries = dataSourceUtils.expectedGeoms(type.toString(), testData);
|
||||
addToResult(type, result, rawResults, geometries);
|
||||
}
|
||||
|
||||
private void addToResult(String type, List<ConvertorTestData> result, Map<Integer, Object> rawResults, Map<Integer, Geometry> geometries) {
|
||||
for (Integer id : rawResults.keySet()) {
|
||||
ConvertorTestData data = new ConvertorTestData();
|
||||
data.id = id;
|
||||
data.geometry = geometries.get(id);
|
||||
data.type = type;
|
||||
data.bytes = (byte[]) rawResults.get(id);
|
||||
result.add(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void discard() throws SQLException, IOException {
|
||||
String sql = dataSourceUtils.parseSqlIn("sqlserver/drop-sqlserver-test-schema.sql");
|
||||
dataSourceUtils.executeStatement(sql);
|
||||
}
|
||||
|
||||
}
|
|
@ -26,7 +26,7 @@
|
|||
*
|
||||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
package org.hibernate.spatial.test.mgeom;
|
||||
package org.hibernate.spatial.mgeom;
|
||||
|
||||
import com.vividsolutions.jts.geom.Coordinate;
|
||||
import com.vividsolutions.jts.geom.CoordinateSequence;
|
||||
|
@ -34,14 +34,6 @@ import com.vividsolutions.jts.geom.CoordinateSequenceComparator;
|
|||
import com.vividsolutions.jts.geom.PrecisionModel;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.hibernate.spatial.mgeom.DoubleComparator;
|
||||
import org.hibernate.spatial.mgeom.MCoordinate;
|
||||
import org.hibernate.spatial.mgeom.MCoordinateSequenceFactory;
|
||||
import org.hibernate.spatial.mgeom.MGeometry;
|
||||
import org.hibernate.spatial.mgeom.MGeometryException;
|
||||
import org.hibernate.spatial.mgeom.MGeometryFactory;
|
||||
import org.hibernate.spatial.mgeom.MLineString;
|
||||
|
||||
/**
|
||||
* @author Karel Maesen
|
||||
*/
|
|
@ -26,18 +26,13 @@
|
|||
*
|
||||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
package org.hibernate.spatial.test.mgeom;
|
||||
package org.hibernate.spatial.mgeom;
|
||||
|
||||
import com.vividsolutions.jts.geom.Coordinate;
|
||||
import com.vividsolutions.jts.geom.CoordinateSequence;
|
||||
import com.vividsolutions.jts.geom.GeometryFactory;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.hibernate.spatial.mgeom.MCoordinate;
|
||||
import org.hibernate.spatial.mgeom.MCoordinateSequenceFactory;
|
||||
import org.hibernate.spatial.mgeom.MLineString;
|
||||
import org.hibernate.spatial.mgeom.MultiMLineString;
|
||||
|
||||
/**
|
||||
* @author Karel Maesen
|
||||
*/
|
|
@ -23,7 +23,7 @@
|
|||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.test.mgeom;
|
||||
package org.hibernate.spatial.mgeom;
|
||||
|
||||
import com.vividsolutions.jts.geom.Coordinate;
|
||||
import com.vividsolutions.jts.geom.PrecisionModel;
|
|
@ -23,7 +23,7 @@
|
|||
* For more information, visit: http://www.hibernatespatial.org/
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.test.mgeom;
|
||||
package org.hibernate.spatial.mgeom;
|
||||
|
||||
import com.vividsolutions.jts.geom.Coordinate;
|
||||
import com.vividsolutions.jts.geom.CoordinateSequence;
|
|
@ -28,7 +28,7 @@
|
|||
" http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<hibernate-mapping>
|
||||
<class name="org.hibernate.spatial.test.GeomEntity" table="GEOMTEST">
|
||||
<class name="org.hibernate.spatial.integration.GeomEntity" table="GEOMTEST">
|
||||
<id name="id" type="integer">
|
||||
<generator class="assigned"/>
|
||||
</id>
|
||||
|
|
|
@ -22,6 +22,28 @@
|
|||
# Boston, MA 02110-1301 USA
|
||||
#
|
||||
|
||||
# Default unit/integration test config.
|
||||
|
||||
hibernate.dialect org.hibernate.dialect.H2Dialect
|
||||
hibernate.connection.driver_class org.h2.Driver
|
||||
hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE
|
||||
hibernate.connection.username sa
|
||||
|
||||
hibernate.connection.pool_size 5
|
||||
|
||||
hibernate.show_sql false
|
||||
|
||||
hibernate.max_fetch_depth 5
|
||||
|
||||
hibernate.cache.region_prefix hibernate.test
|
||||
hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory
|
||||
|
||||
# NOTE: hibernate.jdbc.batch_versioned_data should be set to false when testing with Oracle
|
||||
hibernate.jdbc.batch_versioned_data true
|
||||
|
||||
|
||||
## Configs for spatial databases (used during testin on local dev environment).
|
||||
|
||||
#hibernate.dialect org.hibernate.spatial.dialect.postgis.PostgisDialect
|
||||
#hibernate.connection.driver_class org.postgresql.Driver
|
||||
#hibernate.connection.url jdbc:postgresql://localhost:5432:hibbrtru
|
||||
|
@ -34,17 +56,17 @@
|
|||
#hibernate.connection.username hbs
|
||||
#hibernate.connection.password hbs
|
||||
|
||||
hibernate.dialect org.hibernate.spatial.dialect.sqlserver.SqlServer2008SpatialDialect
|
||||
hibernate.connection.driver_class com.microsoft.sqlserver.jdbc.SQLServerDriver
|
||||
hibernate.connection.url jdbc:sqlserver://192.168.122.67:1433;databaseName=HBS
|
||||
hibernate.connection.username hbs
|
||||
hibernate.connection.password hbs
|
||||
|
||||
hibernate.connection.pool_size 5
|
||||
|
||||
hibernate.show_sql true
|
||||
|
||||
hibernate.max_fetch_depth 5
|
||||
|
||||
hibernate.cache.region_prefix hibernate.test
|
||||
hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory
|
||||
#hibernate.dialect org.hibernate.spatial.dialect.sqlserver.SqlServer2008SpatialDialect
|
||||
#hibernate.connection.driver_class com.microsoft.sqlserver.jdbc.SQLServerDriver
|
||||
#hibernate.connection.url jdbc:sqlserver://192.168.122.67:1433;databaseName=HBS
|
||||
#hibernate.connection.username hbs
|
||||
#hibernate.connection.password hbs
|
||||
#
|
||||
#hibernate.connection.pool_size 5
|
||||
#
|
||||
#hibernate.show_sql true
|
||||
#
|
||||
#hibernate.max_fetch_depth 5
|
||||
#
|
||||
#hibernate.cache.region_prefix hibernate.test
|
||||
#hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
# $Id: hibernate-spatial-sqlserver-test.properties 182 2010-03-20 17:30:12Z maesenka $
|
||||
#
|
||||
|
||||
jdbcUrl = jdbc:sqlserver://192.168.0.100:1433;databaseName=HBS
|
||||
jdbcDriver = com.microsoft.sqlserver.jdbc.SQLServerDriver
|
||||
jdbcUser = hbs
|
||||
jdbcPass = hbs
|
||||
dataset = test-data-set.xml
|
||||
#jdbcUrl = jdbc:sqlserver://192.168.0.100:1433;databaseName=HBS
|
||||
#jdbcDriver = com.microsoft.sqlserver.jdbc.SQLServerDriver
|
||||
#jdbcUser = hbs
|
||||
#jdbcPass = hbs
|
||||
#dataset = test-data-set.xml
|
||||
|
||||
|
|
Loading…
Reference in New Issue