Skip to content

Commit

Permalink
HHH-13083 - Fix matrix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maesenka committed Dec 6, 2018
1 parent 89e36cf commit d9dd1eb
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 68 deletions.
Expand Up @@ -8,7 +8,7 @@
hibernate.test.new_metadata_mappings = true
hibernate.dialect org.hibernate.spatial.dialect.postgis.PostgisPG95Dialect
hibernate.connection.driver_class org.postgresql.Driver
hibernate.connection.url jdbc:postgresql://hibpg95.cctaez8ywvn2.eu-west-1.rds.amazonaws.com:5432/hibernate
hibernate.connection.url jdbc:postgresql://hbpg96.cctaez8ywvn2.eu-west-1.rds.amazonaws.com:5432/hibernate
hibernate.connection.username hibbrtru
hibernate.connection.password QilTygcxHwk1

Expand Down
Expand Up @@ -62,7 +62,7 @@ public void dimension(String pckg) throws SQLException {
return;
}
Map<Integer, Integer> dbexpected = expectationsFactory.getDimension();
String hql = format( "SELECT id, dimension(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity", pckg );
String hql = format( "SELECT id, dimension(geom) FROM %s", entityName( pckg ) );
retrieveHQLResultsAndCompare( dbexpected, hql, pckg );
}

Expand All @@ -81,7 +81,7 @@ public void astext(String pckg) throws SQLException {
return;
}
Map<Integer, String> dbexpected = expectationsFactory.getAsText();
String hql = format( "SELECT id, astext(geom) from org.hibernate.spatial.integration.%s.GeomEntity", pckg );
String hql = format( "SELECT id, astext(geom) from %s", entityName( pckg ) );
retrieveHQLResultsAndCompare( dbexpected, hql, pckg );
}

Expand All @@ -101,7 +101,7 @@ public void asbinary(String pckg) throws SQLException {
return;
}
Map<Integer, byte[]> dbexpected = expectationsFactory.getAsBinary();
String hql = format( "SELECT id, asbinary(geom) from org.hibernate.spatial.integration.%s.GeomEntity", pckg );
String hql = format( "SELECT id, asbinary(geom) from %s", entityName( pckg ) );
retrieveHQLResultsAndCompare( dbexpected, hql, pckg );
}

Expand All @@ -121,10 +121,10 @@ public void geometrytype(String pckg) throws SQLException {
}
Map<Integer, String> dbexpected = expectationsFactory.getGeometryType();
String hql = format(
"SELECT id, geometrytype(geom) from org.hibernate.spatial.integration.%s.GeomEntity",
pckg
"SELECT id, geometrytype(geom) from %s",
entityName( pckg )
);
retrieveHQLResultsAndCompare( dbexpected, hql, pckg );
retrieveHQLResultsAndCompare( dbexpected, hql, entityName( pckg ) );
}

@Test
Expand All @@ -142,7 +142,7 @@ public void srid(String pckg) throws SQLException {
return;
}
Map<Integer, Integer> dbexpected = expectationsFactory.getSrid();
String hql = format( "SELECT id, srid(geom) from org.hibernate.spatial.integration.%s.GeomEntity", pckg );
String hql = format( "SELECT id, srid(geom) from %s", entityName( pckg ) );
retrieveHQLResultsAndCompare( dbexpected, hql, pckg );
}

Expand All @@ -161,7 +161,7 @@ public void issimple(String pckg) throws SQLException {
return;
}
Map<Integer, Boolean> dbexpected = expectationsFactory.getIsSimple();
String hql = format( "SELECT id, issimple(geom) from org.hibernate.spatial.integration.%s.GeomEntity", pckg );
String hql = format( "SELECT id, issimple(geom) from %s", entityName( pckg ) );
retrieveHQLResultsAndCompare( dbexpected, hql, pckg );
}

