public static String getUsageTextForGraph(String path, CommandLineContext commandLineContext) { final Graph graph; try { graph = commandLineContext.readGraph(path, new HashMap<String, String>()); } catch (GraphException e) { return e.getMessage(); } catch (IOException e) { return e.getMessage(); } final StringBuilder usageText = new StringBuilder(1024); final Header header = graph.getHeader(); if (header != null) { usageText.append("Usage:\n"); usageText.append(MessageFormat.format(" {0} {1} [options] ", CommandLineTool.TOOL_NAME, path)); ArrayList<DocElement> sourceDocElementList = createSourceDocElementList(header.getSources()); ArrayList<DocElement> paramDocElementList = createParamDocElementList(header.getParameters()); if (!sourceDocElementList.isEmpty()) { usageText.append("\nSource Options:\n"); appendDocElementList(usageText, sourceDocElementList); } if (!paramDocElementList.isEmpty()) { usageText.append("\nParameter Options:\n"); appendDocElementList(usageText, paramDocElementList); } } return usageText.toString(); }
public void testOptSourcesOp() { final String opName = "OptSourcesOp"; Graph graph; Node outputNode; graph = createTestGraph(opName); try { new GraphContext(graph); } catch (GraphException ge) { fail("GraphException not expected, sources not checked. Error: " + ge.getMessage()); } graph = createTestGraph(opName); outputNode = graph.getNode("output"); outputNode.addSource(new NodeSource("dummy1", "input1")); outputNode.addSource(new NodeSource("dummy2", "input2")); outputNode.addSource(new NodeSource("dummy3", "input3")); try { new GraphContext(graph); } catch (GraphException ge) { fail("GraphException not expected, sources not checked. Error: " + ge.getMessage()); } }
public void testAnySourcesOp() { final String opName = "AnySourcesOp"; Graph graph; Node outputNode; graph = createTestGraph(opName); try { new GraphContext(graph); fail("GraphException expected, at least one source expected"); } catch (GraphException ge) { } graph = createTestGraph(opName); outputNode = graph.getNode("output"); outputNode.addSource(new NodeSource("dummy1", "input1")); outputNode.addSource(new NodeSource("dummy2", "input2")); outputNode.addSource(new NodeSource("dummy3", "input3")); try { new GraphContext(graph); } catch (GraphException ge) { fail("GraphException not expected, any number of sources allowed. Error: " + ge.getMessage()); } }
graphContext = new GraphContext(graph); } catch (GraphException e) { fail(e.getMessage());
graphContext = new GraphContext(graph); } catch (GraphException e) { fail(e.getMessage());
new GraphContext(graph); } catch (GraphException ge) { fail("GraphException not expected, exactly 2 sources given. Error: " + ge.getMessage());
graphContext = new GraphContext(graph); } catch (GraphException e) { fail(e.getMessage());