Repository: incubator-rya
Updated Branches:
  refs/heads/master 65f6d478c -> fa2aad55f


http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/fa2aad55/extras/rya.console/src/main/java/org/apache/rya/shell/util/JLinePrompt.java
----------------------------------------------------------------------
diff --git 
a/extras/rya.console/src/main/java/org/apache/rya/shell/util/JLinePrompt.java 
b/extras/rya.console/src/main/java/org/apache/rya/shell/util/JLinePrompt.java
index c9403b0..a259593 100644
--- 
a/extras/rya.console/src/main/java/org/apache/rya/shell/util/JLinePrompt.java
+++ 
b/extras/rya.console/src/main/java/org/apache/rya/shell/util/JLinePrompt.java
@@ -23,9 +23,6 @@ import static java.util.Objects.requireNonNull;
 import java.io.IOException;
 import java.util.Set;
 
-import edu.umd.cs.findbugs.annotations.DefaultAnnotation;
-import edu.umd.cs.findbugs.annotations.NonNull;
-
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.util.FieldUtils;
 import org.springframework.shell.core.Shell;
@@ -33,6 +30,8 @@ import org.springframework.shell.core.Shell;
 import com.google.common.base.Optional;
 import com.google.common.collect.Sets;
 
+import edu.umd.cs.findbugs.annotations.DefaultAnnotation;
+import edu.umd.cs.findbugs.annotations.NonNull;
 import jline.console.ConsoleReader;
 
 /**
@@ -72,6 +71,17 @@ public abstract class JLinePrompt {
      * @return A prompt that shows the default value for a field.
      */
     public String makeFieldPrompt(final String fieldName, final boolean 
defaultValue) {
+       return makeFieldPrompt(fieldName, Boolean.toString(defaultValue));
+    }
+
+    /**
+     * Formats a prompt that shows a default value.
+     *
+     * @param fieldName - The text portion that appears before the default. 
(not null)
+     * @param defaultValue - The default value that will be shown in the 
prompt.
+     * @return A prompt that shows the default value for a field.
+     */
+    public String makeFieldPrompt(final String fieldName, final String 
defaultValue) {
         return String.format("%s [default: %s]: ", fieldName, defaultValue);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/fa2aad55/extras/rya.console/src/main/java/org/apache/rya/shell/util/SparqlPrompt.java
----------------------------------------------------------------------
diff --git 
a/extras/rya.console/src/main/java/org/apache/rya/shell/util/SparqlPrompt.java 
b/extras/rya.console/src/main/java/org/apache/rya/shell/util/SparqlPrompt.java
index 97aefdd..2574eea 100644
--- 
a/extras/rya.console/src/main/java/org/apache/rya/shell/util/SparqlPrompt.java
+++ 
b/extras/rya.console/src/main/java/org/apache/rya/shell/util/SparqlPrompt.java
@@ -20,9 +20,10 @@ package org.apache.rya.shell.util;
 
 import java.io.IOException;
 
+import com.google.common.base.Optional;
+
 import edu.umd.cs.findbugs.annotations.DefaultAnnotation;
 import edu.umd.cs.findbugs.annotations.NonNull;
-
 import jline.console.ConsoleReader;
 
 /**
@@ -32,13 +33,12 @@ import jline.console.ConsoleReader;
 public interface SparqlPrompt {
 
     /**
-     * Prompt the user for a SPARQL query, wait for their input, and then get 
the
-     * value they entered.
+     * Prompt the user for a SPARQL query, wait for their input, and then get 
the value they entered.
      *
-     * @return The user entered SPARQL query.
-     * @throws IOEXception There was a problem reading the user's input.
+     * @return The user entered SPARQL query, or an empty string if the user 
aborts.
+     * @throws IOException There was a problem reading the user's input.
      */
-    public String getSparql() throws IOException;
+    public Optional<String> getSparql() throws IOException;
 
     /**
      * Prompts a user for a SPARQL query using a JLine {@link ConsoleReader}.
@@ -46,11 +46,37 @@ public interface SparqlPrompt {
     @DefaultAnnotation(NonNull.class)
     public static class JLineSparqlPrompt extends JLinePrompt implements 
SparqlPrompt {
 
+        private final String EXECUTE_COMMAND = "\\e";
+        private final String CLEAR_COMMAND = "\\c";
+
         @Override
-        public String getSparql() throws IOException {
+        public Optional<String> getSparql() throws IOException {
             final ConsoleReader reader = getReader();
-            reader.setPrompt("SPARQL: ");
-            return reader.readLine();
+            reader.setCopyPasteDetection(true); // disable tab completion from 
activating
+            reader.setHistoryEnabled(false);    // don't store SPARQL 
fragments in the command history
+            try {
+                reader.println("Enter a SPARQL Query.");
+                reader.println("Type '" + EXECUTE_COMMAND + "' to execute the 
current query.");
+                reader.println("Type '" + CLEAR_COMMAND + "' to clear the 
current query.");
+                reader.flush();
+
+                final StringBuilder sb = new StringBuilder();
+                String line = reader.readLine("SPARQL> ");
+                while (!line.endsWith(CLEAR_COMMAND) && 
!line.endsWith(EXECUTE_COMMAND)) {
+                    sb.append(line).append("\n");
+                    line = reader.readLine("     -> ");
+                }
+
+                if (line.endsWith(EXECUTE_COMMAND)) {
+                    sb.append(line.substring(0, line.length() - 
EXECUTE_COMMAND.length()));
+                    return Optional.of(sb.toString());
+                }
+                return Optional.absent();
+            } finally {
+                reader.setHistoryEnabled(true);      // restore the 
ConsoleReader's settings
+                reader.setCopyPasteDetection(false); // restore tab completion
+            }
         }
     }
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/fa2aad55/extras/rya.console/src/main/resources/META-INF/spring/spring-shell-plugin.xml
----------------------------------------------------------------------
diff --git 
a/extras/rya.console/src/main/resources/META-INF/spring/spring-shell-plugin.xml 
b/extras/rya.console/src/main/resources/META-INF/spring/spring-shell-plugin.xml
index 02d9f4f..48c4846 100644
--- 
a/extras/rya.console/src/main/resources/META-INF/spring/spring-shell-plugin.xml
+++ 
b/extras/rya.console/src/main/resources/META-INF/spring/spring-shell-plugin.xml
@@ -32,9 +32,19 @@
     <bean id="sharedShellState" class="org.apache.rya.shell.SharedShellState" 
/>
     <bean id="passwordPrompt" 
class="org.apache.rya.shell.util.PasswordPrompt.JLinePasswordPrompt" />
     <bean id="installPrompt" 
class="org.apache.rya.shell.util.InstallPrompt.JLineAccumuloInstallPrompt" />
+    <bean id="uninstallPrompt" 
class="org.apache.rya.shell.util.UninstallPrompt.JLineUninstallPrompt" />
     <bean id="sparqlPrompt" 
class="org.apache.rya.shell.util.SparqlPrompt.JLineSparqlPrompt" />
+    <bean id="consolePrinter" 
class="org.apache.rya.shell.util.ConsolePrinter.JLineConsolePrinter" />
     
     <!-- Define each of the beans that hold onto commands used by the shell. 
-->
     <bean id="ryaConnectionCommands" 
class="org.apache.rya.shell.RyaConnectionCommands" />
     <bean id="ryaAdminCommands" class="org.apache.rya.shell.RyaAdminCommands" 
/>
+    <bean id="ryaCommands" class="org.apache.rya.shell.RyaCommands" />
+    
+    <!--  
+    <bean id="springHelpCommands" 
class="org.springframework.shell.commands.HelpCommands" />
+    <bean id="springScriptCommands" 
class="org.springframework.shell.commands.ScriptCommands" />
+    <bean id="springExitCommands" 
class="org.springframework.shell.commands.ExitCommands" />
+    -->
+    
 </beans>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/fa2aad55/extras/rya.console/src/main/scripts/rya
----------------------------------------------------------------------
diff --git a/extras/rya.console/src/main/scripts/rya 
b/extras/rya.console/src/main/scripts/rya
new file mode 100644
index 0000000..5280286
--- /dev/null
+++ b/extras/rya.console/src/main/scripts/rya
@@ -0,0 +1,33 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+
+PROJECT_HOME=$(dirname $(cd $(dirname $0) && pwd))
+#cd $PROJECT_HOME
+
+java -cp $PROJECT_HOME/lib/${project.artifactId}-${project.version}-shaded.jar 
\
+  -Drya.shell.home="${PROJECT_HOME}/" \
+  -Dlog4j.configuration="file://$PROJECT_HOME/conf/log4j.properties" \
+  org.springframework.shell.Bootstrap "$@"
+  
+# --profiles - Specifies values for the system property spring.profiles.active 
so that Spring 3.1 and greater profile support is enabled.
+# --cmdfile - Specifies a file to read that contains shell commands
+# --histsize - Specifies the maximum number of lines to store in the command 
history file. Default value is 3000.
+# --disableInternalCommands - Flag that disables all commands that would be 
pre-registered with the shell. There is no argument to this option. You can 
selectively add back any internal commands by referencing them in your shell 
plugin file. Look at the Spring Shell javadocs for specific commands located in 
the org.springframework.shell.commands package as well as the section in this 
documentation of Built in commands.

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/fa2aad55/extras/rya.console/src/test/java/org/apache/rya/shell/RyaAdminCommandsTest.java
----------------------------------------------------------------------
diff --git 
a/extras/rya.console/src/test/java/org/apache/rya/shell/RyaAdminCommandsTest.java
 
b/extras/rya.console/src/test/java/org/apache/rya/shell/RyaAdminCommandsTest.java
index a5b73f2..e3e8d98 100644
--- 
a/extras/rya.console/src/test/java/org/apache/rya/shell/RyaAdminCommandsTest.java
+++ 
b/extras/rya.console/src/test/java/org/apache/rya/shell/RyaAdminCommandsTest.java
@@ -84,7 +84,7 @@ public class RyaAdminCommandsTest {
         state.connectedToInstance(instanceName);
 
         final SparqlPrompt mockSparqlPrompt = mock(SparqlPrompt.class);
-        when(mockSparqlPrompt.getSparql()).thenReturn(sparql);
+        when(mockSparqlPrompt.getSparql()).thenReturn(Optional.of(sparql));
 
         // Execute the command.
         final RyaAdminCommands commands = new RyaAdminCommands(state, 
mock(InstallPrompt.class), mockSparqlPrompt, mock(UninstallPrompt.class));
@@ -99,6 +99,29 @@ public class RyaAdminCommandsTest {
     }
 
     @Test
+    public void createPCJ_cancelledPrompt() 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);
+
+        final SparqlPrompt mockSparqlPrompt = mock(SparqlPrompt.class);
+        when(mockSparqlPrompt.getSparql()).thenReturn(Optional.absent());
+
+        // Execute the command.
+        final RyaAdminCommands commands = new RyaAdminCommands(state, 
mock(InstallPrompt.class), mockSparqlPrompt, mock(UninstallPrompt.class));
+        final String message = commands.createPcj();
+
+        // Verify a message is returned that explains what was created.
+        final String expected = "";
+        assertEquals(expected, message);
+    }
+
+    @Test
     public void deletePCJ() throws InstanceDoesNotExistException, 
RyaClientException {
         // Mock the object that performs the delete operation.
         final DeletePCJ mockDeletePCJ = mock(DeletePCJ.class);
@@ -170,7 +193,7 @@ public class RyaAdminCommandsTest {
 
         // Execute the command.
         final RyaAdminCommands commands = new RyaAdminCommands(state, 
mock(InstallPrompt.class), mock(SparqlPrompt.class), 
mock(UninstallPrompt.class));
-        final String message = commands.getInstanceDetails();
+        final String message = commands.printInstanceDetails();
 
         // Verify the values that were provided to the command were passed 
through to the GetInstanceDetails.
         verify(mockGetInstanceDetails).getDetails(eq(instanceName));
@@ -228,7 +251,7 @@ public class RyaAdminCommandsTest {
 
         final InstallPrompt mockInstallPrompt = mock(InstallPrompt.class);
         when(mockInstallPrompt.promptInstanceName()).thenReturn( instanceName 
);
-        when(mockInstallPrompt.promptInstallConfiguration()).thenReturn( 
installConfig );
+        
when(mockInstallPrompt.promptInstallConfiguration(instanceName)).thenReturn( 
installConfig );
         when(mockInstallPrompt.promptVerified(eq(instanceName), 
eq(installConfig))).thenReturn(true);
 
         final RyaAdminCommands commands = new RyaAdminCommands(state, 
mockInstallPrompt, mock(SparqlPrompt.class), mock(UninstallPrompt.class));
@@ -243,6 +266,97 @@ public class RyaAdminCommandsTest {
     }
 
     @Test
+    public void installWithParameters() throws DuplicateInstanceNameException, 
RyaClientException, IOException {
+        // Mock the object that performs the install operation.
+        final Install mockInstall = mock(Install.class);
+
+        final RyaClient mockCommands = mock(RyaClient.class);
+        when(mockCommands.getInstall()).thenReturn( mockInstall );
+
+        final SharedShellState state = new SharedShellState();
+        state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), 
mockCommands);
+
+        final String instanceName = "unitTests";
+        final boolean enableTableHashPrefix = false;
+        final boolean enableEntityCentricIndex = true;
+        final boolean enableFreeTextIndex = false;
+        final boolean enableGeospatialIndex = true;
+        final boolean enableTemporalIndex = false;
+        final boolean enablePcjIndex = true;
+        final String fluoPcjAppName = instanceName + "pcj_updater";
+
+        // Execute the command.
+        final InstallConfiguration installConfig = 
InstallConfiguration.builder()
+                .setEnableTableHashPrefix(enableTableHashPrefix)
+                .setEnableEntityCentricIndex(enableEntityCentricIndex)
+                .setEnableFreeTextIndex(enableFreeTextIndex)
+                .setEnableGeoIndex(enableGeospatialIndex)
+                .setEnableTemporalIndex(enableTemporalIndex)
+                .setEnablePcjIndex(enablePcjIndex)
+                .setFluoPcjAppName(fluoPcjAppName)
+                .build();
+
+        final InstallPrompt mockInstallPrompt = mock(InstallPrompt.class);
+        when(mockInstallPrompt.promptInstanceName()).thenReturn( instanceName 
);
+        
when(mockInstallPrompt.promptInstallConfiguration(instanceName)).thenReturn( 
installConfig );
+        when(mockInstallPrompt.promptVerified(eq(instanceName), 
eq(installConfig))).thenReturn(true);
+
+        final RyaAdminCommands commands = new RyaAdminCommands(state, 
mockInstallPrompt, mock(SparqlPrompt.class), mock(UninstallPrompt.class));
+        final String message = commands.installWithParameters(instanceName, 
enableTableHashPrefix, enableEntityCentricIndex, enableFreeTextIndex, 
enableGeospatialIndex, enableTemporalIndex, enablePcjIndex, fluoPcjAppName);
+
+        // Verify the values that were provided to the command were passed 
through to the Install.
+        verify(mockInstall).install(eq(instanceName), eq(installConfig));
+
+        // Verify a message is returned that indicates the success of the 
operation.
+        final String expected = "The Rya instance named 'unitTests' has been 
installed.";
+        assertEquals(expected, message);
+    }
+
+    @Test
+    public void installWithParameters_userAbort() throws 
DuplicateInstanceNameException, RyaClientException, IOException {
+        // Mock the object that performs the install operation.
+        final Install mockInstall = mock(Install.class);
+
+        final RyaClient mockCommands = mock(RyaClient.class);
+        when(mockCommands.getInstall()).thenReturn( mockInstall );
+
+        final SharedShellState state = new SharedShellState();
+        state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), 
mockCommands);
+
+        final String instanceName = "unitTests";
+        final boolean enableTableHashPrefix = false;
+        final boolean enableEntityCentricIndex = true;
+        final boolean enableFreeTextIndex = false;
+        final boolean enableGeospatialIndex = true;
+        final boolean enableTemporalIndex = false;
+        final boolean enablePcjIndex = true;
+        final String fluoPcjAppName = instanceName + "pcj_updater";
+
+        // Execute the command.
+        final InstallConfiguration installConfig = 
InstallConfiguration.builder()
+                .setEnableTableHashPrefix(enableTableHashPrefix)
+                .setEnableEntityCentricIndex(enableEntityCentricIndex)
+                .setEnableFreeTextIndex(enableFreeTextIndex)
+                .setEnableGeoIndex(enableGeospatialIndex)
+                .setEnableTemporalIndex(enableTemporalIndex)
+                .setEnablePcjIndex(enablePcjIndex)
+                .setFluoPcjAppName(fluoPcjAppName)
+                .build();
+
+        final InstallPrompt mockInstallPrompt = mock(InstallPrompt.class);
+        when(mockInstallPrompt.promptInstanceName()).thenReturn( instanceName 
);
+        
when(mockInstallPrompt.promptInstallConfiguration(instanceName)).thenReturn( 
installConfig );
+        when(mockInstallPrompt.promptVerified(eq(instanceName), 
eq(installConfig))).thenReturn(false);
+
+        final RyaAdminCommands commands = new RyaAdminCommands(state, 
mockInstallPrompt, mock(SparqlPrompt.class), mock(UninstallPrompt.class));
+        final String message = commands.installWithParameters(instanceName, 
enableTableHashPrefix, enableEntityCentricIndex, enableFreeTextIndex, 
enableGeospatialIndex, enableTemporalIndex, enablePcjIndex, fluoPcjAppName);
+
+        // Verify a message is returned that indicates the success of the 
operation.
+        final String expected = "Skipping Installation.";
+        assertEquals(expected, message);
+    }
+
+    @Test
     public void listInstances() throws RyaClientException, IOException {
         // Mock the object that performs the list operation.
         final ListInstances mockListInstances = mock(ListInstances.class);

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/fa2aad55/extras/rya.console/src/test/java/org/apache/rya/shell/RyaCommandsTest.java
----------------------------------------------------------------------
diff --git 
a/extras/rya.console/src/test/java/org/apache/rya/shell/RyaCommandsTest.java 
b/extras/rya.console/src/test/java/org/apache/rya/shell/RyaCommandsTest.java
new file mode 100644
index 0000000..a0a3979
--- /dev/null
+++ b/extras/rya.console/src/test/java/org/apache/rya/shell/RyaCommandsTest.java
@@ -0,0 +1,278 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.rya.shell;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Paths;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.rya.api.client.ExecuteSparqlQuery;
+import org.apache.rya.api.client.InstanceDoesNotExistException;
+import org.apache.rya.api.client.LoadStatementsFile;
+import org.apache.rya.api.client.RyaClient;
+import org.apache.rya.api.client.RyaClientException;
+import org.apache.rya.api.client.accumulo.AccumuloConnectionDetails;
+import org.apache.rya.shell.util.ConsolePrinter;
+import org.apache.rya.shell.util.SparqlPrompt;
+import org.junit.Test;
+import org.openrdf.rio.RDFFormat;
+
+import com.google.common.base.Optional;
+
+/**
+ * Unit tests the methods of {@link RyaAdminCommands}.
+ */
+public class RyaCommandsTest {
+
+    @Test
+    public void testLoadData() throws InstanceDoesNotExistException, 
RyaClientException, IOException {
+        // Mock the object that performs the create operation.
+        final String instanceName = "unitTest";
+        final String statementsFile = "/path/to/statements.nt";
+        final String format = null;
+
+        final LoadStatementsFile mockLoadStatementsFile = 
mock(LoadStatementsFile.class);
+        final RyaClient mockCommands = mock(RyaClient.class);
+        
when(mockCommands.getLoadStatementsFile()).thenReturn(mockLoadStatementsFile);
+
+        final SharedShellState state = new SharedShellState();
+        state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), 
mockCommands);
+        state.connectedToInstance(instanceName);
+
+        final SparqlPrompt mockSparqlPrompt = mock(SparqlPrompt.class);
+
+        final ConsolePrinter mockConsolePrinter = mock(ConsolePrinter.class);
+
+        // Execute the command.
+        final RyaCommands commands = new RyaCommands(state, mockSparqlPrompt, 
mockConsolePrinter);
+        final String message = commands.loadData(statementsFile, format);
+
+        // Verify the values that were provided to the command were passed 
through to LoadStatementsFile.
+        verify(mockLoadStatementsFile).loadStatements(instanceName, 
Paths.get(statementsFile), RDFFormat.NTRIPLES);
+
+        // Verify a message is returned that explains what was created.
+        assertTrue(message.startsWith("Loaded the file: '" + statementsFile 
+"' successfully in "));
+        assertTrue(message.endsWith(" seconds."));
+    }
+
+    @Test
+    public void testLoadData_specifyFormat() throws 
InstanceDoesNotExistException, RyaClientException, IOException {
+        // Mock the object that performs the create operation.
+        final String instanceName = "unitTest";
+        final String statementsFile = "/path/to/statements.nt";
+        final String format = "N-TRIPLES";
+
+        final LoadStatementsFile mockLoadStatementsFile = 
mock(LoadStatementsFile.class);
+        final RyaClient mockCommands = mock(RyaClient.class);
+        
when(mockCommands.getLoadStatementsFile()).thenReturn(mockLoadStatementsFile);
+
+        final SharedShellState state = new SharedShellState();
+        state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), 
mockCommands);
+        state.connectedToInstance(instanceName);
+
+        final SparqlPrompt mockSparqlPrompt = mock(SparqlPrompt.class);
+
+        final ConsolePrinter mockConsolePrinter = mock(ConsolePrinter.class);
+
+        // Execute the command.
+        final RyaCommands commands = new RyaCommands(state, mockSparqlPrompt, 
mockConsolePrinter);
+        final String message = commands.loadData(statementsFile, format);
+
+        // Verify the values that were provided to the command were passed 
through to LoadStatementsFile.
+        verify(mockLoadStatementsFile).loadStatements(instanceName, 
Paths.get(statementsFile), RDFFormat.NTRIPLES);
+
+        // Verify a message is returned that explains what was created.
+        assertTrue(message.startsWith("Loaded the file: '" + statementsFile 
+"' successfully in "));
+        assertTrue(message.endsWith(" seconds."));
+    }
+
+    @Test(expected = RuntimeException.class)
+    public void testLoadData_specifyInvalidFormat() throws 
InstanceDoesNotExistException, RyaClientException, IOException {
+        // Mock the object that performs the create operation.
+        final String instanceName = "unitTest";
+        final String statementsFile = "/path/to/statements.nt";
+        final String format = "INVALID_FORMAT_NAME";
+
+        final LoadStatementsFile mockLoadStatementsFile = 
mock(LoadStatementsFile.class);
+        final RyaClient mockCommands = mock(RyaClient.class);
+        
when(mockCommands.getLoadStatementsFile()).thenReturn(mockLoadStatementsFile);
+
+        final SharedShellState state = new SharedShellState();
+        state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), 
mockCommands);
+        state.connectedToInstance(instanceName);
+
+        final SparqlPrompt mockSparqlPrompt = mock(SparqlPrompt.class);
+
+        final ConsolePrinter mockConsolePrinter = mock(ConsolePrinter.class);
+
+        // Execute the command.
+        final RyaCommands commands = new RyaCommands(state, mockSparqlPrompt, 
mockConsolePrinter);
+
+        commands.loadData(statementsFile, format);
+    }
+
+    @Test(expected = RuntimeException.class)
+    public void testLoadData_specifyInvalidFilenameFormat() throws 
InstanceDoesNotExistException, RyaClientException, IOException {
+        // Mock the object that performs the create operation.
+        final String instanceName = "unitTest";
+        final String statementsFile = "/path/to/statements.invalidFormat";
+        final String format = null;
+
+        final LoadStatementsFile mockLoadStatementsFile = 
mock(LoadStatementsFile.class);
+        final RyaClient mockCommands = mock(RyaClient.class);
+        
when(mockCommands.getLoadStatementsFile()).thenReturn(mockLoadStatementsFile);
+
+        final SharedShellState state = new SharedShellState();
+        state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), 
mockCommands);
+        state.connectedToInstance(instanceName);
+
+        final SparqlPrompt mockSparqlPrompt = mock(SparqlPrompt.class);
+
+        final ConsolePrinter mockConsolePrinter = mock(ConsolePrinter.class);
+
+        // Execute the command.
+        final RyaCommands commands = new RyaCommands(state, mockSparqlPrompt, 
mockConsolePrinter);
+
+        commands.loadData(statementsFile, format);
+    }
+
+    @Test
+    public void testSparqlQuery() throws InstanceDoesNotExistException, 
RyaClientException, IOException {
+        // Mock the object that performs the create operation.
+        final String instanceName = "unitTest";
+        final String queryFile = "src/test/resources/Query1.sparql";
+        final String queryContent = FileUtils.readFileToString(new 
File(queryFile), StandardCharsets.UTF_8);
+        final String expectedMessage = "MockAnswer";
+
+        final ExecuteSparqlQuery mockExecuteSparqlQuery = 
mock(ExecuteSparqlQuery.class);
+        when(mockExecuteSparqlQuery.executeSparqlQuery(instanceName, 
queryContent)).thenReturn(expectedMessage);
+
+        final RyaClient mockCommands = mock(RyaClient.class);
+        
when(mockCommands.getExecuteSparqlQuery()).thenReturn(mockExecuteSparqlQuery);
+
+
+        final SharedShellState state = new SharedShellState();
+        state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), 
mockCommands);
+        state.connectedToInstance(instanceName);
+
+        final SparqlPrompt mockSparqlPrompt = mock(SparqlPrompt.class);
+
+        final ConsolePrinter mockConsolePrinter = mock(ConsolePrinter.class);
+
+        // Execute the command.
+        final RyaCommands commands = new RyaCommands(state, mockSparqlPrompt, 
mockConsolePrinter);
+        final String message = commands.sparqlQuery(queryFile);
+
+        // Verify the values that were provided to the command were passed 
through to LoadStatementsFile.
+        verify(mockExecuteSparqlQuery).executeSparqlQuery(instanceName, 
queryContent);
+
+        assertEquals(expectedMessage, message);
+        // Verify a message is returned that explains what was created.
+    }
+
+    @Test(expected = RuntimeException.class)
+    public void testSparqlQuery_nonexistentFile() throws 
InstanceDoesNotExistException, RyaClientException, IOException {
+        // Mock the object that performs the create operation.
+        final String instanceName = "unitTest";
+        final String queryFile = "src/test/resources/Nonexistent.sparql";
+
+        final RyaClient mockCommands = mock(RyaClient.class);
+
+        final SharedShellState state = new SharedShellState();
+        state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), 
mockCommands);
+        state.connectedToInstance(instanceName);
+
+        final SparqlPrompt mockSparqlPrompt = mock(SparqlPrompt.class);
+
+        final ConsolePrinter mockConsolePrinter = mock(ConsolePrinter.class);
+
+        // Execute the command.
+        final RyaCommands commands = new RyaCommands(state, mockSparqlPrompt, 
mockConsolePrinter);
+        commands.sparqlQuery(queryFile);
+    }
+
+    @Test
+    public void testSparqlQuery_fromPrompt() throws 
InstanceDoesNotExistException, RyaClientException, IOException {
+        // Mock the object that performs the create operation.
+        final String instanceName = "unitTest";
+        final String queryContent = "SELECT * WHERE { ?person <http://isA> 
?noun }";
+        final String queryFile = null;
+        final String expectedMessage = "MockAnswer";
+
+        final ExecuteSparqlQuery mockExecuteSparqlQuery = 
mock(ExecuteSparqlQuery.class);
+        when(mockExecuteSparqlQuery.executeSparqlQuery(instanceName, 
queryContent)).thenReturn(expectedMessage);
+
+        final RyaClient mockCommands = mock(RyaClient.class);
+        
when(mockCommands.getExecuteSparqlQuery()).thenReturn(mockExecuteSparqlQuery);
+
+
+        final SharedShellState state = new SharedShellState();
+        state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), 
mockCommands);
+        state.connectedToInstance(instanceName);
+
+        final SparqlPrompt mockSparqlPrompt = mock(SparqlPrompt.class);
+        
when(mockSparqlPrompt.getSparql()).thenReturn(Optional.of(queryContent));
+
+        final ConsolePrinter mockConsolePrinter = mock(ConsolePrinter.class);
+
+        // Execute the command.
+        final RyaCommands commands = new RyaCommands(state, mockSparqlPrompt, 
mockConsolePrinter);
+        final String message = commands.sparqlQuery(queryFile);
+
+        // Verify the values that were provided to the command were passed 
through to LoadStatementsFile.
+        verify(mockExecuteSparqlQuery).executeSparqlQuery(instanceName, 
queryContent);
+
+        assertEquals(expectedMessage, message);
+        // Verify a message is returned that explains what was created.
+    }
+
+    @Test
+    public void testSparqlQuery_fromPrompt_cancelled() throws 
InstanceDoesNotExistException, RyaClientException, IOException {
+        // Mock the object that performs the create operation.
+        final String instanceName = "unitTest";
+        final String queryFile = null;
+        final String expectedMessage = "";
+
+        final RyaClient mockCommands = mock(RyaClient.class);
+
+        final SharedShellState state = new SharedShellState();
+        state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), 
mockCommands);
+        state.connectedToInstance(instanceName);
+
+        final SparqlPrompt mockSparqlPrompt = mock(SparqlPrompt.class);
+        when(mockSparqlPrompt.getSparql()).thenReturn(Optional.absent());
+
+        final ConsolePrinter mockConsolePrinter = mock(ConsolePrinter.class);
+
+        // Execute the command.
+        final RyaCommands commands = new RyaCommands(state, mockSparqlPrompt, 
mockConsolePrinter);
+        final String message = commands.sparqlQuery(queryFile);
+
+        assertEquals(expectedMessage, message);
+        // Verify a message is returned that explains what was created.
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/fa2aad55/extras/rya.console/src/test/java/org/apache/rya/shell/RyaConnectionCommandsIT.java
----------------------------------------------------------------------
diff --git 
a/extras/rya.console/src/test/java/org/apache/rya/shell/RyaConnectionCommandsIT.java
 
