Search in sources :

Example 1 with TextReExecuteDataService

use of org.knime.core.webui.data.text.TextReExecuteDataService 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"));
}
Also used : TextInitialDataService(org.knime.core.webui.data.text.TextInitialDataService) TextDataService(org.knime.core.webui.data.text.TextDataService) Optional(java.util.Optional) TextReExecuteDataService(org.knime.core.webui.data.text.TextReExecuteDataService) Matchers.containsString(org.hamcrest.Matchers.containsString) IOException(java.io.IOException) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)1 Optional (java.util.Optional)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Test (org.junit.Test)1 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)1 TextDataService (org.knime.core.webui.data.text.TextDataService)1 TextInitialDataService (org.knime.core.webui.data.text.TextInitialDataService)1 TextReExecuteDataService (org.knime.core.webui.data.text.TextReExecuteDataService)1