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);
}
Aggregations