Search in sources :

Example 1 with NodeViewStateEvent

use of org.knime.gateway.impl.service.events.NodeViewStateEvent in project knime-core by knime.

the class NodeViewEntUtilTest method testCreateNodeViewEntAndSetUpEventSources.

/**
 * Tests
 * {@link NodeViewEntUtil#createNodeViewEntAndEventSources(org.knime.core.node.workflow.NativeNodeContainer, BiConsumer, boolean)}.
 *
 * @throws IOException
 */
@SuppressWarnings("unchecked")
@Test
public void testCreateNodeViewEntAndSetUpEventSources() throws IOException {
    var wfm = WorkflowManagerUtil.createEmptyWorkflow();
    var nnc = WorkflowManagerUtil.createAndAddNode(wfm, new NodeViewNodeFactory(0, 0));
    var hlh = nnc.getNodeModel().getInHiLiteHandler(0);
    wfm.executeAllAndWaitUntilDone();
    BiConsumer<String, Object> eventConsumer = Mockito.mock(BiConsumer.class);
    /* assert that the selection event source is properly set up */
    var eventSource = NodeViewEntUtil.createNodeViewEntAndEventSources(nnc, eventConsumer, false).getSecond()[0];
    fireHiLiteEvent(hlh, "test");
    verify(eventConsumer).accept(eq("SelectionEvent"), argThat(se -> verifySelectionEvent((SelectionEvent) se, "test")));
    /* assert that all the listeners are removed from the selection event source on node state change */
    wfm.resetAndConfigureAll();
    fireHiLiteEvent(hlh, "test2");
    verify(eventConsumer, never()).accept(eq("SelectionEvent"), argThat(se -> verifySelectionEvent((SelectionEvent) se, "test2")));
    eventSource.removeAllEventListeners();
    /* test the selection event source in combination with the node view state event source */
    // test selection events
    wfm.executeAllAndWaitUntilDone();
    NodeViewEntUtil.createNodeViewEntAndEventSources(nnc, eventConsumer, true);
    fireHiLiteEvent(hlh, "test3");
    verify(eventConsumer).accept(eq("SelectionEvent"), argThat(se -> verifySelectionEvent((SelectionEvent) se, "test3")));
    // test node view state event: configured
    wfm.resetAndConfigureAll();
    awaitUntilAsserted(() -> verify(eventConsumer).accept(eq("NodeViewStateEvent"), argThat(se -> verifyNodeViewStateEvent((NodeViewStateEvent) se, "configured", null))));
    // make sure no selection events are fired if node is not executed
    fireHiLiteEvent(hlh, "test4");
    verify(eventConsumer, never()).accept(eq("SelectionEvent"), argThat(se -> verifySelectionEvent((SelectionEvent) se, "test4")));
    // test node view state event: executed
    wfm.executeAllAndWaitUntilDone();
    awaitUntilAsserted(() -> verify(eventConsumer).accept(eq("NodeViewStateEvent"), argThat(se -> verifyNodeViewStateEvent((NodeViewStateEvent) se, "executed", "the initial data"))));
    // make sure that selection events are issued again
    fireHiLiteEvent(hlh, "test5");
    verify(eventConsumer).accept(eq("SelectionEvent"), argThat(se -> verifySelectionEvent((SelectionEvent) se, "test5")));
    WorkflowManagerUtil.disposeWorkflow(wfm);
}
Also used : NodeViewNodeFactory(org.knime.testing.node.view.NodeViewNodeFactory) KeyEvent(org.knime.core.node.property.hilite.KeyEvent) NodeViewStateEvent(org.knime.gateway.impl.service.events.NodeViewStateEvent) Awaitility.await(org.awaitility.Awaitility.await) 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) IOException(java.io.IOException) Test(org.junit.Test) Mockito.verify(org.mockito.Mockito.verify) Objects(java.util.Objects) ThrowingRunnable(org.awaitility.core.ThrowingRunnable) Mockito(org.mockito.Mockito) Mockito.never(org.mockito.Mockito.never) List(java.util.List) SelectionEvent(org.knime.gateway.impl.service.events.SelectionEvent) WorkflowManagerUtil(org.knime.testing.util.WorkflowManagerUtil) HiLiteHandler(org.knime.core.node.property.hilite.HiLiteHandler) BiConsumer(java.util.function.BiConsumer) FIVE_SECONDS(org.awaitility.Duration.FIVE_SECONDS) ONE_HUNDRED_MILLISECONDS(org.awaitility.Duration.ONE_HUNDRED_MILLISECONDS) NodeViewNodeFactory(org.knime.testing.node.view.NodeViewNodeFactory) NodeViewStateEvent(org.knime.gateway.impl.service.events.NodeViewStateEvent) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)1 List (java.util.List)1 Objects (java.util.Objects)1 BiConsumer (java.util.function.BiConsumer)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 ThrowingRunnable (org.awaitility.core.ThrowingRunnable)1 Test (org.junit.Test)1 RowKey (org.knime.core.data.RowKey)1 HiLiteHandler (org.knime.core.node.property.hilite.HiLiteHandler)1 KeyEvent (org.knime.core.node.property.hilite.KeyEvent)1 NodeViewStateEvent (org.knime.gateway.impl.service.events.NodeViewStateEvent)1 SelectionEvent (org.knime.gateway.impl.service.events.SelectionEvent)1 SelectionEventMode (org.knime.gateway.impl.service.events.SelectionEventSource.SelectionEventMode)1 NodeViewNodeFactory (org.knime.testing.node.view.NodeViewNodeFactory)1 WorkflowManagerUtil (org.knime.testing.util.WorkflowManagerUtil)1 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)1 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)1 Mockito (org.mockito.Mockito)1