5
5
import static org .junit .Assert .assertNotNull ;
6
6
import static org .junit .Assert .assertTrue ;
7
7
8
- import java .util .Arrays ;
9
- import java .util .List ;
10
- import java .util .concurrent .ExecutionException ;
11
- import java .util .concurrent .Future ;
8
+ import java .util .ArrayList ;
12
9
13
- import org .junit .AfterClass ;
14
10
import org .junit .Before ;
15
11
import org .junit .BeforeClass ;
16
12
import org .junit .Test ;
24
20
import org .knime .core .data .def .IntCell ;
25
21
import org .knime .core .data .def .LongCell ;
26
22
import org .knime .core .data .def .StringCell ;
27
- import org .knime .scijava .commands .converter .KNIMEConverterService ;
28
- import org .knime .scijava .commands .io .DefaultInputDataRowService ;
29
- import org .knime .scijava .commands .io .DefaultOutputDataRowService ;
30
- import org .knime .scijava .commands .io .InputDataRowService ;
31
- import org .knime .scijava .commands .io .OutputDataRowService ;
32
- import org .knime .scijava .commands .process .DefaultKnimePostprocessor ;
33
- import org .knime .scijava .core .ResourceAwareClassLoader ;
23
+ import org .knime .core .node .NodeLogger ;
24
+ import org .knime .scijava .commands .CellOutput ;
25
+ import org .knime .scijava .commands .SciJavaGateway ;
26
+ import org .knime .scijava .commands .module .NodeModule ;
27
+ import org .knime .scijava .commands .module .NodeModuleService ;
34
28
import org .scijava .Context ;
35
29
import org .scijava .ItemIO ;
36
30
import org .scijava .command .Command ;
37
- import org .scijava .command .CommandModule ;
31
+ import org .scijava .command .CommandInfo ;
38
32
import org .scijava .command .CommandService ;
39
- import org .scijava .plugin .DefaultPluginFinder ;
40
33
import org .scijava .plugin .Parameter ;
41
- import org .scijava .plugin .PluginIndex ;
42
- import org .scijava .service .Service ;
43
34
44
35
/**
45
36
* Test for {@link ColumnInputMappingKnimePreprocessor} and
46
37
* {@link DefaultKnimePostprocessor}.
47
38
*
48
39
* @author Jonathan Hale (University of Konstanz)
49
40
*/
50
- public class KnimeProcessorTest {
41
+ public class NodeModuleTest {
51
42
52
43
private static Context context ;
53
44
54
45
@ Parameter
55
46
CommandService m_commandService ;
56
- @ Parameter
57
- InputDataRowService m_inputRowService ;
58
- @ Parameter
59
- OutputDataRowService m_outputCellsService ;
60
47
61
- protected static List <Class <? extends Service >> requiredServices = Arrays .<Class <? extends Service >> asList (
62
- DefaultInputDataRowService .class , DefaultOutputDataRowService .class , CommandService .class ,
63
- KNIMEConverterService .class );
48
+ @ Parameter
49
+ NodeModuleService m_nodeModuleService ;
64
50
65
51
// Create the test table
66
52
private static final DataRow m_testRow = new DefaultRow (new RowKey ("TestRow001" ), BooleanCell .TRUE , new IntCell (42 ),
@@ -72,14 +58,7 @@ public class KnimeProcessorTest {
72
58
73
59
@ BeforeClass
74
60
public static void setUpOnce () {
75
- ResourceAwareClassLoader cl = new ResourceAwareClassLoader (Thread .currentThread ().getContextClassLoader (), KnimeProcessorTest .class );
76
-
77
- context = new Context (requiredServices , new PluginIndex (new DefaultPluginFinder (cl )));
78
- }
79
-
80
- @ AfterClass
81
- public static void tearDown () {
82
- context .dispose ();
61
+ context = SciJavaGateway .get ().getGlobalContext ();
83
62
}
84
63
85
64
@ Before
@@ -88,30 +67,42 @@ public void setUp() {
88
67
}
89
68
90
69
@ Test
91
- public void testModuleProcessing () throws InterruptedException , ExecutionException {
92
- assertNotNull (m_inputRowService );
93
- assertNotNull (m_outputCellsService );
70
+ public void testModuleExecution () throws Exception {
94
71
assertNotNull (m_commandService );
95
- m_inputRowService .setInputDataRow (m_testRow );
96
- m_inputRowService .setDataTableSpec (m_spec );
97
72
98
- Future <CommandModule > command = m_commandService .run (MyCommand .class , true );
99
- assertNotNull (command );
100
- CommandModule commandModule = command .get ();
73
+ NodeModule commandModule = m_nodeModuleService .createNodeModule (new CommandInfo (MyCommand .class ), null , m_spec ,
74
+ NodeLogger .getLogger (NodeModuleTest .class ));
101
75
assertNotNull (commandModule );
102
- assertFalse ("Command was cancelled: " + commandModule .getCancelReason (), commandModule .isCanceled ());
103
-
104
- DataCell [] cells = m_outputCellsService .getOutputDataCells ();
105
- assertNotNull (cells );
106
- assertEquals (7 , cells .length );
107
-
108
- assertTrue ("Boolean output was not extracted correctly!" , ((BooleanCell ) cells [0 ]).getBooleanValue ());
109
- assertEquals ("Byte output was not extracted correctly!" , 42 , ((IntCell ) cells [1 ]).getIntValue ());
110
- assertEquals ("Short output was not extracted correctly!" , 420 , ((IntCell ) cells [2 ]).getIntValue ());
111
- assertEquals ("Integer output was not extracted correctly!" , 42000 , ((IntCell ) cells [3 ]).getIntValue ());
112
- assertEquals ("Long output was not extracted correctly!" , 4200000 , ((LongCell ) cells [4 ]).getLongValue ());
113
- assertEquals ("String output was not extracted correctly!" , "KNIME" , ((StringCell ) cells [5 ]).getStringValue ());
114
- assertEquals ("Character output was not extracted correctly!" , " " , ((StringCell ) cells [6 ]).getStringValue ());
76
+
77
+ // assertFalse("Command was cancelled: " +
78
+ // commandModule.getCancelReason(), commandModule.isCanceled());
79
+
80
+ ArrayList <DataCell []> cells = new ArrayList <>();
81
+ CellOutput cellOutput = new CellOutput () {
82
+
83
+ ArrayList <DataCell []> m_cells = cells ;
84
+
85
+ @ Override
86
+ public void push (DataCell [] cells ) throws InterruptedException {
87
+ assertNotNull (cells );
88
+ assertEquals (cells .length , 7 );
89
+
90
+ assertTrue ("Boolean output was not extracted correctly!" , ((BooleanCell ) cells [0 ]).getBooleanValue ());
91
+ assertEquals ("Byte output was not extracted correctly!" , 42 , ((IntCell ) cells [1 ]).getIntValue ());
92
+ assertEquals ("Short output was not extracted correctly!" , 420 , ((IntCell ) cells [2 ]).getIntValue ());
93
+ assertEquals ("Integer output was not extracted correctly!" , 42000 , ((IntCell ) cells [3 ]).getIntValue ());
94
+ assertEquals ("Long output was not extracted correctly!" , 4200000 , ((LongCell ) cells [4 ]).getLongValue ());
95
+ assertEquals ("String output was not extracted correctly!" , "KNIME" ,
96
+ ((StringCell ) cells [5 ]).getStringValue ());
97
+ assertEquals ("Character output was not extracted correctly!" , " " ,
98
+ ((StringCell ) cells [6 ]).getStringValue ());
99
+
100
+ m_cells .add (cells );
101
+ }
102
+ };
103
+ commandModule .run (m_testRow , cellOutput , null );
104
+
105
+ assertFalse ("No cells were pushed" , cells .isEmpty ());
115
106
}
116
107
117
108
/**
0 commit comments