8000 Merge pull request #17 from scijava/check-compatible-inputs · scijava/batch-processor@d501636 · GitHub
[go: up one dir, main page]

Skip to content

Commit d501636

Browse files
authored
Merge pull request #17 from scijava/check-compatible-inputs
2 parents 52d68f9 + 5490ab3 commit d501636

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.scijava</groupId>
77
<artifactId>pom-scijava</artifactId>
8-
<version>19.1.1</version>
8+
<version>23.1.1</version>
99
<relativePath />
1010
</parent>
1111

src/main/java/org/scijava/batch/FileBatchService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import org.scijava.Priority;
77
import org.scijava.command.CommandService;
8+
import org.scijava.log.LogService;
89
import org.scijava.module.ModuleInfo;
910
import org.scijava.plugin.Parameter;
1011
import org.scijava.plugin.Plugin;
@@ -15,6 +16,9 @@
1516
public final class FileBatchService extends AbstractService implements
1617
BatchService {
1718

19+
@Parameter
20+
private LogService log;
21+
1822
@Parameter
1923
private CommandService commandService;
2024

@@ -28,6 +32,11 @@ public boolean supports(Class<?> type) {
2832

2933
@Override
3034
public void run(ModuleInfo moduleInfo) {
35+
// check if moduleInfo has batchable inputs
36+
if (batchableInputs(moduleInfo).isEmpty()) {
37+
log.error("No compatible inputs (of type File) found.");
38+
return;
39+
}
3140
// Call ModuleBatchProcessor with input moduleInfo
3241
HashMap<String, Object> inputMap = new HashMap<>();
3342
inputMap.put("moduleInfo", moduleInfo);

src/test/java/org/scijava/batch/BatchServiceTest.java

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
import static org.junit.Assert.assertEquals;
44
import static org.junit.Assert.assertNotNull;
5+
import static org.junit.Assert.assertTrue;
56

67
import java.io.File;
78
import java.io.StringReader;
89
import java.util.HashMap;
10+
import java.util.List;
911
import java.util.concurrent.ExecutionException;
1012

1113
import net.imagej.table.Table;
@@ -17,6 +19,7 @@
1719
import org.scijava.command.CommandInfo;
1820
import org.scijava.command.CommandService;
1921
import org.scijava.module.Module;
22+
import org.scijava.module.ModuleItem;
2023
import org.scijava.module.ModuleService;
2124
import org.scijava.script.ScriptInfo;
2225
import org.scijava.service.SciJavaService;
@@ -44,6 +47,37 @@ public void testContext() {
4447
.getService(BatchService.class);
4548
assertNotNull(batchService);
4649
}
50+
51+
@Test
52+
public void testBatchableFileInputs() {
53+
String script = "" //
54+
+ "#@ File fileInput\n" //
55+
+ "#@ String stringInput\n" //
56+
+ "#@ Integer integerInput\n" //
57+
+ "#@ Double doubleInput\n" //
58+
+ "";
59+
ScriptInfo scriptInfo = createInfo(script);
60+
BatchService batchService = context.getService(BatchService.class);
61+
List<ModuleItem<?>> compatibleInputs = batchService.batchableInputs(
62+
scriptInfo);
63< 8000 code class="diff-text syntax-highlighted-line addition">+
assertEquals("Wrong number of batchable inputs", 1, compatibleInputs
64+
.size());
65+
}
66+
67+
@Test
68+
public void testNoCompatibleInputs() {
69+
String script = "" //
70+
+ "#@ String stringInput\n" //
71+
+ "#@ Integer integerInput\n" //
72+
+ "#@ Double doubleInput\n" //
73+
+ "";
74+
ScriptInfo scriptInfo = createInfo(script);
75+
BatchService batchService = context.getService(BatchService.class);
76+
List<ModuleItem<?>> compatibleInputs = batchService.batchableInputs(
77+
scriptInfo);
78+
assertTrue("Wrong inputs found to be compatible", compatibleInputs
79+
.isEmpty());
80+
}
4781

4882
@Test
4983
public void testModuleBatchProcessor() {
@@ -52,9 +86,7 @@ public void testModuleBatchProcessor() {
5286
+ "#@output result\n" //
5387
+ "" //
5488
+ "result = input";
55-
StringReader scriptReader = new StringReader(script);
56-
ScriptInfo scriptInfo = new ScriptInfo(context, "Foo.groovy",
57-
scriptReader);
89+
ScriptInfo scriptInfo = createInfo(script);
5890

5991
assertEquals("Wrong script language", "Groovy", scriptInfo
6092
.getLanguage().getLanguageName());
@@ -90,4 +122,11 @@ public void testModuleBatchProcessor() {
90122
outputs.getColumnHeader(0));
91123
assertEquals("Wrong file name", "quo.txt", outputs.getRowHeader(2));
92124
}
125+
126+
/* --- Helper methods --- */
127+
128+
private ScriptInfo createInfo(String script) {
129+
StringReader scriptReader = new StringReader(script);
130+
return new ScriptInfo(context, "Foo.groovy", scriptReader);
131+
}
93132
}

0 commit comments

Comments
 (0)
0