Expand All @@ -180,7 +180,7 @@ public void isempty(String pckg) throws SQLException {
return;
}
Map<Integer, Boolean> dbexpected = expectationsFactory.getIsEmpty();
String hql = format( "SELECT id, isEmpty(geom) from org.hibernate.spatial.integration.%s.GeomEntity", pckg );
String hql = format( "SELECT id, isEmpty(geom) from %s", entityName( pckg ) );
retrieveHQLResultsAndCompare( dbexpected, hql, pckg );
}

Expand All @@ -199,7 +199,7 @@ public void boundary(String pckg) throws SQLException {
return;
}
Map<Integer, Geometry> dbexpected = expectationsFactory.getBoundary();
String hql = format( "SELECT id, boundary(geom) from org.hibernate.spatial.integration.%s.GeomEntity", pckg );
String hql = format( "SELECT id, boundary(geom) from %s", entityName( pckg ) );
retrieveHQLResultsAndCompare( dbexpected, hql, pckg );
}

Expand All @@ -218,7 +218,7 @@ public void envelope(String pckg) throws SQLException {
return;
}
Map<Integer, Geometry> dbexpected = expectationsFactory.getEnvelope();
String hql = format( "SELECT id, envelope(geom) from org.hibernate.spatial.integration.%s.GeomEntity", pckg );
String hql = format( "SELECT id, envelope(geom) from %s", entityName( pckg ) );
retrieveHQLResultsAndCompare( dbexpected, hql, pckg );
}

