use of org.apache.rya.streams.api.RyaStreamsClient 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.streams.api.RyaStreamsClient in project incubator-rya by apache.
the class RyaStreamsCommandsTest method stopQuery_alreadyStopped.
@Test
public void stopQuery_alreadyStopped() throws Exception {
// Mock the object that performs the rya streams operation.
final RyaStreamsClient mockClient = mock(RyaStreamsClient.class);
final StopQuery stopQuery = mock(StopQuery.class);
when(mockClient.getStopQuery()).thenReturn(stopQuery);
final GetQuery getQuery = mock(GetQuery.class);
when(mockClient.getGetQuery()).thenReturn(getQuery);
// 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);
// Report the query as not running.
final UUID queryId = UUID.randomUUID();
when(getQuery.getQuery(eq(queryId))).thenReturn(java.util.Optional.of(new StreamsQuery(queryId, "sparql", false, false)));
// Execute the command.
final RyaStreamsCommands commands = new RyaStreamsCommands(state, mock(SparqlPrompt.class), mock(ConsolePrinter.class));
final String message = commands.stopQuery(queryId.toString());
// Verify the interactor was not invoked with the provided parameters.
verify(stopQuery, never()).stop(queryId);
// Verify a message is printed to the user.
final String expected = "That query is already stopped.";
assertEquals(expected, message);
}
use of org.apache.rya.streams.api.RyaStreamsClient 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);
}
use of org.apache.rya.streams.api.RyaStreamsClient in project incubator-rya by apache.
the class RyaStreamsCommandsTest method printQueryDetails.
@Test
public void printQueryDetails() throws Exception {
// Mock the object that performs the rya streams operation.
final RyaStreamsClient mockClient = mock(RyaStreamsClient.class);
final GetQuery getQuery = mock(GetQuery.class);
when(mockClient.getGetQuery()).thenReturn(getQuery);
final UUID queryId = UUID.fromString("da55cea5-c21c-46a5-ab79-5433eef4efaa");
final StreamsQuery query = new StreamsQuery(queryId, "SELECT * WHERE { ?a ?b ?c . }", true, false);
when(getQuery.getQuery(queryId)).thenReturn(java.util.Optional.of(query));
// 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, mock(SparqlPrompt.class), mock(ConsolePrinter.class));
final String message = commands.printQueryDetails(queryId.toString());
// Verify the correct report is returned.
final String expected = " Query ID: da55cea5-c21c-46a5-ab79-5433eef4efaa\n" + "Is Active: true\n" + "Is Insert: false\n" + " SPARQL: select ?a ?b ?c\n" + " where {\n" + " ?a ?b ?c.\n" + " }\n";
assertEquals(expected, message);
}
use of org.apache.rya.streams.api.RyaStreamsClient in project incubator-rya by apache.
the class RyaStreamsCommandsTest method addQuery_insertQueryNotCorrectType.
@Test(expected = RuntimeException.class)
public void addQuery_insertQueryNotCorrectType() 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, true);
when(addQuery.addQuery(eq(sparql), eq(false), eq(true))).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));
commands.addQuery(true, true);
}
Aggregations