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