55import static org .junit .Assert .assertNotNull ;
66import static org .junit .Assert .assertTrue ;
77
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 ;
129
13- import org .junit .AfterClass ;
1410import org .junit .Before ;
1511import org .junit .BeforeClass ;
1612import org .junit .Test ;
2420import org .knime .core .data .def .IntCell ;
2521import org .knime .core .data .def .LongCell ;
2622import 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 ;
3428import org .scijava .Context ;
3529import org .scijava .ItemIO ;
3630import org .scijava .command .Command ;
37- import org .scijava .command .CommandModule ;
31+ import org .scijava .command .CommandInfo ;
3832import org .scijava .command .CommandService ;
39- import org .scijava .plugin .DefaultPluginFinder ;
4033import org .scijava .plugin .Parameter ;
41- import org .scijava .plugin .PluginIndex ;
42- import org .scijava .service .Service ;
4334
4435/**
4536 * Test for {@link ColumnInputMappingKnimePreprocessor} and
4637 * {@link DefaultKnimePostprocessor}.
4738 *
4839 * @author Jonathan Hale (University of Konstanz)
4940 */
50- public class KnimeProcessorTest {
41+ public class NodeModuleTest {
5142
5243 private static Context context ;
5344
5445 @ Parameter
5546 CommandService m_commandService ;
56- @ Parameter
57- InputDataRowService m_inputRowService ;
58- @ Parameter
59- OutputDataRowService m_outputCellsService ;
6047
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 ;
6450
6551 // Create the test table
6652 private static final DataRow m_testRow = new DefaultRow (new RowKey ("TestRow001" ), BooleanCell .TRUE , new IntCell (42 ),
@@ -72,14 +58,7 @@ public class KnimeProcessorTest {
7258
7359 @ BeforeClass
7460 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 ();
8362 }
8463
8564 @ Before
@@ -88,30 +67,42 @@ public void setUp() {
8867 }
8968
9069 @ Test
91- public void testModuleProcessing () throws InterruptedException , ExecutionException {
92- assertNotNull (m_inputRowService );
93- assertNotNull (m_outputCellsService );
70+ public void testModuleExecution () throws Exception {
9471 assertNotNull (m_commandService );
95- m_inputRowService .setInputDataRow (m_testRow );
96- m_inputRowService .setDataTableSpec (m_spec );
9772
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 ));
10175 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 ());
115106 }
116107
117108 /**
0 commit comments