Skip to content

Commit

Permalink
Remove create dummy table in the H2GISDBFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
ebocher committed Sep 21, 2018
1 parent 6fb6f1e commit 610b4d8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,6 @@ public static Connection createSpatialDataBase(String dbName,boolean initSpatial
// Keep a connection alive to not close the DataBase on each unit test
Connection connection = DriverManager.getConnection(databasePath,
"sa", "sa");
Statement st = connection.createStatement();
//Create one row table for tests
st.execute("CREATE TABLE dummy(id INTEGER);");
st.execute("INSERT INTO dummy values (1)");
// Init spatial ext
if(initSpatial) {
H2GISFunctions.load(connection);
Expand Down
64 changes: 34 additions & 30 deletions h2gis-functions/src/test/java/org/h2gis/functions/BasicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,19 @@
import org.h2gis.utilities.trigger.UpdateTrigger;
import org.h2gis.utilities.SFSUtilities;
import org.h2gis.utilities.TableLocation;
import org.junit.After;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import org.junit.Before;

/**
*
* @author Erwan Bocher
*/
public class BasicTest {
private static Connection connection;
private Statement st;

@BeforeClass
public static void tearUp() throws Exception {
Expand All @@ -65,6 +68,19 @@ public static void tearUp() throws Exception {
public static void tearDown() throws Exception {
connection.close();
}

@Before
public void setUpStatement() throws Exception {
st = connection.createStatement();
st.execute("DROP TABLE IF EXISTS dummy;CREATE TABLE dummy(id INTEGER);");
st.execute("INSERT INTO dummy values (1)");
}

@After
public void tearDownStatement() throws Exception {
st.close();
}

@Test
public void testPoints3D() throws Exception {

Expand All @@ -80,7 +96,6 @@ public void testPoints3D() throws Exception {

@Test
public void testUpdateTrigger() throws SQLException {
Statement st = connection.createStatement();
try {
st.execute("drop trigger if exists updatetrigger");
st.execute("DROP TABLE IF EXISTS test");
Expand Down Expand Up @@ -115,22 +130,17 @@ public void testSameClass() {

@Test
public void testGeometryType() throws Exception {
final Statement stat = connection.createStatement();
stat.execute("DROP TABLE IF EXISTS GEOMTABLE;");
stat.execute("CREATE TABLE GEOMTABLE (gid INTEGER AUTO_INCREMENT PRIMARY KEY, the_geom GEOMETRY);");
st.execute("DROP TABLE IF EXISTS GEOMTABLE;");
st.execute("CREATE TABLE GEOMTABLE (gid INTEGER AUTO_INCREMENT PRIMARY KEY, the_geom GEOMETRY);");
}

@Test
public void testWriteRead3DGeometryWithNaNZ() throws ClassNotFoundException, SQLException, ParseException {
st.execute("DROP TABLE IF EXISTS POINT3D");
st.execute("CREATE TABLE POINT3D (gid int , the_geom GEOMETRY)");
st.execute("INSERT INTO POINT3D (gid, the_geom) VALUES(1, ST_GeomFromText('POINT(0 12)', 27582))");

final Statement stat = connection.createStatement();

stat.execute("DROP TABLE IF EXISTS POINT3D");

stat.execute("CREATE TABLE POINT3D (gid int , the_geom GEOMETRY)");
stat.execute("INSERT INTO POINT3D (gid, the_geom) VALUES(1, ST_GeomFromText('POINT(0 12)', 27582))");

ResultSet rs = stat.executeQuery("SELECT * from POINT3D;");
ResultSet rs = st.executeQuery("SELECT * from POINT3D;");
ResultSetMetaData rsmd2 = rs.getMetaData();
Geometry geom;
boolean hasGeometryColumn = false;
Expand All @@ -147,50 +157,44 @@ public void testWriteRead3DGeometryWithNaNZ() throws ClassNotFoundException, SQL

}
assertTrue(hasGeometryColumn);
stat.close();
}

@Test
public void testST_Area() throws Exception {
final Statement stat = connection.createStatement();
ResultSet rs = stat.executeQuery("select ST_Area(ST_GeomFromText('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))', 27572)) as area from dummy");
ResultSet rs = st.executeQuery("select ST_Area(ST_GeomFromText('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))', 27572)) as area from dummy");
assertTrue(rs.next());
assertEquals(100.0,rs.getDouble("area"),1e-12);
stat.close();

}

@Test
public void testSFSUtilities() throws Exception {
final Statement stat = connection.createStatement();
String catalog = connection.getCatalog();
stat.execute("drop schema if exists blah");
stat.execute("create schema blah");
stat.execute("create table blah.testSFSUtilities(id integer, the_geom point)");
st.execute("drop schema if exists blah");
st.execute("create schema blah");
st.execute("create table blah.testSFSUtilities(id integer, the_geom point)");
List<String> geomFields = SFSUtilities.getGeometryFields(connection, new TableLocation(catalog, "blah", "testSFSUtilities"));
assertEquals(1, geomFields.size());
assertEquals("THE_GEOM", geomFields.get(0));
}

@Test
public void testSFSUtilitiesFirstGeometryFieldName1() throws Exception {
final Statement stat = connection.createStatement();
stat.execute("DROP TABLE IF EXISTS POINT3D");
stat.execute("CREATE TABLE POINT3D (gid int , the_geom GEOMETRY)");
stat.execute("INSERT INTO POINT3D (gid, the_geom) VALUES(1, ST_GeomFromText('POINT(0 12)', 27582))");
ResultSet rs = stat.executeQuery("SELECT * from POINT3D;");
st.execute("DROP TABLE IF EXISTS POINT3D");
st.execute("CREATE TABLE POINT3D (gid int , the_geom GEOMETRY)");
st.execute("INSERT INTO POINT3D (gid, the_geom) VALUES(1, ST_GeomFromText('POINT(0 12)', 27582))");
ResultSet rs = st.executeQuery("SELECT * from POINT3D;");
String geomField = SFSUtilities.getFirstGeometryFieldName(rs);
assertEquals("THE_GEOM", geomField);
}

@Test(expected = SQLException.class)
public void testSFSUtilitiesFirstGeometryFieldName2() throws Throwable {
try{
final Statement stat = connection.createStatement();
stat.execute("DROP TABLE IF EXISTS POINT3D");
stat.execute("CREATE TABLE POINT3D (gid int )");
stat.execute("INSERT INTO POINT3D (gid) VALUES(1)");
ResultSet rs = stat.executeQuery("SELECT * from POINT3D;");
st.execute("DROP TABLE IF EXISTS POINT3D");
st.execute("CREATE TABLE POINT3D (gid int )");
st.execute("INSERT INTO POINT3D (gid) VALUES(1)");
ResultSet rs = st.executeQuery("SELECT * from POINT3D;");
SFSUtilities.getFirstGeometryFieldName(rs);
} catch (JdbcSQLException e) {
throw e.getOriginalCause();
Expand Down

0 comments on commit 610b4d8

Please sign in to comment.