b/extras/rya.console/src/test/java/org/apache/rya/shell/RyaConnectionCommandsIT.java
index 6d2644b..f424c49 100644
--- 
a/extras/rya.console/src/test/java/org/apache/rya/shell/RyaConnectionCommandsIT.java
+++ 
b/extras/rya.console/src/test/java/org/apache/rya/shell/RyaConnectionCommandsIT.java
@@ -16,24 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-///**
-// * Licensed to the Apache Software Foundation (ASF) under one
-// * or more contributor license agreements.  See the NOTICE file
-// * distributed with this work for additional information
-// * regarding copyright ownership.  The ASF licenses this file
-// * to you under the Apache License, Version 2.0 (the
-// * "License"); you may not use this file except in compliance
-// * with the License.  You may obtain a copy of the License at
-// *
-// *     http://www.apache.org/licenses/LICENSE-2.0
-// *
-// * Unless required by applicable law or agreed to in writing,
-// * software distributed under the License is distributed on an
-// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// * KIND, either express or implied.  See the License for the
-// * specific language governing permissions and limitations
-// * under the License.
-// */
 package org.apache.rya.shell;
 
 import static org.junit.Assert.assertEquals;
@@ -44,17 +26,16 @@ import static org.mockito.Mockito.when;
 import java.io.IOException;
 
 import org.apache.accumulo.minicluster.MiniAccumuloCluster;
