RYA-362 Improved UX for case where create-pcj is called without args. Closes #223
Project: http://git-wip-us.apache.org/repos/asf/incubator-rya/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-rya/commit/28b0a52d Tree: http://git-wip-us.apache.org/repos/asf/incubator-rya/tree/28b0a52d Diff: http://git-wip-us.apache.org/repos/asf/incubator-rya/diff/28b0a52d Branch: refs/heads/master Commit: 28b0a52d056a553f8602cd204791d577d50b5e1c Parents: 4624598 Author: jdasch <hcs...@gmail.com> Authored: Thu Sep 7 10:14:18 2017 -0400 Committer: David Lotts <david.lo...@parsons.com> Committed: Fri Sep 8 15:04:33 2017 -0400 ---------------------------------------------------------------------- .../org/apache/rya/shell/RyaAdminCommands.java | 25 ++++++++++---------- .../apache/rya/shell/RyaAdminCommandsTest.java | 19 +++++++++++++++ 2 files changed, 32 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/28b0a52d/extras/shell/src/main/java/org/apache/rya/shell/RyaAdminCommands.java ---------------------------------------------------------------------- diff --git a/extras/shell/src/main/java/org/apache/rya/shell/RyaAdminCommands.java b/extras/shell/src/main/java/org/apache/rya/shell/RyaAdminCommands.java index 7d0ab79..db81096 100644 --- a/extras/shell/src/main/java/org/apache/rya/shell/RyaAdminCommands.java +++ b/extras/shell/src/main/java/org/apache/rya/shell/RyaAdminCommands.java @@ -290,9 +290,9 @@ public class RyaAdminCommands implements CommandMarker { @CliCommand(value = CREATE_PCJ_CMD, help = "Creates and starts the maintenance of a new PCJ using a Fluo application.") public String createPcj( - @CliOption(key = {"exportToRya"}, mandatory = false, help = "Indicates that results for the query should be exported to a Rya PCJ table.") + @CliOption(key = {"exportToRya"}, mandatory = false, help = "Indicates that results for the query should be exported to a Rya PCJ table.", unspecifiedDefaultValue = "false", specifiedDefaultValue = "true") boolean exportToRya, - @CliOption(key = {"exportToKafka"}, mandatory = false, help = "Indicates that results for the query should be exported to a Kafka Topic.") + @CliOption(key = {"exportToKafka"}, mandatory = false, help = "Indicates that results for the query should be exported to a Kafka Topic.", unspecifiedDefaultValue = "false", specifiedDefaultValue = "true") boolean exportToKafka) { // Fetch the command that is connected to the store. final ShellState shellState = state.getShellState(); @@ -300,19 +300,20 @@ public class RyaAdminCommands implements CommandMarker { final String ryaInstance = shellState.getRyaInstanceName().get(); try { + final Set<ExportStrategy> strategies = new HashSet<>(); + if(exportToRya) { + strategies.add(ExportStrategy.RYA); + } + if(exportToKafka) { + strategies.add(ExportStrategy.KAFKA); + } + if(strategies.isEmpty()) { + return "The user must specify at least one export strategy: (--exportToRya, --exportToKafka)"; + } + // Prompt the user for the SPARQL. final Optional<String> sparql = sparqlPrompt.getSparql(); if (sparql.isPresent()) { - Set<ExportStrategy> strategies = new HashSet<>(); - if(exportToRya) { - strategies.add(ExportStrategy.RYA); - } - if(exportToKafka) { - strategies.add(ExportStrategy.KAFKA); - } - if(strategies.size() == 0) { - return "The user must specify at least one export strategy by setting either exportToRya or exportToKafka to true."; - } // Execute the command. final String pcjId = commands.getCreatePCJ().createPCJ(ryaInstance, sparql.get(), strategies); // Return a message that indicates the ID of the newly created ID. http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/28b0a52d/extras/shell/src/test/java/org/apache/rya/shell/RyaAdminCommandsTest.java ---------------------------------------------------------------------- diff --git a/extras/shell/src/test/java/org/apache/rya/shell/RyaAdminCommandsTest.java b/extras/shell/src/test/java/org/apache/rya/shell/RyaAdminCommandsTest.java index f08e02a..1249536 100644 --- a/extras/shell/src/test/java/org/apache/rya/shell/RyaAdminCommandsTest.java +++ b/extras/shell/src/test/java/org/apache/rya/shell/RyaAdminCommandsTest.java @@ -128,6 +128,25 @@ public class RyaAdminCommandsTest { } @Test + public void createPCJ_noExportStrategy() throws InstanceDoesNotExistException, RyaClientException, IOException { + // Mock the object that performs the create operation. + final String instanceName = "unitTest"; + + final RyaClient mockCommands = mock(RyaClient.class); + + final SharedShellState state = new SharedShellState(); + state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), mockCommands); + state.connectedToInstance(instanceName); + + // Execute the command. + final RyaAdminCommands commands = new RyaAdminCommands(state, mock(InstallPrompt.class), mock(SparqlPrompt.class), mock(UninstallPrompt.class)); + final String message = commands.createPcj(false, false); + + // Verify a message is returned that explains what was created. + assertEquals("The user must specify at least one export strategy: (--exportToRya, --exportToKafka)", message); + } + + @Test public void deletePCJ() throws InstanceDoesNotExistException, RyaClientException { // Mock the object that performs the delete operation. final DeletePCJ mockDeletePCJ = mock(DeletePCJ.class);