Subversion Repositories hibernate-spatial

Compare Revisions

Ignore whitespace Rev 245 → Rev 246

/branches/hibernate-3.6-integration/hibernate-spatial-postgis/src/test/resources/hibernate.cfg.xml
File deleted
/branches/hibernate-3.6-integration/test-suite/src/test/java/org/hibernatespatial/testsuite/TestStoreRetrieve.java
51,6 → 51,11
}
 
 
protected Logger getLogger(){
return LOGGER;
}
 
 
public void test_store_retrieve() throws ParseException {
Map<Integer, GeomEntity> stored = new HashMap<Integer, GeomEntity>();
storeTestObjects(stored);
/branches/hibernate-3.6-integration/test-suite/src/test/java/org/hibernatespatial/testsuite/TestSpatialFunctions.java
62,7 → 62,11
}
}
 
protected Logger getLogger(){
return LOGGER;
}
 
 
public void test_dimension() throws SQLException {
Map<Integer, Integer> dbexpected = expectationsFactory.getDimension();
String hql = "SELECT id, dimension(geom) FROM GeomEntity";
251,9 → 255,7
}
 
public <T> void retrieveHQLResultsAndCompare(Map<Integer, T> dbexpected, String hql) {
Map<Integer, T> hsreceived = new HashMap<Integer, T>();
doInSession(hql, hsreceived, null);
compare(dbexpected, hsreceived);
retrieveHQLResultsAndCompare(dbexpected, hql, null);
}
 
protected <T> void retrieveHQLResultsAndCompare(Map<Integer, T> dbexpected, String hql, Map<String, Object> params) {
262,35 → 264,8
compare(dbexpected, hsreceived);
}
 
protected <T> void compare(Map<Integer, T> expected, Map<Integer, T> received) {
for (Integer id : expected.keySet()) {
LOGGER.debug("Case :" + id);
LOGGER.debug("expected: " + expected.get(id));
LOGGER.debug("received: " + received.get(id));
compare(id, expected.get(id), received.get(id));
}
}
 
 
protected void compare(Integer id, Object expected, Object received) {
assertTrue(expected != null && received != null);
if (expected instanceof byte[]) {
assertArrayEquals("Failure on testsuite-suite for case " + id, (byte[]) expected, (byte[]) received);
 
} else if (expected instanceof Geometry) {
if (!(received instanceof Geometry))
fail("Expected a Geometry, but received an object of type " + received.getClass().getCanonicalName());
assertTrue("Failure on testsuite-suite for case " + id, geometryEquality.test((Geometry) expected, (Geometry) received));
 
} else {
if (expected instanceof Long) {
assertEquals("Failure on testsuite-suite for case " + id, ((Long) expected).intValue(), received);
} else {
assertEquals("Failure on testsuite-suite for case " + id, expected, received);
}
}
}
 
private <T> void doInSession(String hql, Map<Integer, T> result, Map<String, Object> params) {
Session session = null;
Transaction tx = null;
306,17 → 281,6
}
}
 
private <T> void addQueryResults(Map<Integer, T> result, Query query) {
List<Object[]> rows = (List<Object[]>) query.list();
if (rows.size() == 0) {
LOGGER.warn("No results returned for query!!");
}
for (Object[] row : rows) {
Integer id = (Integer) row[0];
T val = (T) row[1];
result.put(id, val);
}
}
 
private void setParameters(Map<String, Object> params, Query query) {
if (params == null) return;
/branches/hibernate-3.6-integration/test-suite/src/test/java/org/hibernatespatial/testsuite/TestSpatialRestrictions.java
65,6 → 65,10
}
}
 
protected Logger getLogger(){
return LOGGER;
}
 
public void test_within() throws SQLException {
Map<Integer, Boolean> dbexpected = expectationsFactory.getWithin(expectationsFactory.getTestPolygon());
Criterion spatialCriterion = SpatialRestrictions.within("geom", expectationsFactory.getTestPolygon());
137,8 → 141,6
}
}
 
//TODO -- clean this up!
 
