Search in sources :

Example 1 with BUNDLE_ID

use of org.knime.core.webui.page.PageTest.BUNDLE_ID in project knime-core by knime.

the class NodeViewManagerTest method testGetNodeViewPageUrl.

/**
 * Tests {@link NodeViewManager#getNodeViewPageUrl(NativeNodeContainer)}.
 *
 * @throws URISyntaxException
 * @throws IOException
 */
@Test
public void testGetNodeViewPageUrl() throws URISyntaxException, IOException {
    var staticPage = Page.builder(BUNDLE_ID, "files", "page.html").addResourceFile("resource.html").build();
    var dynamicPage = Page.builder(() -> "page content", "page.html").addResourceFromString(() -> "resource content", "resource.html").build();
    NativeNodeContainer nnc = createNodeWithNodeView(m_wfm, m -> createNodeView(staticPage));
    NativeNodeContainer nnc2 = createNodeWithNodeView(m_wfm, m -> createNodeView(staticPage));
    NativeNodeContainer nnc3 = createNodeWithNodeView(m_wfm, m -> createNodeView(dynamicPage));
    var nodeViewManager = NodeViewManager.getInstance();
    String url = nodeViewManager.getNodeViewPageUrl(nnc).orElse("");
    String url2 = nodeViewManager.getNodeViewPageUrl(nnc2).orElse(null);
    String url3 = nodeViewManager.getNodeViewPageUrl(nnc3).orElse(null);
    String url4 = nodeViewManager.getNodeViewPageUrl(nnc3).orElse(null);
    assertThat("file url of static pages not expected to change", url, is(url2));
    assertThat("file url of dynamic pages expected to change between node instances", url, is(not(url3)));
    assertThat("file url of dynamic pages not expected for same node instance (without node state change)", url3, is(url4));
    assertThat("resource files are expected to be written, too", new File(new URI(url.replace("page.html", "resource.html"))).exists(), is(true));
    assertThat(new File(new URI(url)).exists(), is(true));
    assertThat(new File(new URI(url3)).exists(), is(true));
    String pageContent = Files.readLines(new File(new URI(url3)), StandardCharsets.UTF_8).get(0);
    assertThat(pageContent, is("page content"));
    // impose node state changes
    m_wfm.executeAllAndWaitUntilDone();
    var dynamicPage2 = Page.builder(() -> "new page content", "page.html").addResourceFromString(() -> "resource content", "resource.html").build();
    nnc = createNodeWithNodeView(m_wfm, m -> createNodeView(dynamicPage2));
    String url5 = nodeViewManager.getNodeViewPageUrl(nnc).orElse(null);
    pageContent = Files.readLines(new File(new URI(url5)), StandardCharsets.UTF_8).get(0);
    assertThat(pageContent, is("new page content"));
    runOnExecutor(() -> assertThat(nodeViewManager.getNodeViewPageUrl(nnc2).isEmpty(), is(true)));
}
Also used : NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) VirtualSubNodeInputNodeFactory(org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeInputNodeFactory) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) Assert.assertThrows(org.junit.Assert.assertThrows) URISyntaxException(java.net.URISyntaxException) Matchers.not(org.hamcrest.Matchers.not) WorkflowManagerUtil.createAndAddNode(org.knime.testing.util.WorkflowManagerUtil.createAndAddNode) NodeSettings(org.knime.core.node.NodeSettings) ApplyDataService(org.knime.core.webui.data.ApplyDataService) Page(org.knime.core.webui.page.Page) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) InitialDataService(org.knime.core.webui.data.InitialDataService) BUNDLE_ID(org.knime.core.webui.page.PageTest.BUNDLE_ID) NodeContainer(org.knime.core.node.workflow.NodeContainer) Files(com.google.common.io.Files) WorkflowManagerUtil(org.knime.testing.util.WorkflowManagerUtil) After(org.junit.After) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) NodeViewTest.createNodeView(org.knime.core.webui.node.view.NodeViewTest.createNodeView) URI(java.net.URI) TextReExecuteDataService(org.knime.core.webui.data.text.TextReExecuteDataService) Before(org.junit.Before) PortType(org.knime.core.node.port.PortType) NodeViewNodeFactory(org.knime.testing.node.view.NodeViewNodeFactory) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) TimeUnit(java.util.concurrent.TimeUnit) DataService(org.knime.core.webui.data.DataService) NodeViewNodeModel(org.knime.testing.node.view.NodeViewNodeModel) Optional(java.util.Optional) TextInitialDataService(org.knime.core.webui.data.text.TextInitialDataService) Matchers.is(org.hamcrest.Matchers.is) Matchers.containsString(org.hamcrest.Matchers.containsString) Awaitility(org.awaitility.Awaitility) TextDataService(org.knime.core.webui.data.text.TextDataService) Matchers.containsString(org.hamcrest.Matchers.containsString) File(java.io.File) URI(java.net.URI) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) Test(org.junit.Test)

Aggregations

Files (com.google.common.io.Files)1 File (java.io.File)1 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Optional (java.util.Optional)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Function (java.util.function.Function)1 Awaitility (org.awaitility.Awaitility)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Matchers.is (org.hamcrest.Matchers.is)1 Matchers.not (org.hamcrest.Matchers.not)1 After (org.junit.After)1 Assert.assertThrows (org.junit.Assert.assertThrows)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Before (org.junit.Before)1 Test (org.junit.Test)1