Search in sources :

Example 1 with TextInitialDataService

use of org.knime.core.webui.data.text.TextInitialDataService in project knime-core by knime.

the class NodeViewEntTest method testNodeViewEnt.

/**
 * Tests {@link NodeViewEnt#NodeViewEnt(NativeNodeContainer)}.
 *
 * @throws IOException
 */
@Test
public void testNodeViewEnt() throws IOException {
    var wfm = WorkflowManagerUtil.createEmptyWorkflow();
    NativeNodeContainer nncWithoutNodeView = WorkflowManagerUtil.createAndAddNode(wfm, new VirtualSubNodeInputNodeFactory(null, new PortType[0]));
    Assert.assertThrows(IllegalArgumentException.class, () -> new NodeViewEnt(nncWithoutNodeView));
    Function<NodeViewNodeModel, NodeView> nodeViewCreator = m -> {
        Page p = Page.builder(() -> "blub", "index.html").build();
        return NodeViewTest.createNodeView(p, new TextInitialDataService() {

            @Override
            public String getInitialData() {
                return "dummy initial data";
            }
        }, null, null);
    };
    NativeNodeContainer nnc = WorkflowManagerUtil.createAndAddNode(wfm, new NodeViewNodeFactory(nodeViewCreator));
    wfm.executeAllAndWaitUntilDone();
    nnc.setNodeMessage(NodeMessage.newWarning("node message"));
    nnc.getNodeAnnotation().getData().setText("node annotation");
    var ent = new NodeViewEnt(nnc, null);
    assertThat(ent.getProjectId(), startsWith("workflow"));
    assertThat(ent.getWorkflowId(), is("root"));
    assertThat(ent.getNodeId(), is("root:2"));
    assertThat(ent.getInitialData(), is("dummy initial data"));
    assertThat(ent.getInitialSelection(), is(nullValue()));
    var resourceInfo = ent.getResourceInfo();
    assertThat(resourceInfo.getUrl(), endsWith("index.html"));
    assertThat(resourceInfo.getPath(), is(nullValue()));
    assertThat(resourceInfo.getType(), is(Resource.Type.HTML.toString()));
    assertThat(resourceInfo.getId(), is(PageUtil.getPageId(nnc, false, false)));
    var nodeInfo = ent.getNodeInfo();
    assertThat(nodeInfo.getNodeName(), is("NodeView"));
    assertThat(nodeInfo.getNodeAnnotation(), is("node annotation"));
    assertThat(nodeInfo.getNodeState(), is("executed"));
    assertThat(nodeInfo.getNodeWarnMessage(), is("node message"));
    assertThat(nodeInfo.getNodeErrorMessage(), is(nullValue()));
    // a node view as a 'component' without initial data
    nodeViewCreator = m -> {
        Page p = Page.builder(PageTest.BUNDLE_ID, "files", "component.umd.min.js").build();
        return NodeViewTest.createNodeView(p);
    };
    nnc = WorkflowManagerUtil.createAndAddNode(wfm, new NodeViewNodeFactory(nodeViewCreator));
    wfm.executeAllAndWaitUntilDone();
    ent = new NodeViewEnt(nnc, null);
    resourceInfo = ent.getResourceInfo();
    assertThat(ent.getInitialData(), is(nullValue()));
    assertThat(resourceInfo.getType(), is(Resource.Type.VUE_COMPONENT_LIB.toString()));
    assertThat(resourceInfo.getUrl(), endsWith("component.umd.min.js"));
    assertThat(resourceInfo.getPath(), is(nullValue()));
    // test to create a node view entity while running headless (e.g. on the executor)
    NativeNodeContainer nnc2 = nnc;
    runOnExecutor(() -> {
        var ent2 = new NodeViewEnt(nnc2, null);
        assertThat(ent2.getResourceInfo().getPath(), endsWith("component.umd.min.js"));
        assertThat(ent2.getResourceInfo().getUrl(), is(nullValue()));
    });
    WorkflowManagerUtil.disposeWorkflow(wfm);
}
Also used : NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) NodeMessage(org.knime.core.node.workflow.NodeMessage) VirtualSubNodeInputNodeFactory(org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeInputNodeFactory) NodeView(org.knime.core.webui.node.view.NodeView) SelectionEventMode(org.knime.gateway.impl.service.events.SelectionEventSource.SelectionEventMode) RowKey(org.knime.core.data.RowKey) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Resource(org.knime.core.webui.page.Resource) SelectionEventSource(org.knime.gateway.impl.service.events.SelectionEventSource) Page(org.knime.core.webui.page.Page) Function(java.util.function.Function) PageUtil(org.knime.core.webui.page.PageUtil) SelectionEvent(org.knime.gateway.impl.service.events.SelectionEvent) WorkflowManagerUtil(org.knime.testing.util.WorkflowManagerUtil) Matchers.nullValue(org.hamcrest.Matchers.nullValue) BiConsumer(java.util.function.BiConsumer) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ONE_HUNDRED_MILLISECONDS(org.awaitility.Duration.ONE_HUNDRED_MILLISECONDS) PortType(org.knime.core.node.port.PortType) NodeViewNodeFactory(org.knime.testing.node.view.NodeViewNodeFactory) Awaitility.await(org.awaitility.Awaitility.await) PageTest(org.knime.core.webui.page.PageTest) NodeViewTest(org.knime.core.webui.node.view.NodeViewTest) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Test(org.junit.Test) NodeViewManagerTest.runOnExecutor(org.knime.core.webui.node.view.NodeViewManagerTest.runOnExecutor) Matchers.startsWith(org.hamcrest.Matchers.startsWith) Mockito.verify(org.mockito.Mockito.verify) List(java.util.List) NodeViewNodeModel(org.knime.testing.node.view.NodeViewNodeModel) TextInitialDataService(org.knime.core.webui.data.text.TextInitialDataService) Matchers.is(org.hamcrest.Matchers.is) Assert(org.junit.Assert) Matchers.endsWith(org.hamcrest.Matchers.endsWith) Collections(java.util.Collections) FIVE_SECONDS(org.awaitility.Duration.FIVE_SECONDS) Mockito.mock(org.mockito.Mockito.mock) SelectionEventSourceTest(org.knime.gateway.impl.service.events.SelectionEventSourceTest) TextInitialDataService(org.knime.core.webui.data.text.TextInitialDataService) NodeViewNodeFactory(org.knime.testing.node.view.NodeViewNodeFactory) VirtualSubNodeInputNodeFactory(org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeInputNodeFactory) Page(org.knime.core.webui.page.Page) NodeViewNodeModel(org.knime.testing.node.view.NodeViewNodeModel) NodeView(org.knime.core.webui.node.view.NodeView) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) PortType(org.knime.core.node.port.PortType) PageTest(org.knime.core.webui.page.PageTest) NodeViewTest(org.knime.core.webui.node.view.NodeViewTest) Test(org.junit.Test) SelectionEventSourceTest(org.knime.gateway.impl.service.events.SelectionEventSourceTest)

Example 2 with TextInitialDataService

use of org.knime.core.webui.data.text.TextInitialDataService 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)2 Test (org.junit.Test)2 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)2 TextInitialDataService (org.knime.core.webui.data.text.TextInitialDataService)2 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 BiConsumer (java.util.function.BiConsumer)1 Function (java.util.function.Function)1 Awaitility.await (org.awaitility.Awaitility.await)1 FIVE_SECONDS (org.awaitility.Duration.FIVE_SECONDS)1 ONE_HUNDRED_MILLISECONDS (org.awaitility.Duration.ONE_HUNDRED_MILLISECONDS)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Matchers.endsWith (org.hamcrest.Matchers.endsWith)1 Matchers.is (org.hamcrest.Matchers.is)1 Matchers.nullValue (org.hamcrest.Matchers.nullValue)1 Matchers.startsWith (org.hamcrest.Matchers.startsWith)1 Assert (org.junit.Assert)1 RowKey (org.knime.core.data.RowKey)1