Skip to content

Commit

Permalink
Merge pull request #164 from SPalominos/master
Browse files Browse the repository at this point in the history
Process input data fix and test
  • Loading branch information
SPalominos authored Nov 21, 2019
2 parents 82e9bbf + d3d531a commit c30d16d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -329,4 +329,17 @@ public void hasTable() throws SQLException {
assertTrue(h2GIS.hasTable("table1"));
assertFalse(h2GIS.hasTable("OrbisGIS"));
}

@Test
void testGetTableOnEmptyTable() throws SQLException {
Map<String, String> 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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -213,24 +213,26 @@ private Object[] getClosureArgs(LinkedHashMap<String, Object> inputDataMap){

@Override
public boolean execute(LinkedHashMap<String, Object> inputDataMap) {
LinkedHashMap<String, Object> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

0 comments on commit c30d16d

Please sign in to comment.