use of org.knime.gateway.impl.service.events.SelectionEvent in project knime-core by knime.
the class NodeViewEntTest method testNodeViewEntWithSelectionEventSource.
/**
* Tests the {@link SelectionEventSource} in conjunction with {@link NodeViewEnt}.
*
* @throws IOException
*/
@Test
public void testNodeViewEntWithSelectionEventSource() throws IOException {
var wfm = WorkflowManagerUtil.createEmptyWorkflow();
Function<NodeViewNodeModel, NodeView> nodeViewCreator = m -> NodeViewTest.createNodeView(Page.builder(() -> "blub", "index.html").build());
NativeNodeContainer nnc = WorkflowManagerUtil.createAndAddNode(wfm, new NodeViewNodeFactory(nodeViewCreator));
wfm.executeAllAndWaitUntilDone();
var hiLiteHandler = nnc.getNodeModel().getInHiLiteHandler(0);
hiLiteHandler.fireHiLiteEvent(new RowKey("k1"), new RowKey("k2"));
@SuppressWarnings("unchecked") final BiConsumer<String, SelectionEvent> consumerMock = mock(BiConsumer.class);
var selectionEventSource = SelectionEventSourceTest.createSelectionEventSource(consumerMock);
var initialSelection = selectionEventSource.addEventListenerAndGetInitialEventFor(nnc).map(SelectionEvent::getKeys).orElse(Collections.emptyList());
var nodeViewEnt = new NodeViewEnt(nnc, () -> initialSelection);
assertThat(nodeViewEnt.getInitialSelection(), is(List.of("k1", "k2")));
hiLiteHandler.fireHiLiteEvent(new RowKey("k3"));
await().pollDelay(ONE_HUNDRED_MILLISECONDS).timeout(FIVE_SECONDS).untilAsserted(() -> verify(consumerMock, times(1)).accept(eq("SelectionEvent"), argThat(se -> se.getKeys().equals(List.of("k3")) && se.getMode() == SelectionEventMode.ADD)));
WorkflowManagerUtil.disposeWorkflow(wfm);
}
use of org.knime.gateway.impl.service.events.SelectionEvent 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