-import org.junit.Test;
-import org.springframework.context.ApplicationContext;
-import org.springframework.shell.Bootstrap;
-import org.springframework.shell.core.CommandResult;
-import org.springframework.shell.core.JLineShellComponent;
-
 import org.apache.rya.api.client.Install.InstallConfiguration;
 import org.apache.rya.shell.SharedShellState.ConnectionState;
 import org.apache.rya.shell.SharedShellState.ShellState;
 import org.apache.rya.shell.util.InstallPrompt;
 import org.apache.rya.shell.util.PasswordPrompt;
+import org.junit.Test;
+import org.springframework.context.ApplicationContext;
+import org.springframework.shell.Bootstrap;
+import org.springframework.shell.core.CommandResult;
+import org.springframework.shell.core.JLineShellComponent;
 
 /**
  * Integration tests the methods of {@link RyaConnectionCommands}.
@@ -201,7 +182,7 @@ public class RyaConnectionCommandsIT extends RyaShellITBase 
{
 
         final InstallPrompt installPrompt = context.getBean( 
InstallPrompt.class );
         when(installPrompt.promptInstanceName()).thenReturn("testInstance");
-        when(installPrompt.promptInstallConfiguration()).thenReturn( 
installConf );
+        
when(installPrompt.promptInstallConfiguration("testInstance")).thenReturn( 
installConf );
         when(installPrompt.promptVerified(instanceName, 
installConf)).thenReturn(true);
 
         result = shell.executeCommand( RyaAdminCommands.INSTALL_CMD );

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/fa2aad55/extras/rya.console/src/test/resources/Query1.sparql
----------------------------------------------------------------------
diff --git a/extras/rya.console/src/test/resources/Query1.sparql 
b/extras/rya.console/src/test/resources/Query1.sparql
new file mode 100644
index 0000000..555607e
--- /dev/null
+++ b/extras/rya.console/src/test/resources/Query1.sparql
@@ -0,0 +1,20 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+SELECT * WHERE { ?person <http://isA> ?noun }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/fa2aad55/extras/rya.console/src/test/resources/RyaShellTest-context.xml
----------------------------------------------------------------------
diff --git a/extras/rya.console/src/test/resources/RyaShellTest-context.xml 
b/extras/rya.console/src/test/resources/RyaShellTest-context.xml
index f841129..f7ffe0f 100644
--- a/extras/rya.console/src/test/resources/RyaShellTest-context.xml
+++ b/extras/rya.console/src/test/resources/RyaShellTest-context.xml
@@ -46,6 +46,11 @@
         <constructor-arg value="org.apache.rya.shell.util.SparqlPrompt"/>
     </bean>
     
+    <!-- We use a mock ConsolePrintert here to simulate console output to the 
user. -->
+    <bean id="consolePrinter" class="org.mockito.Mockito" 
factory-method="mock">
+        <constructor-arg value="org.apache.rya.shell.util.ConsolePrinter"/>
+    </bean>
+    
     <!-- We use a mock Uninstall Prompt here to simulate a user entering the 
installation configuration. -->
     <bean id="uninstallPrompt" class="org.mockito.Mockito" 
factory-method="mock">
         <constructor-arg value="org.apache.rya.shell.util.UninstallPrompt"/>
@@ -53,5 +58,6 @@
 
     <!-- Define each of the beans that hold onto commands used by the shell. 
-->
     <bean id="ryaConnectionCommands" 
class="org.apache.rya.shell.RyaConnectionCommands" />
+    <bean id="ryaCommands" class="org.apache.rya.shell.RyaCommands" />
     <bean id="ryaAdminCommands" class="org.apache.rya.shell.RyaAdminCommands" 
/>
 </beans>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/fa2aad55/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 52c5bd6..93c6ed8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -293,6 +293,11 @@ under the License.
             </dependency>
             <dependency>
                 <groupId>org.openrdf.sesame</groupId>
+                <artifactId>sesame-queryresultio-text</artifactId>
+                <version>${openrdf.sesame.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.openrdf.sesame</groupId>
                 <artifactId>sesame-rio-rdfxml</artifactId>
                 <version>${openrdf.sesame.version}</version>
             </dependency>
@@ -780,6 +785,11 @@ under the License.
                     </configuration>
                 </plugin>
                 <plugin>
+                    <groupId>org.jacoco</groupId>
+                    <artifactId>jacoco-maven-plugin</artifactId>
+                    <version>0.7.9</version>
+                </plugin>
+                <plugin>
                     <groupId>org.apache.maven.plugins</groupId>
                     <artifactId>maven-checkstyle-plugin</artifactId>
                 </plugin>


Reply via email to