Search in sources :

Example 1 with NodeDialogNodeView

use of org.knime.testing.node.dialog.NodeDialogNodeView 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"));
}
Also used : NodeSettingsWO(org.knime.core.node.NodeSettingsWO) NodeDialogNodeModel(org.knime.testing.node.dialog.NodeDialogNodeModel) IOException(java.io.IOException) TextDataService(org.knime.core.webui.data.text.TextDataService) NodeDialogNodeView(org.knime.testing.node.dialog.NodeDialogNodeView) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) NodeDialogTest.createNodeDialog(org.knime.core.webui.node.dialog.NodeDialogTest.createNodeDialog) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)1 Test (org.junit.Test)1 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)1 NodeSettingsWO (org.knime.core.node.NodeSettingsWO)1 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)1 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)1 TextDataService (org.knime.core.webui.data.text.TextDataService)1 NodeDialogTest.createNodeDialog (org.knime.core.webui.node.dialog.NodeDialogTest.createNodeDialog)1 NodeDialogNodeModel (org.knime.testing.node.dialog.NodeDialogNodeModel)1 NodeDialogNodeView (org.knime.testing.node.dialog.NodeDialogNodeView)1