diff --git a/graphwalker-cli/src/main/java/org/graphwalker/cli/CLI.java b/graphwalker-cli/src/main/java/org/graphwalker/cli/CLI.java index 82ea9140..e287db84 100644 --- a/graphwalker-cli/src/main/java/org/graphwalker/cli/CLI.java +++ b/graphwalker-cli/src/main/java/org/graphwalker/cli/CLI.java @@ -101,19 +101,20 @@ enum Command { public static void main(String[] args) { CLI cli = new CLI(); try { - cli.run(args); + int status = cli.run(args); + System.exit(status); } catch (Exception e) { // We should have caught all exceptions up until here, but there // might have been problems with the command parser for instance... System.err.println(e + System.lineSeparator()); - logger.error("An error occurred when running command: " + StringUtils.join(args, " "), e); + logger.error("An unexpected error occurred when running command: " + StringUtils.join(args, " "), e); } } /** * Parses the command line. */ - private void run(String[] args) { + public int run(String[] args) { Options options = new Options(); JCommander jc = new JCommander(options); jc.setProgramName("graphwalker"); @@ -145,12 +146,12 @@ private void run(String[] args) { if (options.help) { jc.usage(); - return; + return 0; } else if (options.version) { System.out.println(printVersionInformation()); - return; + return 0; } else if (jc.getParsedCommand() == null) { - throw new MissingCommandException("Missing a command. Add '--help'"); + throw new MissingCommandException("Missing a command. Use the '--help' option to list all available commands."); } // Parse for commands @@ -174,19 +175,24 @@ private void run(String[] args) { runCommandSource(); } else if (jc.getParsedCommand().equalsIgnoreCase("check")) { command = Command.CHECK; - runCommandCheck(); + return runCommandCheck(); } } catch (UnsupportedFileFormat | MissingCommandException e) { System.err.println(e.getMessage() + System.lineSeparator()); + return 1; } catch (ParameterException e) { - System.err.println("An error occurred when running command: " + StringUtils.join(args, " ")); + System.err.println("An error occurred when running command: '" + StringUtils.join(args, " ") + "'."); System.err.println(e.getMessage() + System.lineSeparator()); jc.usage(); + return 1; } catch (Exception e) { - System.err.println("An error occurred when running command: " + StringUtils.join(args, " ")); - System.err.println(e.getMessage() + System.lineSeparator()); logger.error("An error occurred when running command: " + StringUtils.join(args, " "), e); + System.err.println("An error occurred when running command: '" + StringUtils.join(args, " ") + "'."); + System.err.println(e.getMessage() + System.lineSeparator()); + return 2; } + + return 0; } private void setLogLevel(Options options) { @@ -210,7 +216,7 @@ private void setLogLevel(Options options) { } } - private void runCommandCheck() throws Exception, UnsupportedFileFormat { + private int runCommandCheck() throws Exception, UnsupportedFileFormat { List contexts = getContextsWithPathGenerators(check.model.iterator()); if (check.blocked) { org.graphwalker.io.common.Util.filterBlockedElements(contexts); @@ -221,8 +227,10 @@ private void runCommandCheck() throws Exception, UnsupportedFileFormat { for (String issue : issues) { System.out.println(issue); } + return 1; } else { System.out.println("No issues found with the model(s)."); + return 0; } } @@ -252,7 +260,7 @@ private void runCommandMethods() throws Exception, UnsupportedFileFormat { for (Context context : contexts) { for (Vertex.RuntimeVertex vertex : context.getModel().getVertices()) { - if (null != vertex.getName()) { + if (vertex.getName() != null) { names.add(vertex.getName()); } } @@ -296,6 +304,7 @@ private void runCommandOnline() throws Exception, UnsupportedFileFormat { + online.port + "/graphwalker/getNext"); System.out.println("Press Control+C to end..."); + try { server.start(); Thread.currentThread().join(); @@ -308,7 +317,7 @@ private void runCommandOnline() throws Exception, UnsupportedFileFormat { server.stop(); } } else { - throw new ParameterException("--service expected either WEBSOCKET or RESTFUL"); + throw new ParameterException("--service expected either WEBSOCKET or RESTFUL."); } } @@ -320,8 +329,9 @@ private void runCommandConvert() throws Exception, UnsupportedFileFormat { try { contexts = inputFactory.create(Paths.get(inputFileName)); } catch (DslException e) { - System.err.println("When parsing model: '" + inputFileName + "' " + e.getMessage() + System.lineSeparator()); - throw new Exception("Model syntax error"); + throw new Exception("The following syntax error occurred when parsing: '" + inputFileName + "'." + + System.lineSeparator() + + "Syntax Error: " + e.getMessage() + System.lineSeparator()); } if (convert.blocked) { @@ -343,11 +353,12 @@ private void runCommandSource() throws Exception, UnsupportedFileFormat { contexts = inputFactory.create(Paths.get(modelFileName)); if (isNullOrEmpty(contexts)) { logger.error("No valid models found in: " + modelFileName); - throw new RuntimeException("No valid models found in: " + modelFileName); + throw new RuntimeException("No valid models found in: '" + modelFileName + "'."); } } catch (DslException e) { - System.err.println("When parsing model: '" + modelFileName + "' " + e.getMessage() + System.lineSeparator()); - throw new Exception("Model syntax error"); + throw new Exception("The following syntax error occurred when parsing: '" + modelFileName + "'." + + System.lineSeparator() + + "Syntax Error: " + e.getMessage()); } if (source.blocked) { @@ -376,7 +387,7 @@ private void runCommandSource() throws Exception, UnsupportedFileFormat { } } catch (IOException e) { logger.error(e.getMessage()); - throw new RuntimeException("Could not read the file: " + templateFileName); + throw new RuntimeException("Could not read the file: '" + templateFileName + "'."); } String templateStr = templateStrBuilder.toString(); @@ -446,10 +457,12 @@ public List getContextsWithPathGenerators(Iterator itr) throws Exceptio try { contexts = factory.create(Paths.get(modelFileName)); } catch (DslException e) { - System.err.println("When parsing model: '" + modelFileName + "' " + e.getMessage() + System.lineSeparator()); - throw new Exception("Model syntax error"); + throw new Exception("The following syntax error occurred when parsing: '" + modelFileName + "'." + + System.lineSeparator() + + "Syntax Error: " + e.getMessage()); } - // TODO fix all occurences of get(0) is not safe + + // TODO fix all occurrences of get(0) is not safe contexts.get(0).setPathGenerator(GeneratorFactory.parse((String) itr.next())); if (triggerOnce && @@ -464,9 +477,9 @@ public List getContextsWithPathGenerators(Iterator itr) throws Exceptio } if (elements == null) { - throw new ParameterException("--start-element Did not find matching element in the model: " + modelFileName); + throw new ParameterException("--start-element Did not find matching element in the model: '" + modelFileName + "'."); } else if (elements.size() > 1) { - throw new ParameterException("--start-element There are more than one matching element in the model: " + modelFileName); + throw new ParameterException("--start-element There are more than one matching element in the model: '" + modelFileName + "'."); } contexts.get(0).setNextElement(elements.get(0)); } @@ -501,8 +514,9 @@ private List getContexts(Iterator itr) throws Exception, UnsupportedFil try { contexts = factory.create(Paths.get(modelFileName)); } catch (DslException e) { - System.err.println("When parsing model: '" + modelFileName + "' " + e.getMessage() + System.lineSeparator()); - throw new Exception("Model syntax error"); + throw new Exception("The following syntax error occurred when parsing: '" + modelFileName + "'." + + System.lineSeparator() + + "Syntax Error: " + e.getMessage()); } executionContexts.addAll(contexts); } diff --git a/graphwalker-cli/src/test/java/org/graphwalker/cli/CLITestRoot.java b/graphwalker-cli/src/test/java/org/graphwalker/cli/CLITestRoot.java index 8a9d6dee..3761cdae 100644 --- a/graphwalker-cli/src/test/java/org/graphwalker/cli/CLITestRoot.java +++ b/graphwalker-cli/src/test/java/org/graphwalker/cli/CLITestRoot.java @@ -12,10 +12,10 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -49,17 +49,23 @@ protected Result runCommand(String args[]) { System.setOut(outStream); System.setErr(errStream); + int status = -1; + try { - CLI.main(args); + CLI cli = new CLI(); + status = cli.run(args); } finally { System.setOut(oldOutStream); System.setErr(oldErrStream); String outMsg = stdOutput.toString(); String errMsg = errOutput.toString(); + logger.info("stdout: " + outMsg); logger.info("stderr: " + errMsg); - return new Result(outMsg, errMsg); + logger.info("status: " + status); + + return new Result(outMsg, errMsg, status); } } @@ -82,10 +88,12 @@ public class Result { private final String output; private final String error; + private final int status; - public Result(String output, String error) { + public Result(String output, String error, int status) { this.output = output; this.error = error; + this.status = status; } public String getOutput() { @@ -95,5 +103,9 @@ public String getOutput() { public String getError() { return error; } + + public int getStatus() { + return status; + } } } diff --git a/graphwalker-cli/src/test/java/org/graphwalker/cli/CheckTest.java b/graphwalker-cli/src/test/java/org/graphwalker/cli/CheckTest.java index 91ddf664..fba60dd4 100644 --- a/graphwalker-cli/src/test/java/org/graphwalker/cli/CheckTest.java +++ b/graphwalker-cli/src/test/java/org/graphwalker/cli/CheckTest.java @@ -10,10 +10,10 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -41,6 +41,7 @@ public class CheckTest extends CLITestRoot { public void check() throws IOException { String args[] = {"check", "-m", "graphml/online/ShoppingCart.graphml", "random(edge_coverage(100))"}; Result result = runCommand(args); + assertThat(result.getStatus(), is(0)); assertThat(result.getError(), is("")); assertThat(result.getOutput(), containsString("No issues found with the model(s).")); } @@ -49,6 +50,7 @@ public void check() throws IOException { public void checkWithBlocked() throws IOException { String args[] = {"check", "-m", "graphml/online/ShoppingCart.graphml", "random(edge_coverage(100))"}; Result result = runCommand(args); + assertThat(result.getStatus(), is(0)); assertThat(result.getError(), is("")); assertThat(result.getOutput(), containsString("No issues found with the model(s).")); } diff --git a/graphwalker-cli/src/test/java/org/graphwalker/cli/ConvertFilesTest.java b/graphwalker-cli/src/test/java/org/graphwalker/cli/ConvertFilesTest.java index e32f852a..9f54eece 100644 --- a/graphwalker-cli/src/test/java/org/graphwalker/cli/ConvertFilesTest.java +++ b/graphwalker-cli/src/test/java/org/graphwalker/cli/ConvertFilesTest.java @@ -10,10 +10,10 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -46,8 +46,9 @@ public class ConvertFilesTest extends CLITestRoot { public void convertGraphmlToJava() throws IOException { String args[] = {"convert", "--input", "graphml/UC01_GW2.graphml", "--format", "java"}; Result result = runCommand(args); + assertThat(result.getStatus(), is(0)); assertThat(result.getError(), is("")); - //TODO:Fix test -// Assert.assertTrue(tempFile.length() > 0); + // TODO: Fix test + // assertTrue(tempFile.length() > 0); } } diff --git a/graphwalker-cli/src/test/java/org/graphwalker/cli/CorrectModelsTest.java b/graphwalker-cli/src/test/java/org/graphwalker/cli/CorrectModelsTest.java index 3071ffc5..a556bd26 100644 --- a/graphwalker-cli/src/test/java/org/graphwalker/cli/CorrectModelsTest.java +++ b/graphwalker-cli/src/test/java/org/graphwalker/cli/CorrectModelsTest.java @@ -10,10 +10,10 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -67,9 +67,10 @@ public class CorrectModelsTest extends CLITestRoot { public void simplestModel() { String args[] = {"offline", "-m", "graphml/CorrectModels/simplestModel.graphml", "random(vertex_coverage(100))"}; Result result = runCommand(args); + assertThat(result.getStatus(), is(0)); assertThat(result.getError(), is("")); assertThat(result.getOutput(), is("{\"currentElementName\":\"e1\"}" + System.lineSeparator() + - "{\"currentElementName\":\"v1\"}" + System.lineSeparator())); + "{\"currentElementName\":\"v1\"}" + System.lineSeparator())); } /** @@ -79,17 +80,18 @@ public void simplestModel() { public void shortestAllPathsVertexCoverage() { String args[] = {"offline", "-m", "graphml/CorrectModels/shortestAllPathsVertexCoverage.graphml", "shortest_all_paths(vertex_coverage(100))"}; Result result = runCommand(args); + assertThat(result.getStatus(), is(0)); assertThat(result.getError(), is("")); assertThat(result.getOutput(), is("{\"currentElementName\":\"e1\"}" + System.lineSeparator() + - "{\"currentElementName\":\"v1\"}" + System.lineSeparator() + - "{\"currentElementName\":\"e2\"}" + System.lineSeparator() + - "{\"currentElementName\":\"v2\"}" + System.lineSeparator() + - "{\"currentElementName\":\"e4\"}" + System.lineSeparator() + - "{\"currentElementName\":\"v4\"}" + System.lineSeparator() + - "{\"currentElementName\":\"e6\"}" + System.lineSeparator() + - "{\"currentElementName\":\"v1\"}" + System.lineSeparator() + - "{\"currentElementName\":\"e3\"}" + System.lineSeparator() + - "{\"currentElementName\":\"v3\"}" + System.lineSeparator())); + "{\"currentElementName\":\"v1\"}" + System.lineSeparator() + + "{\"currentElementName\":\"e2\"}" + System.lineSeparator() + + "{\"currentElementName\":\"v2\"}" + System.lineSeparator() + + "{\"currentElementName\":\"e4\"}" + System.lineSeparator() + + "{\"currentElementName\":\"v4\"}" + System.lineSeparator() + + "{\"currentElementName\":\"e6\"}" + System.lineSeparator() + + "{\"currentElementName\":\"v1\"}" + System.lineSeparator() + + "{\"currentElementName\":\"e3\"}" + System.lineSeparator() + + "{\"currentElementName\":\"v3\"}" + System.lineSeparator())); } /** @@ -99,6 +101,7 @@ public void shortestAllPathsVertexCoverage() { public void loginNoErrors() { String args[] = {"offline", "-o", "-m", "graphml/Login.graphml", "random(edge_coverage(100))"}; Result result = runCommand(args); + assertThat(result.getStatus(), is(0)); assertThat(result.getError(), is("")); } @@ -109,11 +112,12 @@ public void loginNoErrors() { public void noStartVertex() { String args[] = {"offline", "-e", "v1", "-m", "graphml/CorrectModels/modelWithNoStartVertex.graphml", "a_star(reached_edge(e4))"}; Result result = runCommand(args); + assertThat(result.getStatus(), is(0)); assertThat(result.getError(), is("")); assertThat(result.getOutput(), is("{\"currentElementName\":\"v1\"}" + System.lineSeparator() + - "{\"currentElementName\":\"e2\"}" + System.lineSeparator() + - "{\"currentElementName\":\"v2\"}" + System.lineSeparator() + - "{\"currentElementName\":\"e4\"}" + System.lineSeparator())); + "{\"currentElementName\":\"e2\"}" + System.lineSeparator() + + "{\"currentElementName\":\"v2\"}" + System.lineSeparator() + + "{\"currentElementName\":\"e4\"}" + System.lineSeparator())); } /** @@ -123,11 +127,12 @@ public void noStartVertex() { public void dontUseBlocked() { String args[] = {"offline", "-b", "false", "-m", "graphml/CorrectModels/blockedVertex.graphml", "random(edge_coverage(100))"}; Result result = runCommand(args); + assertThat(result.getStatus(), is(0)); assertThat(result.getError(), is("")); assertThat(result.getOutput(), is("{\"currentElementName\":\"e1\"}" + System.lineSeparator() + - "{\"currentElementName\":\"v1\"}" + System.lineSeparator() + - "{\"currentElementName\":\"e2\"}" + System.lineSeparator() + - "{\"currentElementName\":\"v2\"}" + System.lineSeparator())); + "{\"currentElementName\":\"v1\"}" + System.lineSeparator() + + "{\"currentElementName\":\"e2\"}" + System.lineSeparator() + + "{\"currentElementName\":\"v2\"}" + System.lineSeparator())); } /** @@ -137,9 +142,10 @@ public void dontUseBlocked() { public void useBlocked() { String args[] = {"offline", "-m", "graphml/CorrectModels/blockedVertex.graphml", "random(edge_coverage(100))"}; Result result = runCommand(args); + assertThat(result.getStatus(), is(0)); assertThat(result.getError(), is("")); assertThat(result.getOutput(), is("{\"currentElementName\":\"e1\"}" + System.lineSeparator() + - "{\"currentElementName\":\"v1\"}" + System.lineSeparator())); + "{\"currentElementName\":\"v1\"}" + System.lineSeparator())); } /** @@ -149,23 +155,24 @@ public void useBlocked() { public void dontUseBlockedJson() { String args[] = {"offline", "-b", "false", "-g", "json/graphWithBlockedElements.json"}; Result result = runCommand(args); + assertThat(result.getStatus(), is(0)); assertThat(result.getError(), is("")); assertThat(Arrays.asList(result.getOutput().split(System.lineSeparator())), - hasItems("{\"currentElementName\":\"e1\"}", - "{\"currentElementName\":\"e2\"}", - "{\"currentElementName\":\"e3\"}", - "{\"currentElementName\":\"e4\"}", - "{\"currentElementName\":\"e5\"}", - "{\"currentElementName\":\"e6\"}", - "{\"currentElementName\":\"e7\"}", - "{\"currentElementName\":\"e8\"}", - "{\"currentElementName\":\"e9\"}", - "{\"currentElementName\":\"e10\"}", - "{\"currentElementName\":\"v1\"}", - "{\"currentElementName\":\"v2\"}", - "{\"currentElementName\":\"v3\"}", - "{\"currentElementName\":\"v4\"}", - "{\"currentElementName\":\"v5\"}")); + hasItems("{\"currentElementName\":\"e1\"}", + "{\"currentElementName\":\"e2\"}", + "{\"currentElementName\":\"e3\"}", + "{\"currentElementName\":\"e4\"}", + "{\"currentElementName\":\"e5\"}", + "{\"currentElementName\":\"e6\"}", + "{\"currentElementName\":\"e7\"}", + "{\"currentElementName\":\"e8\"}", + "{\"currentElementName\":\"e9\"}", + "{\"currentElementName\":\"e10\"}", + "{\"currentElementName\":\"v1\"}", + "{\"currentElementName\":\"v2\"}", + "{\"currentElementName\":\"v3\"}", + "{\"currentElementName\":\"v4\"}", + "{\"currentElementName\":\"v5\"}")); } /** @@ -175,23 +182,24 @@ public void dontUseBlockedJson() { public void useBlockedJson() { String args[] = {"offline", "-g", "json/graphWithBlockedElements.json"}; Result result = runCommand(args); + assertThat(result.getStatus(), is(0)); assertThat(result.getError(), is("")); assertThat(Arrays.asList(result.getOutput().split(System.lineSeparator())), - hasItems("{\"currentElementName\":\"e1\"}", - "{\"currentElementName\":\"e2\"}", - "{\"currentElementName\":\"e3\"}", - "{\"currentElementName\":\"e4\"}", - "{\"currentElementName\":\"e7\"}", - "{\"currentElementName\":\"e8\"}", - "{\"currentElementName\":\"e9\"}", - "{\"currentElementName\":\"v1\"}", - "{\"currentElementName\":\"v2\"}", - "{\"currentElementName\":\"v3\"}", - "{\"currentElementName\":\"v4\"}")); + hasItems("{\"currentElementName\":\"e1\"}", + "{\"currentElementName\":\"e2\"}", + "{\"currentElementName\":\"e3\"}", + "{\"currentElementName\":\"e4\"}", + "{\"currentElementName\":\"e7\"}", + "{\"currentElementName\":\"e8\"}", + "{\"currentElementName\":\"e9\"}", + "{\"currentElementName\":\"v1\"}", + "{\"currentElementName\":\"v2\"}", + "{\"currentElementName\":\"v3\"}", + "{\"currentElementName\":\"v4\"}")); assertThat(Arrays.asList(result.getOutput().split(System.lineSeparator())), - not(hasItems("{\"currentElementName\":\"e5\"}", - "{\"currentElementName\":\"e6\"}", - "{\"currentElementName\":\"v5\"}"))); + not(hasItems("{\"currentElementName\":\"e5\"}", + "{\"currentElementName\":\"e6\"}", + "{\"currentElementName\":\"v5\"}"))); } } diff --git a/graphwalker-cli/src/test/java/org/graphwalker/cli/IOErrorsTest.java b/graphwalker-cli/src/test/java/org/graphwalker/cli/IOErrorsTest.java index 5f6ef434..e30eedaf 100644 --- a/graphwalker-cli/src/test/java/org/graphwalker/cli/IOErrorsTest.java +++ b/graphwalker-cli/src/test/java/org/graphwalker/cli/IOErrorsTest.java @@ -12,10 +12,10 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -41,9 +41,10 @@ public class IOErrorsTest extends CLITestRoot { public void nonExistentFile() { String args[] = {"offline", "-m", "sdsdtkdsjhsl.graphml", "random(edge_coverage(100))"}; Result result = runCommand(args); - assertThat(result.getError(), is("An error occurred when running command: " + - "offline -m sdsdtkdsjhsl.graphml random(edge_coverage(100))" + - System.lineSeparator() + "Could not read the file." + System.lineSeparator() + System.lineSeparator())); + assertThat(result.getStatus(), is(2)); assertThat(result.getOutput(), is("")); + assertThat(result.getError(), is("An error occurred when running command: 'offline -m sdsdtkdsjhsl.graphml random(edge_coverage(100))'." + + System.lineSeparator() + + "Could not read the file." + System.lineSeparator() + System.lineSeparator())); } } diff --git a/graphwalker-cli/src/test/java/org/graphwalker/cli/IncorrectModelsTest.java b/graphwalker-cli/src/test/java/org/graphwalker/cli/IncorrectModelsTest.java index f9a43ea5..9e7a6bba 100644 --- a/graphwalker-cli/src/test/java/org/graphwalker/cli/IncorrectModelsTest.java +++ b/graphwalker-cli/src/test/java/org/graphwalker/cli/IncorrectModelsTest.java @@ -12,10 +12,10 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -42,12 +42,11 @@ public void wrongVertexSyntax() { String args[] = {"offline", "-m", "graphml/IncorrectModels/wrongVertexSyntax.graphml", "random(edge_coverage(100))"}; Result result = runCommand(args); assertThat(result.getError(), - is("When parsing model: 'graphml/IncorrectModels/wrongVertexSyntax.graphml' The string '1' did not conform to GraphWalker syntax rules." - + System.lineSeparator() - + System.lineSeparator() - + "An error occurred when running command: offline -m graphml/IncorrectModels/wrongVertexSyntax.graphml random(edge_coverage(100))" - + System.lineSeparator() - + "Model syntax error" + System.lineSeparator() + System.lineSeparator())); + is("An error occurred when running command: 'offline -m graphml/IncorrectModels/wrongVertexSyntax.graphml random(edge_coverage(100))'." + + System.lineSeparator() + + "The following syntax error occurred when parsing: 'graphml/IncorrectModels/wrongVertexSyntax.graphml'." + + System.lineSeparator() + + "Syntax Error: The string '1' did not conform to GraphWalker syntax rules." + System.lineSeparator() + System.lineSeparator())); assertThat(result.getOutput(), is("")); } @@ -58,9 +57,9 @@ public void wrongVertexSyntax() { public void onlyOneVertex() { String args[] = {"offline", "-m", "graphml/IncorrectModels/singleVertex.graphml", "random(edge_coverage(100))"}; Result result = runCommand(args); - assertThat(result.getError(), is("An error occurred when running command: " + - "offline -m graphml/IncorrectModels/singleVertex.graphml random(edge_coverage(100))" + - System.lineSeparator() + "No start context found" + System.lineSeparator() + System.lineSeparator())); + assertThat(result.getError(), is("An error occurred when running command: 'offline -m graphml/IncorrectModels/singleVertex.graphml random(edge_coverage(100))'." + + System.lineSeparator() + + "No start context found" + System.lineSeparator() + System.lineSeparator())); assertThat(result.getOutput(), is("")); } @@ -71,9 +70,9 @@ public void onlyOneVertex() { public void singleStartVertex() { String args[] = {"offline", "-m", "graphml/IncorrectModels/singleStartVertex.graphml", "random(edge_coverage(100))"}; Result result = runCommand(args); - assertThat(result.getError(), is("An error occurred when running command: " + - "offline -m graphml/IncorrectModels/singleStartVertex.graphml random(edge_coverage(100))" + - System.lineSeparator() + "No start context found" + System.lineSeparator() + System.lineSeparator())); + assertThat(result.getError(), is("An error occurred when running command: 'offline -m graphml/IncorrectModels/singleStartVertex.graphml random(edge_coverage(100))'." + + System.lineSeparator() + + "No start context found" + System.lineSeparator() + System.lineSeparator())); assertThat(result.getOutput(), is("")); } @@ -85,12 +84,11 @@ public void badEdgeName() { String args[] = {"offline", "-m", "graphml/IncorrectModels/badEdgeName.graphml", "random(edge_coverage(100))"}; Result result = runCommand(args); assertThat(result.getError(), - is("When parsing model: 'graphml/IncorrectModels/badEdgeName.graphml' The string '1_badName' did not conform to GraphWalker syntax rules." - + System.lineSeparator() - + System.lineSeparator() - + "An error occurred when running command: offline -m graphml/IncorrectModels/badEdgeName.graphml random(edge_coverage(100))" - + System.lineSeparator() - + "Model syntax error" + System.lineSeparator() + System.lineSeparator())); + is("An error occurred when running command: 'offline -m graphml/IncorrectModels/badEdgeName.graphml random(edge_coverage(100))'." + + System.lineSeparator() + + "The following syntax error occurred when parsing: 'graphml/IncorrectModels/badEdgeName.graphml'." + + System.lineSeparator() + + "Syntax Error: The string '1_badName' did not conform to GraphWalker syntax rules." + System.lineSeparator() + System.lineSeparator())); assertThat(result.getOutput(), is("")); } @@ -102,12 +100,11 @@ public void badVertexName() { String args[] = {"offline", "-m", "graphml/IncorrectModels/badVertexName.graphml", "random(edge_coverage(100))"}; Result result = runCommand(args); assertThat(result.getError(), - is("When parsing model: 'graphml/IncorrectModels/badVertexName.graphml' The string '1_badName' did not conform to GraphWalker syntax rules." - + System.lineSeparator() - + System.lineSeparator() - + "An error occurred when running command: offline -m graphml/IncorrectModels/badVertexName.graphml random(edge_coverage(100))" - + System.lineSeparator() - + "Model syntax error" + System.lineSeparator() + System.lineSeparator())); + is("An error occurred when running command: 'offline -m graphml/IncorrectModels/badVertexName.graphml random(edge_coverage(100))'." + + System.lineSeparator() + + "The following syntax error occurred when parsing: 'graphml/IncorrectModels/badVertexName.graphml'." + + System.lineSeparator() + + "Syntax Error: The string '1_badName' did not conform to GraphWalker syntax rules." + System.lineSeparator() + System.lineSeparator())); assertThat(result.getOutput(), is("")); } } diff --git a/graphwalker-cli/src/test/java/org/graphwalker/cli/MethodsTest.java b/graphwalker-cli/src/test/java/org/graphwalker/cli/MethodsTest.java index 9d24f509..6dbbc8f7 100644 --- a/graphwalker-cli/src/test/java/org/graphwalker/cli/MethodsTest.java +++ b/graphwalker-cli/src/test/java/org/graphwalker/cli/MethodsTest.java @@ -10,10 +10,10 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -44,39 +44,40 @@ public void methodsDontUseBlockedFeature() throws IOException { Result result = runCommand(args); assertThat(result.getError(), is("")); assertThat(Arrays.asList(result.getOutput().split("\\s+")), - containsInAnyOrder("e1", - "e2", - "e3", - "e4", - "e5", - "e6", - "e7", - "e8", - "e9", - "e10", - "v1", - "v2", - "v3", - "v4", - "v5")); + containsInAnyOrder("e1", + "e2", + "e3", + "e4", + "e5", + "e6", + "e7", + "e8", + "e9", + "e10", + "v1", + "v2", + "v3", + "v4", + "v5")); } @Test public void methodsUseBlockedFeature() throws IOException { String args[] = {"methods", "-m", "json/graphWithBlockedElements.json"}; Result result = runCommand(args); + assertThat(result.getStatus(), is(0)); assertThat(result.getError(), is("")); assertThat(Arrays.asList(result.getOutput().split("\\s+")), - containsInAnyOrder("e1", - "e2", - "e3", - "e4", - "e7", - "e8", - "e9", - "v1", - "v2", - "v3", - "v4")); + containsInAnyOrder("e1", + "e2", + "e3", + "e4", + "e7", + "e8", + "e9", + "v1", + "v2", + "v3", + "v4")); } } diff --git a/graphwalker-cli/src/test/java/org/graphwalker/cli/OnlineTest.java b/graphwalker-cli/src/test/java/org/graphwalker/cli/OnlineTest.java index 91405a34..a5d9bf57 100644 --- a/graphwalker-cli/src/test/java/org/graphwalker/cli/OnlineTest.java +++ b/graphwalker-cli/src/test/java/org/graphwalker/cli/OnlineTest.java @@ -10,10 +10,10 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/graphwalker-cli/src/test/java/org/graphwalker/cli/PrintHelpTest.java b/graphwalker-cli/src/test/java/org/graphwalker/cli/PrintHelpTest.java index 5ac67d31..89534215 100644 --- a/graphwalker-cli/src/test/java/org/graphwalker/cli/PrintHelpTest.java +++ b/graphwalker-cli/src/test/java/org/graphwalker/cli/PrintHelpTest.java @@ -41,6 +41,7 @@ public class PrintHelpTest extends CLITestRoot { public void help() throws IOException { String args[] = {"--help"}; Result result = runCommand(args); + assertThat(result.getStatus(), is(0)); assertThat(result.getError(), is("")); assertThat(result.getOutput(), containsString("Usage: graphwalker [options] [command] [command options]")); } diff --git a/graphwalker-cli/src/test/java/org/graphwalker/cli/PrintVersionTest.java b/graphwalker-cli/src/test/java/org/graphwalker/cli/PrintVersionTest.java index c39754ee..9a71cbdd 100644 --- a/graphwalker-cli/src/test/java/org/graphwalker/cli/PrintVersionTest.java +++ b/graphwalker-cli/src/test/java/org/graphwalker/cli/PrintVersionTest.java @@ -10,10 +10,10 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -41,6 +41,7 @@ public class PrintVersionTest extends CLITestRoot { public void version() throws IOException { String args[] = {"--version"}; Result result = runCommand(args); + assertThat(result.getStatus(), is(0)); assertThat(result.getError(), is("")); assertThat(result.getOutput(), containsString("org.graphwalker version: ")); } diff --git a/graphwalker-cli/src/test/java/org/graphwalker/cli/RequirementsTest.java b/graphwalker-cli/src/test/java/org/graphwalker/cli/RequirementsTest.java index e4de582e..c09cbf1e 100644 --- a/graphwalker-cli/src/test/java/org/graphwalker/cli/RequirementsTest.java +++ b/graphwalker-cli/src/test/java/org/graphwalker/cli/RequirementsTest.java @@ -10,10 +10,10 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -43,6 +43,7 @@ public class RequirementsTest extends CLITestRoot { public void requirements() throws IOException { String args[] = {"requirements", "-m", "graphml/online/ShoppingCart.graphml"}; Result result = runCommand(args); + assertThat(result.getStatus(), is(0)); assertThat(result.getError(), is("")); List array = Arrays.asList(result.getOutput().split("\n")); @@ -50,10 +51,10 @@ public void requirements() throws IOException { array.set(i, array.get(i).trim()); } assertThat(array, - containsInAnyOrder("UC01 2.2.1", - "UC01 2.2.2", - "UC01 2.2.3", - "UC01 2.3", - "UC01 2.4")); + containsInAnyOrder("UC01 2.2.1", + "UC01 2.2.2", + "UC01 2.2.3", + "UC01 2.3", + "UC01 2.4")); } } diff --git a/graphwalker-cli/src/test/java/org/graphwalker/cli/SourceTest.java b/graphwalker-cli/src/test/java/org/graphwalker/cli/SourceTest.java index 4f460271..18bc9a89 100644 --- a/graphwalker-cli/src/test/java/org/graphwalker/cli/SourceTest.java +++ b/graphwalker-cli/src/test/java/org/graphwalker/cli/SourceTest.java @@ -10,10 +10,10 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -41,6 +41,7 @@ public class SourceTest extends CLITestRoot { public void generatePerl() throws IOException { String args[] = {"source", "--input", "json/example.json", "template/perl.template"}; Result result = runCommand(args); + assertThat(result.getStatus(), is(0)); assertThat(result.getError(), is("")); assertTrue(result.getOutput().length() > 1200 && result.getOutput().length() < 1300); } @@ -49,6 +50,7 @@ public void generatePerl() throws IOException { public void generatePython() throws IOException { String args[] = {"source", "--input", "json/example.json", "template/python.template"}; Result result = runCommand(args); + assertThat(result.getStatus(), is(0)); assertThat(result.getError(), is("")); assertTrue(result.getOutput().length() > 950 && result.getOutput().length() < 1150); } diff --git a/pom.xml b/pom.xml index d32f1a8a..22ee4d2c 100644 --- a/pom.xml +++ b/pom.xml @@ -433,7 +433,7 @@ org.jacoco jacoco-maven-plugin - 0.8.7 + 0.8.8