use of org.knime.gateway.impl.service.events.SelectionEventSource 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);
}
Aggregations