use of org.knime.core.webui.data.text.TextDataService in project knime-core by knime.
the class NodeViewManagerTest method testCallDataServices.
/**
* Tests {@link NodeViewManager#callTextInitialDataService(NodeContainer)},
* {@link NodeViewManager#callTextDataService(NodeContainer, String)} and
* {@link NodeViewManager#callTextApplyDataService(NodeContainer, String)}
*/
@Test
public void testCallDataServices() {
var page = Page.builder(() -> "test page content", "index.html").build();
var nodeView = createNodeView(page, new TextInitialDataService() {
@Override
public String getInitialData() {
return "init service";
}
}, new TextDataService() {
@Override
public String handleRequest(final String request) {
return "general data service";
}
}, new TextReExecuteDataService() {
@Override
public Optional<String> validateData(final String data) throws IOException {
throw new UnsupportedOperationException("should not be called in this test");
}
@Override
public void applyData(final String data) throws IOException {
throw new UnsupportedOperationException("should not be called in this test");
}
@Override
public void reExecute(final String data) throws IOException {
throw new IOException("re-execute data service");
}
});
NativeNodeContainer nc = NodeViewManagerTest.createNodeWithNodeView(m_wfm, m -> nodeView);
var nodeViewManager = NodeViewManager.getInstance();
assertThat(nodeViewManager.callTextInitialDataService(nc), is("init service"));
assertThat(nodeViewManager.callTextDataService(nc, ""), is("general data service"));
String message = assertThrows(IOException.class, () -> nodeViewManager.callTextApplyDataService(nc, "ERROR,test")).getMessage();
assertThat(message, is("re-execute data service"));
}
use of org.knime.core.webui.data.text.TextDataService in project knime-core by knime.
the class NodeDialogManagerTest method testCallDataServices.
/**
* Tests {@link NodeDialogManager#callTextInitialDataService(NodeContainer)},
* {@link NodeDialogManager#callTextDataService(NodeContainer, String)} and
* {@link NodeDialogManager#callTextApplyDataService(NodeContainer, String)}
*
* @throws IOException
* @throws InvalidSettingsException
*/
@Test
public void testCallDataServices() throws IOException, InvalidSettingsException {
var page = Page.builder(() -> "test page content", "index.html").build();
Supplier<NodeDialog> nodeDialogSupplier = () -> createNodeDialog(page, new // NOSONAR
TextSettingsDataService() {
@Override
public void applyData(final String s, final Map<SettingsType, NodeSettingsWO> settings) {
var split = s.split(",");
settings.get(SettingsType.MODEL).addString(split[0], split[1]);
settings.get(SettingsType.VIEW).addString(split[0], split[1]);
}
@Override
public String getInitialData(final Map<SettingsType, NodeSettingsRO> settings, final PortObjectSpec[] specs) {
assertThat(settings.size(), is(2));
return "the node settings";
}
}, new TextDataService() {
@Override
public String handleRequest(final String request) {
return "general data service";
}
});
NativeNodeContainer nc = NodeDialogManagerTest.createNodeWithNodeDialog(m_wfm, nodeDialogSupplier);
var nodeDialogManager = NodeDialogManager.getInstance();
assertThat(nodeDialogManager.callTextInitialDataService(nc), is("the node settings"));
assertThat(nodeDialogManager.callTextDataService(nc, ""), is("general data service"));
nodeDialogManager.callTextApplyDataService(nc, "key,node settings value");
var modelSettings = ((NodeDialogNodeModel) nc.getNode().getNodeModel()).getLoadNodeSettings();
assertThat(modelSettings.getString("key"), is("node settings value"));
assertThat(nc.getNodeSettings().getNodeSettings("model").getString("key"), is("node settings value"));
var viewSettings = ((NodeDialogNodeView) NodeViewManager.getInstance().getNodeView(nc)).getLoadNodeSettings();
assertThat(viewSettings.getString("key"), is("node settings value"));
assertThat(nc.getNodeSettings().getNodeSettings("view").getString("key"), is("node settings value"));
String message = assertThrows(IOException.class, () -> nodeDialogManager.callTextApplyDataService(nc, "ERROR,invalid")).getMessage();
assertThat(message, is("Invalid node settings"));
}
Aggregations