use of org.apache.rya.shell.util.SparqlPrompt in project incubator-rya by apache.
the class RyaCommandsTest method testLoadData_specifyInvalidFormat.
@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);
}
use of org.apache.rya.shell.util.SparqlPrompt in project incubator-rya by apache.
the class RyaCommandsTest method testLoadData.
@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."));
}
use of org.apache.rya.shell.util.SparqlPrompt in project incubator-rya by apache.
the class RyaCommandsTest method loadData_relativePath.
@Test
public void loadData_relativePath() throws Exception {
// Mock the object that performs the create operation.
final String instanceName = "unitTest";
final String statementsFile = "~/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
// using a user rooted filename.
String rootedFile = System.getProperty("user.home") + "/statements.nt";
verify(mockLoadStatementsFile).loadStatements(instanceName, Paths.get(rootedFile), 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."));
}
use of org.apache.rya.shell.util.SparqlPrompt in project incubator-rya by apache.
the class RyaStreamsCommandsTest method addQuery_userAbortsSparqlPrompt.
@Test
public void addQuery_userAbortsSparqlPrompt() throws Exception {
// Mock the object that performs the rya streams operation.
final RyaStreamsClient mockClient = mock(RyaStreamsClient.class);
final AddQuery addQuery = mock(AddQuery.class);
when(mockClient.getAddQuery()).thenReturn(addQuery);
// Mock a SPARQL prompt that a user aborts.
final SparqlPrompt prompt = mock(SparqlPrompt.class);
when(prompt.getSparql()).thenReturn(Optional.absent());
// Mock a shell state and connect it to a Rya instance.
final SharedShellState state = new SharedShellState();
state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), mock(RyaClient.class));
state.connectedToInstance("unitTest");
state.connectedToRyaStreams(mockClient);
// Execute the command.
final RyaStreamsCommands commands = new RyaStreamsCommands(state, prompt, mock(ConsolePrinter.class));
final String message = commands.addQuery(false, false);
// Verify a message is printed to the user.
assertEquals("", message);
}
use of org.apache.rya.shell.util.SparqlPrompt in project incubator-rya by apache.
the class RyaStreamsCommandsTest method addQuery_doNotInsertQuery.
@Test
public void addQuery_doNotInsertQuery() throws Exception {
// Mock the object that performs the rya streams operation.
final RyaStreamsClient mockClient = mock(RyaStreamsClient.class);
final AddQuery addQuery = mock(AddQuery.class);
when(mockClient.getAddQuery()).thenReturn(addQuery);
final String sparql = "SELECT * WHERE { ?a ?b ?c }";
final StreamsQuery addedQuery = new StreamsQuery(UUID.randomUUID(), sparql, true, false);
when(addQuery.addQuery(eq(sparql), eq(true), eq(false))).thenReturn(addedQuery);
// Mock a SPARQL prompt that a user entered a query through.
final SparqlPrompt prompt = mock(SparqlPrompt.class);
when(prompt.getSparql()).thenReturn(Optional.of(sparql));
// Mock a shell state and connect it to a Rya instance.
final SharedShellState state = new SharedShellState();
state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), mock(RyaClient.class));
state.connectedToInstance("unitTest");
state.connectedToRyaStreams(mockClient);
// Execute the command.
final RyaStreamsCommands commands = new RyaStreamsCommands(state, prompt, mock(ConsolePrinter.class));
final String message = commands.addQuery(false, false);
// Verify the interactor was invoked with the provided input.
verify(addQuery).addQuery(sparql, true, false);
// Verify a message is printed to the user.
final String expected = "The added query's ID is " + addedQuery.getQueryId();
assertEquals(expected, message);
}
Aggregations