Skip to content

Commit

Permalink
Improve throwing data error
Browse files Browse the repository at this point in the history
  • Loading branch information
ebocher committed Jun 3, 2024
1 parent 2f7557b commit 1464595
Show file tree
Hide file tree
Showing 17 changed files with 95 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private static class DummyTableLocation implements ITableLocation {
/**
* Fake data location.
*/
private String location;
private final String location;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ private class DummyException extends Exception {
* Simple implementation of the {@link IJdbcDataSource} interface.
*/
private class DummyDataSource implements IJdbcDataSource {
private Object prop1;
private Object prop2;
private final Object prop1;
private final Object prop2;
private boolean streamScript = false;
private boolean fileScript = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ void getTypeTest(){
assertEquals((byte)3, dataFrame.getObject(4, Byte.class));
assertEquals((short)3, dataFrame.getObject(5, short.class));
assertEquals((short)3, dataFrame.getObject(5, Short.class));
assertEquals(3l, dataFrame.getObject(6, long.class));
assertEquals(3l, dataFrame.getObject(6, Long.class));
assertEquals(3L, dataFrame.getObject(6, long.class));
assertEquals(3L, dataFrame.getObject(6, Long.class));
assertEquals(3.5f, dataFrame.getObject(7, float.class));
assertEquals(3.5f, dataFrame.getObject(7, Float.class));
assertEquals(3d, dataFrame.getObject(8, double.class));
Expand All @@ -244,8 +244,8 @@ void getTypeTest(){
assertEquals(4, dataFrame.getObject("COL5", Integer.class));
assertEquals(4, dataFrame.getObject("COL6", int.class));
assertEquals(4, dataFrame.getObject("COL6", Integer.class));
assertEquals(4l, dataFrame.getObject("COL7", long.class));
assertEquals(4l, dataFrame.getObject("COL7", Long.class));
assertEquals(4L, dataFrame.getObject("COL7", long.class));
assertEquals(4L, dataFrame.getObject("COL7", Long.class));
assertEquals(4.5f, dataFrame.getObject("COL8", float.class));
assertEquals(4.5f, dataFrame.getObject("COL8", Float.class));
assertEquals(4d, dataFrame.getObject("COL9", double.class));
Expand Down Expand Up @@ -588,7 +588,7 @@ void testRandomForestNominalValuesInResult() {
// Dataset used
BaseVector[] bv = new BaseVector[]{
IntVector.of("LCZ", new int[]{105, 107, 106, 105, 105, 106, 107, 106, 106, 107, 107, 107, 107}),
StringVector.of("TYPE", new String[]{"grass", "corn", "corn", "grass", "corn", "grass", "forest", "grass", "grass", "corn", "corn", "corn", "corn"}),
StringVector.of("TYPE", "grass", "corn", "corn", "grass", "corn", "grass", "forest", "grass", "grass", "corn", "corn", "corn", "corn"),
IntVector.of("TEMPERATURE", new int[]{12, 12, 18, 12, 16, 12, 12, 12, 16, 16, 2, 16, 18}),
IntVector.of("WIND", new int[]{20, 30, 20, 30, 20, 20, 20, 20, 20, 20, 20, 50, 40}),
};
Expand Down
22 changes: 11 additions & 11 deletions data/h2gis/src/test/java/org/orbisgis/data/H2GISDataSourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class H2GISDataSourceTest {
* @throws SQLException Sql exception.
*/
@BeforeEach
void init() throws SQLException, Exception {
void init() throws Exception {
h2gis = H2GIS.open(DB_NAME);
h2gis.execute("DROP TABLE IF EXISTS test_h2gis");
h2gis.execute("CREATE TABLE test_h2gis(id int, the_geom GEOMETRY, text varchar)");
Expand Down Expand Up @@ -266,7 +266,7 @@ public Object call(Object arguments) {
*/
@Test
@EnabledIfSystemProperty(named = "test.postgis", matches = "true")
void testExecuteMethod1() throws URISyntaxException, SQLException, Exception {
void testExecuteMethod1() throws Exception {
Map<String, String> map = new HashMap<>();
map.put("intArg", "51");
URL url = this.getClass().getResource("simpleWithArgs.sql");
Expand Down Expand Up @@ -303,7 +303,7 @@ void testExecuteMethod1() throws URISyntaxException, SQLException, Exception {
*/
@Test
@EnabledIfSystemProperty(named = "test.postgis", matches = "true")
void testExecuteMethod2() throws SQLException, Exception {
void testExecuteMethod2() throws Exception {
Map<String, String> map = new HashMap<>();
map.put("intArg", "51");

Expand Down Expand Up @@ -341,7 +341,7 @@ void testMetaClassMethods() {
*/
@Test
@EnabledIfSystemProperty(named = "test.postgis", matches = "true")
void testSave() throws SQLException, MalformedURLException, Exception {
void testSave() throws Exception {
h2gis.execute("DROP TABLE IF EXISTS load");
postgis.execute("DROP TABLE IF EXISTS load");

Expand Down Expand Up @@ -382,7 +382,7 @@ void testSave() throws SQLException, MalformedURLException, Exception {
*/
@Test
@EnabledIfSystemProperty(named = "test.postgis", matches = "true")
void testLink() throws SQLException, URISyntaxException, MalformedURLException, Exception {
void testLink() throws Exception {
URL url = this.getClass().getResource("linkTable.dbf");
URI uri = url.toURI();
File file = new File(uri);
Expand Down Expand Up @@ -503,7 +503,7 @@ void testLink() throws SQLException, URISyntaxException, MalformedURLException,
*/
@Disabled
@Test
void loadFromDB() throws SQLException, Exception {
void loadFromDB() throws Exception {
String tableNameDS1 = "test_h2gis";
String tableNameDS2 = "test_postgis";

Expand Down Expand Up @@ -547,7 +547,7 @@ void loadFromDB() throws SQLException, Exception {
*/
@Test
@EnabledIfSystemProperty(named = "test.postgis", matches = "true")
void testLoadPath() throws SQLException, URISyntaxException, Exception {
void testLoadPath() throws Exception {
URL url = this.getClass().getResource("loadTable.dbf");
URI uri = url.toURI();
File file = new File(uri);
Expand Down Expand Up @@ -808,12 +808,12 @@ void testHasTable() throws Exception {
@EnabledIfSystemProperty(named = "test.postgis", matches = "true")
void testGetDataSet() throws Exception {
Object dataset = h2gis.getDataSet("TEST_H2GIS");
assertTrue(dataset instanceof ISpatialTable);
assertInstanceOf(ISpatialTable.class, dataset);
dataset = h2gis.getDataSet("GEOMETRY_COLUMNS");
assertNotNull(dataset);

dataset = postgis.getDataSet("test_postgis");
assertTrue(dataset instanceof ISpatialTable);
assertInstanceOf(ISpatialTable.class, dataset);
dataset = postgis.getDataSet("geometry_columns");
assertNotNull(dataset);
}
Expand All @@ -836,7 +836,7 @@ void testResultSetBuilder() throws Exception {
.maxFieldSize(FIELD_SIZE).getTable("TEST_H2GIS");
assertNotNull(table);
assertArrayEquals(new int[]{3, 3}, table.getSize());
assertTrue(table instanceof H2gisSpatialTable);
assertInstanceOf(H2gisSpatialTable.class, table);
IResultSetProperties rsp = ((H2gisSpatialTable)table).getResultSetProperties();
assertEquals(ResultSet.TYPE_FORWARD_ONLY, rsp.getType());
assertEquals(ResultSet.CONCUR_READ_ONLY, rsp.getConcurrency());
Expand All @@ -854,7 +854,7 @@ void testResultSetBuilder() throws Exception {
.maxFieldSize(FIELD_SIZE).getTable("test_postgis");
assertNotNull(table);
assertArrayEquals(new int[]{3, 3}, table.getSize());
assertTrue(table instanceof PostgisSpatialTable);
assertInstanceOf(PostgisSpatialTable.class, table);
rsp = ((PostgisSpatialTable)table).getResultSetProperties();
assertEquals(ResultSet.TYPE_SCROLL_INSENSITIVE, rsp.getType());
assertEquals(ResultSet.CONCUR_READ_ONLY, rsp.getConcurrency());
Expand Down
26 changes: 13 additions & 13 deletions data/h2gis/src/test/java/org/orbisgis/data/H2GISTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void openH2GIS() throws Exception {
}

@Test
public void testColumnsType() throws SQLException, Exception {
public void testColumnsType() throws Exception {
Map<String, String> map = new HashMap<>();
map.put(H2GISDBFactory.JDBC_DATABASE_NAME, "./target/loadH2GIS");
H2GIS h2GIS = H2GIS.open(map);
Expand All @@ -89,9 +89,9 @@ public void testColumnsType() throws SQLException, Exception {

Map<String, String> columnTypes = h2GIS.getColumnNamesTypes("types");
assertTrue(columnTypes.containsKey("COLINT"));
assertTrue(columnTypes.get("COLINT")=="INTEGER");
assertSame("INTEGER", columnTypes.get("COLINT"));
assertTrue(columnTypes.containsKey("COLREAL"));
assertTrue(columnTypes.get("COLREAL")=="REAL");
assertSame("REAL", columnTypes.get("COLREAL"));
}


Expand All @@ -105,7 +105,7 @@ public void loadH2GIS() throws Exception {


@Test
public void queryH2GIS() throws SQLException, Exception {
public void queryH2GIS() throws Exception {
Map<String, String> map = new HashMap<>();
map.put(H2GISDBFactory.JDBC_DATABASE_NAME, "./target/loadH2GIS2");
H2GIS h2GIS = H2GIS.open(map);
Expand All @@ -125,7 +125,7 @@ public Object call(Object argument) {
}

@Test
public void querySpatialTable() throws SQLException, Exception {
public void querySpatialTable() throws Exception {
Map<String, String> map = new HashMap<>();
map.put(H2GISDBFactory.JDBC_DATABASE_NAME, "./target/loadH2GIS2");
H2GIS h2GIS = H2GIS.open(map);
Expand Down Expand Up @@ -153,7 +153,7 @@ public Object call(Object argument) {
}

@Test
public void queryTableNames() throws SQLException, Exception {
public void queryTableNames() throws Exception {
Map<String, String> map = new HashMap<>();
map.put(H2GISDBFactory.JDBC_DATABASE_NAME, "./target/loadH2GIS");
H2GIS h2GIS = H2GIS.open(map);
Expand All @@ -167,7 +167,7 @@ public void queryTableNames() throws SQLException, Exception {
}

@Test
public void updateSpatialTable() throws SQLException, Exception {
public void updateSpatialTable() throws Exception {
Map<String, String> map = new HashMap<>();
map.put(H2GISDBFactory.JDBC_DATABASE_NAME, "./target/loadH2GIS");
H2GIS h2GIS = H2GIS.open(map);
Expand Down Expand Up @@ -208,7 +208,7 @@ public Object call(Object argument) {
}

@Test
public void request() throws SQLException, Exception {
public void request() throws Exception {
Map<String, String> map = new HashMap<>();
map.put(H2GISDBFactory.JDBC_DATABASE_NAME, "./target/loadH2GIS2");
H2GIS h2GIS = H2GIS.open(map);
Expand Down Expand Up @@ -293,7 +293,7 @@ public Object call(Object argument) {
}

@Test
public void hasTable() throws SQLException, Exception {
public void hasTable() throws Exception {
Map<String, String> map = new HashMap<>();
map.put(H2GISDBFactory.JDBC_DATABASE_NAME, "./target/loadH2GIS");
H2GIS h2GIS = H2GIS.open(map);
Expand All @@ -308,7 +308,7 @@ public void hasTable() throws SQLException, Exception {
}

@Test
void testGetTableOnEmptyTable() throws SQLException, Exception {
void testGetTableOnEmptyTable() throws Exception {
Map<String, String> map = new HashMap<>();
map.put(H2GISDBFactory.JDBC_DATABASE_NAME, "./target/loadH2GIS");
H2GIS h2GIS = H2GIS.open(map);
Expand Down Expand Up @@ -374,7 +374,7 @@ void addNetworkFunctionsTest() throws Exception {
}

@Test
void testExtent() throws SQLException, Exception {
void testExtent() throws Exception {
H2GIS h2GIS = H2GIS.open("./target/orbisgis");
h2GIS.execute("DROP TABLE IF EXISTS forests;\n" +
" CREATE TABLE forests ( fid INTEGER NOT NULL PRIMARY KEY, name CHARACTER VARYING(64),\n" +
Expand All @@ -394,7 +394,7 @@ void testExtent() throws SQLException, Exception {
}

@Test
void testExtentWithFilter() throws SQLException, Exception {
void testExtentWithFilter() throws Exception {
H2GIS h2GIS = H2GIS.open("./target/orbisgis");
h2GIS.execute("DROP TABLE IF EXISTS forests;\n" +
" CREATE TABLE forests ( fid INTEGER NOT NULL PRIMARY KEY, name CHARACTER VARYING(64),\n" +
Expand All @@ -414,7 +414,7 @@ void testExtentWithFilter() throws SQLException, Exception {
}

@Test
public void getTableSelect() throws SQLException, Exception {
public void getTableSelect() throws Exception {
Map<String, String> map = new HashMap<>();
map.put(H2GISDBFactory.JDBC_DATABASE_NAME, "./target/selectTable");
H2GIS h2GIS = H2GIS.open(map);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ public void testAsType() throws Exception {
fail(e);
}
ISpatialTable table = h2gis.getSpatialTable("name");
assertTrue(table.asType(ISpatialTable.class) instanceof ISpatialTable);
assertTrue(table.asType(ITable.class) instanceof ITable);
assertTrue(table.asType(H2gisSpatialTable.class) instanceof H2gisSpatialTable);
assertTrue(table.asType(H2gisTable.class) instanceof H2gisTable);
assertInstanceOf(ISpatialTable.class, table.asType(ISpatialTable.class));
assertInstanceOf(ITable.class, table.asType(ITable.class));
assertInstanceOf(H2gisSpatialTable.class, table.asType(H2gisSpatialTable.class));
assertInstanceOf(H2gisTable.class, table.asType(H2gisTable.class));
assertNull(table.asType(String.class));
}

@Test
void testReproject() throws SQLException, Exception {
void testReproject() throws Exception {
new File("target/reprojected_table.shp").delete();
H2GIS dataSource = H2GIS.open("./target/test");
dataSource.execute(" DROP TABLE IF EXISTS orbisgis;" +
Expand All @@ -138,7 +138,7 @@ void testReproject() throws SQLException, Exception {
IJdbcTable reprojectedTable = dataSource.getTable(dataSource.load("target/reprojected_table.shp", true));
assertNotNull(reprojectedTable);
assertEquals(2, reprojectedTable.getRowCount());
assertTrue(reprojectedTable instanceof IJdbcSpatialTable);
assertInstanceOf(IJdbcSpatialTable.class, reprojectedTable);

IJdbcSpatialTable spatialReprojectedTable = (IJdbcSpatialTable) reprojectedTable;
assertEquals(2154, spatialReprojectedTable.getSrid());
Expand All @@ -150,7 +150,7 @@ void testReproject() throws SQLException, Exception {
}

@Test
void testSaveQueryInFile() throws SQLException, Exception {
void testSaveQueryInFile() throws Exception {
new File("target/query_table.shp").delete();
H2GIS dataSource = H2GIS.open("./target/test");
dataSource.execute(" DROP TABLE IF EXISTS orbisgis, query_table;" +
Expand All @@ -166,15 +166,15 @@ void testSaveQueryInFile() throws SQLException, Exception {
IJdbcTable queryTable = dataSource.getTable(dataSource.load("target/query_table.shp"));
assertNotNull(queryTable);
assertEquals(2, queryTable.getRowCount());
assertTrue(queryTable instanceof IJdbcSpatialTable);
assertInstanceOf(IJdbcSpatialTable.class, queryTable);

IJdbcSpatialTable spatialReprojectedTable = (IJdbcSpatialTable) queryTable;
assertEquals(4326, spatialReprojectedTable.getSrid());

IJdbcSpatialTable spLoaded = dataSource.getSpatialTable("QUERY_TABLE");
assertEquals(2, spLoaded.getRowCount());
assertEquals(4326, spLoaded.getSrid());
assertTrue(spLoaded.getFirstRow().get(1) instanceof Point);
assertInstanceOf(Point.class, spLoaded.getFirstRow().get(1));
}
/**
* Test the {@link JdbcSpatialTable#isSpatial()} method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ void firstRowTest() throws Exception {
assertEquals("Simple points", map.get(COL_MEANING));

map = getTempTable().firstRow();
assertTrue(!map.isEmpty());
assertFalse(map.isEmpty());

map = getEmptyTable().firstRow();
assertTrue(map.isEmpty());
Expand All @@ -335,7 +335,7 @@ void firstRowTest() throws Exception {
* Test the {@link IJdbcTable#getLocation()} method.
*/
@Test
public void testGetLocation() throws SQLException, Exception {
public void testGetLocation() throws Exception {
assertEquals("catalog.schema.table", new PostgisTable(
new TableLocation("catalog", "schema", "table"),
"not a request", dataSource.getConnection().createStatement(), null, dataSource).getLocation());
Expand All @@ -356,7 +356,7 @@ public void testGetLocation() throws SQLException, Exception {
* Test the {@link JdbcTable#getMetaData()} constructor.
*/
@Test
void testGetMetadata() throws SQLException, Exception {
void testGetMetadata() throws Exception {
assertNotNull(getTable().getMetaData());
assertNotNull(getLinkedTable().getMetaData());
assertNotNull(getTempTable().getMetaData());
Expand Down Expand Up @@ -679,7 +679,7 @@ void testGetTable() throws Exception {
@Test
public void testAsType() throws Exception {
assertNotNull(getTable().asType(ITable.class));
assertTrue(getTable().asType(ITable.class) instanceof ITable);
assertInstanceOf(ITable.class, getTable().asType(ITable.class));
assertNotNull(getTable().asType(ISpatialTable.class));
assertEquals("+--------------------+\n" +
"| ORBISGIS_TABLE |\n" +
Expand Down
2 changes: 1 addition & 1 deletion data/postgis/src/main/java/org/orbisgis/data/POSTGIS.java
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ public void dropColumn(String tableName, String... columnName) {
return;
}
try {
StringBuilder sb = new StringBuilder("ALTER TABLE IF EXISTS " + TableLocation.parse(tableName, DBTypes.POSTGIS).toString());
StringBuilder sb = new StringBuilder("ALTER TABLE IF EXISTS " + TableLocation.parse(tableName, DBTypes.POSTGIS));
int count = columnName.length;
for (int i = 0; i < count; i++) {
String col = columnName[i];
Expand Down
Loading

0 comments on commit 1464595

Please sign in to comment.