private void compare(Map<Integer, Boolean> dbexpected, List list) {
int cnt = 0;
for (Integer id : dbexpected.keySet()) {
/branches/hibernate-3.6-integration/test-suite/src/test/java/org/hibernatespatial/testsuite/SpatialFunctionalTestCase.java
1,19 → 1,30
package org.hibernatespatial.testsuite;
 
import com.vividsolutions.jts.geom.Geometry;
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.cfg.Configuration;
import org.hibernate.testing.junit.functional.FunctionalTestCase;
import org.hibernatespatial.test.*;
import org.slf4j.Logger;
 
import java.util.List;
import java.util.Map;
 
import static org.junit.Assert.assertArrayEquals;
 
/**
* @author Karel Maesen, Geovise BVBA
* creation-date: Sep 30, 2010
*/
public abstract class SpatialFunctionalTestCase extends FunctionalTestCase {
 
protected TestData testData;
protected DataSourceUtils dataSourceUtils;
protected GeometryEquality geometryEquality;
protected AbstractExpectationsFactory expectationsFactory;
 
 
public SpatialFunctionalTestCase(String string) {
super(string);
}
21,7 → 32,7
public void prepareTest(){
try {
TestSupportFactory tsFactory = TestSupportFactories.instance().getTestSupportFactory(getDialect());
Configuration cfg = getEnvironment().getConfiguration();
Configuration cfg = getCfg();
dataSourceUtils = tsFactory.createDataSourceUtil(cfg);
expectationsFactory = tsFactory.createExpectationsFactory(dataSourceUtils);
testData = tsFactory.createTestData(this);
40,5 → 51,60
return new String[]{"GeomEntity.hbm.xml"};
}
 
abstract protected Logger getLogger();
 
/**
* Adds the query results to a Map.
*
* Each row is added as a Map entry with the first column the key,
* and the second the value. It is assumed that the first column is an
* identifier of a type assignable to Integer.
*
* @param result map of
* @param query the source Query
* @param <T> type of the second column in the query results
*/
protected <T> void addQueryResults(Map<Integer, T> result, Query query) {
List<Object[]> rows = (List<Object[]>) query.list();
if (rows.size() == 0) {
getLogger().warn("No results returned for query!!");
}
for (Object[] row : rows) {
Integer id = (Integer) row[0];
T val = (T) row[1];
result.put(id, val);
}
}
 
protected <T> void compare(Map<Integer, T> expected, Map<Integer, T> received) {
for (Integer id : expected.keySet()) {
getLogger().debug("Case :" + id);
getLogger().debug("expected: " + expected.get(id));
getLogger().debug("received: " + received.get(id));
compare(id, expected.get(id), received.get(id));
}
}
 
 
protected void compare(Integer id, Object expected, Object received) {
assertTrue(expected != null && received != null);
if (expected instanceof byte[]) {
assertArrayEquals("Failure on testsuite-suite for case " + id, (byte[]) expected, (byte[]) received);
 
} else if (expected instanceof Geometry) {
if (!(received instanceof Geometry))
fail("Expected a Geometry, but received an object of type " + received.getClass().getCanonicalName());
assertTrue("Failure on testsuite-suite for case " + id, geometryEquality.test((Geometry) expected, (Geometry) received));
 
} else {
if (expected instanceof Long) {
assertEquals("Failure on testsuite-suite for case " + id, ((Long) expected).intValue(), received);
} else {
assertEquals("Failure on testsuite-suite for case " + id, expected, received);
}
}
}
 
 
 
}
/branches/hibernate-3.6-integration/hibernate-spatial/src/test/java/org/hibernatespatial/test/GeomEntity.hbm.xml
29,7 → 29,7
 
<hibernate-mapping>
<class name="org.hibernatespatial.test.GeomEntity" table="GEOMTEST">
<id name="id" type="int">
<id name="id" type="integer">
<generator class="assigned"/>
</id>
<property name="type" type="string">
/branches/hibernate-3.6-integration/hibernate-spatial/src/test/java/org/hibernatespatial/test/AbstractExpectationsFactory.java
42,7 → 42,6
* The expected values are returned as a map of (identifier, expected value) pairs.
*
* @author Karel Maesen, Geovise BVBA
* @see TestSpatialFunctions
*/
public abstract class AbstractExpectationsFactory {
 
/branches/hibernate-3.6-integration/hibernate-spatial/src/test/java/org/hibernatespatial/test/GeomEntity.java
31,19 → 31,19
/**
* Test class used in unit testing.
*/
public class GeomEntity {
public class GeomEntity implements TestFeature {
 
private int id;
private Integer id;
 
private String type;
 
private Geometry geom;
 
public int getId() {
public Integer getId() {
return id;
}
 
public void setId(int id) {
public void setId(Integer id) {
this.id = id;
}
 
/branches/hibernate-3.6-integration/hibernate-spatial/src/test/java/org/hibernatespatial/test/TestFeature.java
New file
0,0 → 1,22
package org.hibernatespatial.test;
 
import com.vividsolutions.jts.geom.Geometry;
 
/**
* Interface for persistent entities in
* integration tests.
*
* @author Karel Maesen, Geovise BVBA
* creation-date: Oct 2, 2010
*/
public interface TestFeature {
 
public Integer getId();
 
public void setId(Integer id);
 
public Geometry getGeom();
 
public void setGeom(Geometry geom);
 
}