Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Refactoring and cleanup #49

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f5e223a
Refactor scijava integration
dietzc Aug 29, 2016
ff8a056
Add javadoc to everything and cleanup.
Squareys Sep 12, 2016
82eeeac
Rename ConverterCacheService to KNIMEConverterService
Squareys Sep 12, 2016
3fbb32d
Avoid deprecated setResolved method
Squareys Sep 12, 2016
f23b70d
Always use NodeModuleOutputChangedListener, even for single row outputs
Squareys Sep 12, 2016
b3c4f7a
Pre is never null
Squareys Sep 12, 2016
215d97f
Fix MultiOutputListener @Parameters not being marked resolved
Squareys Sep 12, 2016
fe6e1bb
Avoid deprecated ResourceAwareClassLoader constructor
Squareys Sep 12, 2016
fbd8bef
Move per-node-execution preprocessing into private method.
Squareys Sep 12, 2016
c811481
Fix tiny bug
Squareys Sep 12, 2016
76acbea
Rename KnimeProcessorTest to NodeModuleTest
Squareys Sep 12, 2016
8d9bfd4
Avoid null checking getWidgetStyle()
Squareys Sep 12, 2016
24bc5ad
More javadoc
Squareys Sep 12, 2016
488620f
Use NodeLogger for logging in NodeModules and implement KNIMELogService
Squareys Sep 12, 2016
feeafa9
NodeModuleTest: Adapt to API changes in org.knime.scijava.commands
Squareys Sep 12, 2016
2bd9815
Specify 'manualPush' in constructor instead of setter.
Squareys Sep 12, 2016
6ea385c
Add tests for NodeModule and DefaultNodeModuleService
Squareys Sep 13, 2016
71e1053
Add getPreferredDataType(Class) to KNIMEConverterService
Squareys Sep 13, 2016
d2420bc
Delegate exception during notifyListener()
Squareys Sep 13, 2016
624b28f
Simplyfy getting output DataType for module output.
Squareys Sep 13, 2016
911fe46
Some Code cleanup
Squareys Sep 13, 2016
4e0736e
Remove unused imports
Squareys Sep 13, 2016
255e9fc
Use better way of detecting synthetic "result" ouput
Squareys Sep 26, 2016
321c004
Merge branch 'master' into refactoring-and-cleanup
dietzc Dec 4, 2016
a1480f0
fixes
dietzc Dec 4, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
package org.knime.scijava.commands.testing;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.HashMap;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.knime.core.data.DataCell;
import org.knime.core.data.DataRow;
import org.knime.core.data.DataTableSpec;
import org.knime.core.data.DataType;
import org.knime.core.data.MissingCell;
import org.knime.core.data.RowKey;
import org.knime.core.data.def.BooleanCell;
import org.knime.core.data.def.DefaultRow;
import org.knime.core.data.def.IntCell;
import org.knime.core.data.def.LongCell;
import org.knime.core.data.def.StringCell;
import org.knime.core.node.NodeLogger;
import org.knime.core.node.defaultnodesettings.SettingsModel;
import org.knime.core.node.defaultnodesettings.SettingsModelBoolean;
import org.knime.core.node.defaultnodesettings.SettingsModelString;
import org.knime.scijava.commands.CellOutput;
import org.knime.scijava.commands.SciJavaGateway;
import org.knime.scijava.commands.module.NodeModule;
import org.knime.scijava.commands.module.NodeModuleService;
import org.knime.scijava.commands.settings.models.SettingsModelColumnSelection;
import org.scijava.Context;
import org.scijava.command.CommandInfo;
import org.scijava.plugin.Parameter;

