Search in sources :

Example 1 with ONE_HUNDRED_MILLISECONDS

use of org.awaitility.Duration.ONE_HUNDRED_MILLISECONDS 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);
}
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) NodeViewNodeFactory(org.knime.testing.node.view.NodeViewNodeFactory) RowKey(org.knime.core.data.RowKey) NodeViewNodeModel(org.knime.testing.node.view.NodeViewNodeModel) NodeView(org.knime.core.webui.node.view.NodeView) SelectionEvent(org.knime.gateway.impl.service.events.SelectionEvent) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) 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)

Aggregations

IOException (java.io.IOException)1 Collections (java.util.Collections)1 List (java.util.List)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.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 Test (org.junit.Test)1 RowKey (org.knime.core.data.RowKey)1 PortType (org.knime.core.node.port.PortType)1 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)1 NodeMessage (org.knime.core.node.workflow.NodeMessage)1 VirtualSubNodeInputNodeFactory (org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeInputNodeFactory)1