Expand All @@ -238,9 +238,9 @@ public void within(String pckg) throws SQLException {
}
Map<Integer, Boolean> dbexpected = expectationsFactory.getWithin( expectationsFactory.getTestPolygon() );
String hql = format(
"SELECT id, within(geom, :filter) from org.hibernate.spatial.integration.%s.GeomEntity " +
"SELECT id, within(geom, :filter) from %s " +
"where within(geom, :filter) = true and srid(geom) = %d",
pckg,
entityName( pckg ),
expectationsFactory.getTestSrid()
);
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPolygon() );
Expand All @@ -263,9 +263,9 @@ public void equals(String pckg) throws SQLException {
}
Map<Integer, Boolean> dbexpected = expectationsFactory.getEquals( expectationsFactory.getTestPolygon() );
String hql = format(
"SELECT id, equals(geom, :filter) from org.hibernate.spatial.integration.%s.GeomEntity " +
"SELECT id, equals(geom, :filter) from %s " +
"where equals(geom, :filter) = true and srid(geom) = %d",
pckg,
entityName( pckg ),
expectationsFactory.getTestSrid()
);
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPolygon() );
Expand All @@ -288,9 +288,9 @@ public void crosses(String pckg) throws SQLException {
}
Map<Integer, Boolean> dbexpected = expectationsFactory.getCrosses( expectationsFactory.getTestPolygon() );
String hql = format(
"SELECT id, crosses(geom, :filter) from org.hibernate.spatial.integration.%s.GeomEntity " +
"SELECT id, crosses(geom, :filter) from %s " +
"where crosses(geom, :filter) = true and srid(geom) = %d",
pckg,
entityName( pckg ),
expectationsFactory.getTestSrid()
);
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPolygon() );
Expand All @@ -314,9 +314,9 @@ public void contains(String pckg) throws SQLException {
}
Map<Integer, Boolean> dbexpected = expectationsFactory.getContains( expectationsFactory.getTestPolygon() );
String hql = format(
"SELECT id, contains(geom, :filter) from org.hibernate.spatial.integration.%s.GeomEntity " +
"SELECT id, contains(geom, :filter) from %s " +
"where contains(geom, :filter) = true and srid(geom) = %d",
pckg,
entityName( pckg ),
expectationsFactory.getTestSrid()
);
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPolygon() );
Expand All @@ -339,9 +339,9 @@ public void disjoint(String pckg) throws SQLException {
}
Map<Integer, Boolean> dbexpected = expectationsFactory.getDisjoint( expectationsFactory.getTestPolygon() );
String hql = format(
"SELECT id, disjoint(geom, :filter) from org.hibernate.spatial.integration.%s.GeomEntity " +
"SELECT id, disjoint(geom, :filter) from %s " +
"where disjoint(geom, :filter) = true and srid(geom) = %d",
pckg,
entityName( pckg ),
expectationsFactory.getTestSrid()
);
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPolygon() );
Expand All @@ -364,9 +364,9 @@ public void intersects(String pckg) throws SQLException {
}
Map<Integer, Boolean> dbexpected = expectationsFactory.getIntersects( expectationsFactory.getTestPolygon() );
String hql = format(
"SELECT id, intersects(geom, :filter) from org.hibernate.spatial.integration.%s.GeomEntity " +
"SELECT id, intersects(geom, :filter) from %s " +
"where intersects(geom, :filter) = true and srid(geom) = %d",
pckg,
entityName( pckg ),
expectationsFactory.getTestSrid()
);
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPolygon() );
Expand All @@ -389,9 +389,8 @@ public void overlaps(String pckg) throws SQLException {
}
Map<Integer, Boolean> dbexpected = expectationsFactory.getOverlaps( expectationsFactory.getTestPolygon() );
String hql = format(
"SELECT id, overlaps(geom, :filter) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where overlaps(geom, :filter) = true and srid(geom) = %d",
pckg,
"SELECT id, overlaps(geom, :filter) from %s where overlaps(geom, :filter) = true and srid(geom) = %d",
entityName( pckg ),
expectationsFactory.getTestSrid()
);
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPolygon() );
Expand All @@ -413,9 +412,8 @@ public void touches(String pckg) throws SQLException {
return;
}
String hql = format(
"SELECT id, touches(geom, :filter) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where touches(geom, :filter) = true and srid(geom) = %d",
pckg,
"SELECT id, touches(geom, :filter) from %s where touches(geom, :filter) = true and srid(geom) = %d",
entityName( pckg ),
expectationsFactory.getTestSrid()
);
Map<Integer, Boolean> dbexpected = expectationsFactory.getTouches( expectationsFactory.getTestPolygon() );
Expand Down Expand Up @@ -443,9 +441,9 @@ public void relate(String pckg) throws SQLException {
matrix
);
String hql = format(
"SELECT id, relate(geom, :filter, :matrix) from org.hibernate.spatial.integration.%s.GeomEntity " +
"SELECT id, relate(geom, :filter, :matrix) from %s " +
"where relate(geom, :filter, :matrix) = true and srid(geom) = %d",
pckg,
entityName( pckg ),
expectationsFactory.getTestSrid()
);
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPolygon() );
Expand Down Expand Up @@ -475,8 +473,7 @@ public void distance(String pckg) throws SQLException {
}
Map<Integer, Double> dbexpected = expectationsFactory.getDistance( expectationsFactory.getTestPolygon() );
String hql = format(
"SELECT id, distance(geom, :filter) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where srid(geom) = %d", pckg, expectationsFactory.getTestSrid()
"SELECT id, distance(geom, :filter) from %s where srid(geom) = %d", entityName( pckg ), expectationsFactory.getTestSrid()
);
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPolygon() );
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
Expand All @@ -498,8 +495,8 @@ public void buffer(String pckg) throws SQLException {
}
Map<Integer, Geometry> dbexpected = expectationsFactory.getBuffer( Double.valueOf( 1.0 ) );
String hql = format(
"SELECT id, buffer(geom, :distance) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where srid(geom) = %d", pckg, expectationsFactory.getTestSrid()
"SELECT id, buffer(geom, :distance) from %s where srid(geom) = %d",
entityName( pckg ), expectationsFactory.getTestSrid()
);
Map<String, Object> params = createQueryParams( "distance", Double.valueOf( 1.0 ) );
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
Expand Down Expand Up @@ -528,8 +525,8 @@ public void convexhull(String pckg) throws SQLException {
}
Map<Integer, Geometry> dbexpected = expectationsFactory.getConvexHull( expectationsFactory.getTestPolygon() );
String hql = format(
"SELECT id, convexhull(geomunion(geom, :polygon)) from org.hibernate.spatial.integration" +
".%s.GeomEntity where srid(geom) = %d", pckg, expectationsFactory.getTestSrid()
"SELECT id, convexhull(geomunion(geom, :polygon)) from %s where srid(geom) = %d",
entityName( pckg ), expectationsFactory.getTestSrid()
);
Map<String, Object> params = createQueryParams( "polygon", expectationsFactory.getTestPolygon() );
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
Expand All @@ -556,8 +553,8 @@ public void intersection(String pckg) throws SQLException {
}
Map<Integer, Geometry> dbexpected = expectationsFactory.getIntersection( expectationsFactory.getTestPolygon() );
String hql = format(
"SELECT id, intersection(geom, :polygon) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where srid(geom) = %d", pckg, expectationsFactory.getTestSrid()
"SELECT id, intersection(geom, :polygon) from %s where srid(geom) = %d",
entityName( pckg ), expectationsFactory.getTestSrid()
);
Map<String, Object> params = createQueryParams( "polygon", expectationsFactory.getTestPolygon() );
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
Expand All @@ -579,8 +576,8 @@ public void difference(String pckg) throws SQLException {
}
Map<Integer, Geometry> dbexpected = expectationsFactory.getDifference( expectationsFactory.getTestPolygon() );
String hql = format(
"SELECT id, difference(geom, :polygon) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where srid(geom) = %d", pckg, expectationsFactory.getTestSrid()
"SELECT id, difference(geom, :polygon) from %s where srid(geom) = %d",
entityName( pckg ), expectationsFactory.getTestSrid()
);
Map<String, Object> params = createQueryParams( "polygon", expectationsFactory.getTestPolygon() );
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
Expand All @@ -602,9 +599,8 @@ public void symdifference(String pckg) throws SQLException {
}
Map<Integer, Geometry> dbexpected = expectationsFactory.getSymDifference( expectationsFactory.getTestPolygon() );
String hql = format(
"SELECT id, symdifference(geom, :polygon) from " +
"org.hibernate.spatial.integration.%s.GeomEntity where srid(geom) = %d",
pckg,
"SELECT id, symdifference(geom, :polygon) from %s where srid(geom) = %d",
entityName( pckg ),
expectationsFactory.getTestSrid()
);
Map<String, Object> params = createQueryParams( "polygon", expectationsFactory.getTestPolygon() );
Expand All @@ -627,8 +623,8 @@ public void geomunion(String pckg) throws SQLException {
}
Map<Integer, Geometry> dbexpected = expectationsFactory.getGeomUnion( expectationsFactory.getTestPolygon() );
String hql = format(
"SELECT id, geomunion(geom, :polygon) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where srid(geom) = %d", pckg, expectationsFactory.getTestSrid()
"SELECT id, geomunion(geom, :polygon) from %s " +
"where srid(geom) = %d", entityName( pckg ), expectationsFactory.getTestSrid()
);
Map<String, Object> params = createQueryParams( "polygon", expectationsFactory.getTestPolygon() );
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
Expand All @@ -655,8 +651,8 @@ public void dwithin(String pckg) throws SQLException {
);
String hql = format(
"SELECT id, dwithin(geom, :filter, :distance) from " +
"org.hibernate.spatial.integration.%s.GeomEntity where dwithin(geom, :filter, :distance) = true " +
"and srid(geom) = %d", pckg, expectationsFactory.getTestSrid()
"%s where dwithin(geom, :filter, :distance) = true " +
"and srid(geom) = %d", entityName( pckg ), expectationsFactory.getTestSrid()
);
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPoint() );
if ( getDialect() instanceof OracleSpatial10gDialect ) {
Expand Down Expand Up @@ -693,8 +689,8 @@ public void transform(String pckg) throws SQLException {
int epsg = 4324;
Map<Integer, Geometry> dbexpected = expectationsFactory.getTransform( epsg );
String hql = format(
"SELECT id, transform(geom, :epsg) from org.hibernate.spatial.integration.%s.GeomEntity " +
"where srid(geom) = %d", pckg, expectationsFactory.getTestSrid()
"SELECT id, transform(geom, :epsg) from %s " +
"where srid(geom) = %d", entityName( pckg ), expectationsFactory.getTestSrid()
);
Map<String, Object> params = createQueryParams( "epsg", Integer.valueOf( epsg ) );
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
Expand All @@ -717,7 +713,7 @@ public void extent(String pckg) throws SQLException {
}
// here we just check if we get a result, and can read it
String hql = format(
"SELECT id, extent(geom) from org.hibernate.spatial.integration.%s.GeomEntity group by id", pckg
"SELECT id, extent(geom) from %s group by id", entityName( pckg )
);
Map<Integer, Object> hsreceived = new HashMap<Integer, Object>();
doInSession( hql, hsreceived, new HashMap<String, Object>() );
Expand Down
Expand Up @@ -19,7 +19,7 @@
import org.hibernate.spatial.SpatialFunction;
import org.hibernate.spatial.criterion.SpatialRestrictions;
import org.hibernate.spatial.dialect.hana.HANASpatialDialect;
import org.hibernate.spatial.integration.jts.GeomEntity;
import org.hibernate.spatial.integration.jts.JtsGeomEntity;
import org.hibernate.spatial.testing.SpatialDialectMatcher;
import org.hibernate.spatial.testing.SpatialFunctionalTestCase;

Expand Down Expand Up @@ -188,7 +188,7 @@ private void retrieveAndCompare(Map<Integer, Boolean> dbexpected, Criterion spat
try {
session = openSession();
tx = session.beginTransaction();
Criteria criteria = session.createCriteria( GeomEntity.class );
Criteria criteria = session.createCriteria( JtsGeomEntity.class );
criteria.add( spatialCriterion );
compare( dbexpected, criteria.list() );
}
Expand All @@ -207,7 +207,7 @@ private void compare(Map<Integer, Boolean> dbexpected, List list) {
for ( Map.Entry<Integer, Boolean> entry : dbexpected.entrySet() ) {
if ( entry.getValue() ) {
cnt++;
if ( !findInList( entry.getKey(), (List<GeomEntity>) list ) ) {
if ( !findInList( entry.getKey(), (List<JtsGeomEntity>) list ) ) {
fail( String.format( "Expected object with id= %d, but not found in result", entry.getKey() ) );
}
}
Expand All @@ -216,8 +216,8 @@ private void compare(Map<Integer, Boolean> dbexpected, List list) {
LOG.info( String.format( "Found %d objects within testsuite-suite polygon.", cnt ) );
}

private boolean findInList(Integer id, List<GeomEntity> list) {
for ( GeomEntity entity : list ) {
private boolean findInList(Integer id, List<JtsGeomEntity> list) {
for ( JtsGeomEntity entity : list ) {
if ( entity.getId().equals( id ) ) {
return true;
}
Expand Down
Expand Up @@ -27,7 +27,7 @@
*/
@Entity
@Table(name = "geomtest")
public class GeomEntity implements GeomEntityLike<Geometry> {
public class JtsGeomEntity implements GeomEntityLike<Geometry> {


@Id
Expand All @@ -37,10 +37,10 @@ public class GeomEntity implements GeomEntityLike<Geometry> {

private Geometry geom;

public static GeomEntity createFrom(TestDataElement element, Dialect dialect) throws ParseException {
public static JtsGeomEntity createFrom(TestDataElement element, Dialect dialect) throws ParseException {
WktDecoder decoder = getWktDecoder( dialect );
Geometry geom = JTS.to( decoder.decode( element.wkt ) );
GeomEntity result = new GeomEntity();
JtsGeomEntity result = new JtsGeomEntity();
result.setId( element.id );
result.setGeom( geom );
result.setType( element.type );
Expand Down Expand Up @@ -80,7 +80,7 @@ public boolean equals(Object o) {
return false;
}

GeomEntity geomEntity = (GeomEntity) o;
JtsGeomEntity geomEntity = (JtsGeomEntity) o;

if ( !id.equals( geomEntity.id ) ) {
return false;
Expand Down

0 comments on commit d9dd1eb

Please sign in to comment.