use of org.knime.core.webui.data.text.TextInitialDataService in project knime-core by knime.
the class NodeViewEntTest method testNodeViewEnt.
/**
* Tests {@link NodeViewEnt#NodeViewEnt(NativeNodeContainer)}.
*
* @throws IOException
*/
@Test
public void testNodeViewEnt() throws IOException {
var wfm = WorkflowManagerUtil.createEmptyWorkflow();
NativeNodeContainer nncWithoutNodeView = WorkflowManagerUtil.createAndAddNode(wfm, new VirtualSubNodeInputNodeFactory(null, new PortType[0]));
Assert.assertThrows(IllegalArgumentException.class, () -> new NodeViewEnt(nncWithoutNodeView));
Function<NodeViewNodeModel, NodeView> nodeViewCreator = m -> {
Page p = Page.builder(() -> "blub", "index.html").build();
return NodeViewTest.createNodeView(p, new TextInitialDataService() {
@Override
public String getInitialData() {
return "dummy initial data";
}
}, null, null);
};
NativeNodeContainer nnc = WorkflowManagerUtil.createAndAddNode(wfm, new NodeViewNodeFactory(nodeViewCreator));
wfm.executeAllAndWaitUntilDone();
nnc.setNodeMessage(NodeMessage.newWarning("node message"));
nnc.getNodeAnnotation().getData().setText("node annotation");
var ent = new NodeViewEnt(nnc, null);
assertThat(ent.getProjectId(), startsWith("workflow"));
assertThat(ent.getWorkflowId(), is("root"));
assertThat(ent.getNodeId(), is("root:2"));
assertThat(ent.getInitialData(), is("dummy initial data"));
assertThat(ent.getInitialSelection(), is(nullValue()));
var resourceInfo = ent.getResourceInfo();
assertThat(resourceInfo.getUrl(), endsWith("index.html"));
assertThat(resourceInfo.getPath(), is(nullValue()));
assertThat(resourceInfo.getType(), is(Resource.Type.HTML.toString()));
assertThat(resourceInfo.getId(), is(PageUtil.getPageId(nnc, false, false)));
var nodeInfo = ent.getNodeInfo();
assertThat(nodeInfo.getNodeName(), is("NodeView"));
assertThat(nodeInfo.getNodeAnnotation(), is("node annotation"));
assertThat(nodeInfo.getNodeState(), is("executed"));
assertThat(nodeInfo.getNodeWarnMessage(), is("node message"));
assertThat(nodeInfo.getNodeErrorMessage(), is(nullValue()));
// a node view as a 'component' without initial data
nodeViewCreator = m -> {
Page p = Page.builder(PageTest.BUNDLE_ID, "files", "component.umd.min.js").build();
return NodeViewTest.createNodeView(p);
};
nnc = WorkflowManagerUtil.createAndAddNode(wfm, new NodeViewNodeFactory(nodeViewCreator));
wfm.executeAllAndWaitUntilDone();
ent = new NodeViewEnt(nnc, null);
resourceInfo = ent.getResourceInfo();
assertThat(ent.getInitialData(), is(nullValue()));
assertThat(resourceInfo.getType(), is(Resource.Type.VUE_COMPONENT_LIB.toString()));
assertThat(resourceInfo.getUrl(), endsWith("component.umd.min.js"));
assertThat(resourceInfo.getPath(), is(nullValue()));
// test to create a node view entity while running headless (e.g. on the executor)
NativeNodeContainer nnc2 = nnc;
runOnExecutor(() -> {
var ent2 = new NodeViewEnt(nnc2, null);
assertThat(ent2.getResourceInfo().getPath(), endsWith("component.umd.min.js"));
assertThat(ent2.getResourceInfo().getUrl(), is(nullValue()));
});
WorkflowManagerUtil.disposeWorkflow(wfm);
}
use of org.knime.core.webui.data.text.TextInitialDataService in project knime-core by knime.
the class NodeViewManagerTest method testCallDataServices.
/**
* Tests {@link NodeViewManager#callTextInitialDataService(NodeContainer)},
* {@link NodeViewManager#callTextDataService(NodeContainer, String)} and
* {@link NodeViewManager#callTextApplyDataService(NodeContainer, String)}
*/
@Test
public void testCallDataServices() {
var page = Page.builder(() -> "test page content", "index.html").build();
var nodeView = createNodeView(page, new TextInitialDataService() {
@Override
public String getInitialData() {
return "init service";
}
}, new TextDataService() {
@Override
public String handleRequest(final String request) {
return "general data service";
}
}, new TextReExecuteDataService() {
@Override
public Optional<String> validateData(final String data) throws IOException {
throw new UnsupportedOperationException("should not be called in this test");
}
@Override
public void applyData(final String data) throws IOException {
throw new UnsupportedOperationException("should not be called in this test");
}
@Override
public void reExecute(final String data) throws IOException {
throw new IOException("re-execute data service");
}
});
NativeNodeContainer nc = NodeViewManagerTest.createNodeWithNodeView(m_wfm, m -> nodeView);
var nodeViewManager = NodeViewManager.getInstance();
assertThat(nodeViewManager.callTextInitialDataService(nc), is("init service"));
assertThat(nodeViewManager.callTextDataService(nc, ""), is("general data service"));
String message = assertThrows(IOException.class, () -> nodeViewManager.callTextApplyDataService(nc, "ERROR,test")).getMessage();
assertThat(message, is("re-execute data service"));
}
Aggregations