diff --git a/data-manager/src/test/java/org/orbisgis/datamanager/h2gis/H2GISTests.java b/data-manager/src/test/java/org/orbisgis/datamanager/h2gis/H2GISTests.java index a0610f80..7ffb9839 100644 --- a/data-manager/src/test/java/org/orbisgis/datamanager/h2gis/H2GISTests.java +++ b/data-manager/src/test/java/org/orbisgis/datamanager/h2gis/H2GISTests.java @@ -329,4 +329,17 @@ public void hasTable() throws SQLException { assertTrue(h2GIS.hasTable("table1")); assertFalse(h2GIS.hasTable("OrbisGIS")); } + + @Test + void testGetTableOnEmptyTable() throws SQLException { + Map map = new HashMap<>(); + map.put(DataSourceFactory.JDBC_DATABASE_NAME, "./target/loadH2GIS"); + H2GIS h2GIS = H2GIS.open(map); + h2GIS.execute("DROP TABLE IF EXISTS table1, table2; " + + "CREATE TABLE table1 (id int, the_geom geometry(point));" + + "CREATE TABLE table2 (id int, val varchar);"); + assertNotNull(h2GIS.getSpatialTable("table1")); + assertNotNull(h2GIS.getSpatialTable("table1").getGeometricColumns()); + assertNotNull(h2GIS.getTable("table1")); + } } diff --git a/process-manager/src/main/java/org/orbisgis/processmanager/Process.java b/process-manager/src/main/java/org/orbisgis/processmanager/Process.java index 482f751d..f26e7aac 100644 --- a/process-manager/src/main/java/org/orbisgis/processmanager/Process.java +++ b/process-manager/src/main/java/org/orbisgis/processmanager/Process.java @@ -213,24 +213,26 @@ private Object[] getClosureArgs(LinkedHashMap inputDataMap){ @Override public boolean execute(LinkedHashMap inputDataMap) { + LinkedHashMap map = (inputDataMap == null ? new LinkedHashMap<>() : inputDataMap); if(closure == null){ LOGGER.error("The process should have a Closure defined."); return false; } LOGGER.debug("Starting the execution of '" + this.getTitle() + "'."); - if(inputDataMap != null && (inputs.size() < inputDataMap.size() || inputs.size()-defaultValues.size() > inputDataMap.size())){ + if((inputs.size() < map.size() || inputs.size()-defaultValues.size() > map.size())){ LOGGER.error("The number of the input data map and the number of process input are different, should" + - " be between " + (closure.getMaximumNumberOfParameters()-defaultValues.size()) + " and " + closure.getMaximumNumberOfParameters() + "."); + " be between " + (closure.getMaximumNumberOfParameters()-defaultValues.size()) + " and " + + closure.getMaximumNumberOfParameters() + "."); return false; } Object result; try { if(inputs.size() != 0) { - Closure cl = getClosureWithCurry(inputDataMap); + Closure cl = getClosureWithCurry(map); if(cl == null){ return false; } - result = cl.call(getClosureArgs(inputDataMap)); + result = cl.call(getClosureArgs(map)); } else { result = closure.call(); diff --git a/process-manager/src/test/groovy/org/orbisgis/processmanager/TestProcess.groovy b/process-manager/src/test/groovy/org/orbisgis/processmanager/TestProcess.groovy index 1898547e..c02bb0a4 100644 --- a/process-manager/src/test/groovy/org/orbisgis/processmanager/TestProcess.groovy +++ b/process-manager/src/test/groovy/org/orbisgis/processmanager/TestProcess.groovy @@ -480,5 +480,43 @@ class TestProcess { assertTrue mapper([inA2: "a"]) assertEquals "tata", mapper.getResults().outB1 } + + @Test + void testOnlyOneOptionalInput() { + String[] arr = ["key1", "key2"] + def process = processManager.create() + .title("simple process") + .description("description") + .keywords("key1", "key2") + .inputs([inputA: ["key1", "key2"], inputB: String]) + .outputs([outputA: String]) + .version("version") + .run({ inputA, inputB -> [outputA: inputA] }) + .process + assertTrue process.execute([inputB: String]) + assertFalse process.results.isEmpty() + assertTrue process.results.containsKey("outputA") + assertEquals arr.join(""), process.results.outputA.join("") + } + + @Test + void testBadTypeInput() { + String[] arr = ["key1", "key2"] + def process = processManager.create() + .title("simple process") + .description("description") + .keywords("key1", "key2") + .inputs([inputA: String[], inputB: "toto"]) + .outputs([outputA: String]) + .version("version") + .run({ inputA, inputB -> [outputA: inputA] }) + .process + assertFalse process.execute([inputB: 56D]) + assertTrue process.results.isEmpty() + //assertFalse process.execute([inputA: arr]) + //assertTrue process.results.isEmpty() + assertTrue process.execute([inputA: ["key1", "key2"]]) + assertFalse process.results.isEmpty() + } }