/**
* Test for {@link ColumnInputMappingKnimePreprocessor} and
* {@link DefaultKnimePostprocessor}.
*
* @author Jonathan Hale (University of Konstanz)
*/
public class NodeModuleTest {

static Context context;

@Parameter
NodeModuleService m_nodeModuleService;

// Create the test table
final String[] inputNames = new String[] { "b", "i", "l", "str" };
final String[] outputNames = new String[] { "ob", "oi", "ol", "ostr" };

final DataType[] inputDataTypes = new DataType[] { BooleanCell.TYPE, IntCell.TYPE, LongCell.TYPE, StringCell.TYPE };
final DataTableSpec m_spec = new DataTableSpec(new String[] { "b", "i", "l", "str" }, inputDataTypes);
final DataType[] expectedOutputDataTypes = new DataType[] { BooleanCell.TYPE, IntCell.TYPE, LongCell.TYPE,
StringCell.TYPE };

@BeforeClass
public static void setUpOnce() {
context = SciJavaGateway.get().getGlobalContext();
}

@Before
public void setUp() {
context.inject(this);
}

/**
* Create a NodeModule
* @param emptyTest Whether to have the module check for correct input values
* @return the created Module
*/
private NodeModule createNodeModule(boolean emptyTest) {
final HashMap<String, SettingsModel> settings = new HashMap<String, SettingsModel>();
for (final String name : inputNames) {
settings.put(name, new SettingsModelColumnSelection(name, name));
}

settings.put("emptyTest", new SettingsModelBoolean("emptyTest", emptyTest));

for (int i = 0; i < outputNames.length; ++i) {
settings.put(outputNames[i], new SettingsModelString(outputNames[i], expectedOutputDataTypes[i].getName()));
}

return m_nodeModuleService.createNodeModule(new CommandInfo(ScijavaTestCommand.class), settings, m_spec,
NodeLogger.getLogger(NodeModuleTest.class));
}

@Test
public void testExecution() throws Exception {
final NodeModule nodeModule = createNodeModule(false);

final DataRow testRow = new DefaultRow( //
new RowKey("TestRow001"), //
BooleanCell.TRUE, //
new IntCell(42000), //
new LongCell(4200000), //
new StringCell("KNIME"));

final ArrayList<DataCell[]> cells = new ArrayList<>();
final CellOutput cellOutput = new CellOutput() {

final ArrayList<DataCell[]> m_cells = cells;

@Override
public void push(DataCell[] cells) throws InterruptedException {
assertNotNull(cells);
assertEquals("Unexpected amout of cells pushed.", 4, cells.length);

assertEquals("Unexpected type for pushed cell.", BooleanCell.class, cells[0].getClass());
assertEquals("Unexpected type for pushed cell.", IntCell.class, cells[1].getClass());
assertEquals("Unexpected type for pushed cell.", LongCell.class, cells[2].getClass());
assertEquals("Unexpected type for pushed cell.", StringCell.class, cells[3].getClass());

assertTrue("Boolean output was not extracted correctly!", ((BooleanCell) cells[0]).getBooleanValue());
assertEquals("Integer output was not extracted correctly!", 42000, ((IntCell) cells[1]).getIntValue());
assertEquals("Long output was not extracted correctly!", 4200000, ((LongCell) cells[2]).getLongValue());
assertEquals("String output was not extracted correctly!", "KNIME",
((StringCell) cells[3]).getStringValue());

m_cells.add(cells);
}
};

nodeModule.run(testRow, cellOutput, null);

assertFalse("No cells were pushed", cells.isEmpty());
}

@Test
public void testMissings() throws Exception {
final NodeModule nodeModule = createNodeModule(true);

final DataRow emptyRow = new DefaultRow( //
new RowKey("TestRow001"), //
new MissingCell("Nothing here."), //
new MissingCell("Nothing here either."), //
new MissingCell("Full of nihilism."), //
new MissingCell("Void."));

final ArrayList<DataCell[]> cells = new ArrayList<>();
final CellOutput cellOutput = new CellOutput() {

final ArrayList<DataCell[]> m_cells = cells;

@Override
public void push(DataCell[] cells) throws InterruptedException {
assertNotNull(cells);
assertEquals("Unexpected amout of cells pushed.", 4, cells.length);

for (DataCell cell : cells) {
assertEquals("Unexpected type for pushed cell.", MissingCell.class, cell.getClass());
}

m_cells.add(cells);
}
};

nodeModule.run(emptyRow, cellOutput, null);

assertFalse("No cells were pushed", cells.isEmpty());
}
}
Loading