use of org.apache.rya.shell.util.SparqlPrompt in project incubator-rya by apache.
the class RyaCommandsTest method testSparqlQuery.
@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.
}
use of org.apache.rya.shell.util.SparqlPrompt in project incubator-rya by apache.
the class RyaStreamsCommandsTest method addQuery_insertConstructQuery.
@Test
public void addQuery_insertConstructQuery() 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 = "PREFIX vCard: <http://www.w3.org/2001/vcard-rdf/3.0#> " + "PREFIX foaf: <http://xmlns.com/foaf/0.1/> " + "CONSTRUCT { " + "?X vCard:FN ?name . " + "?X vCard:URL ?url . " + "?X vCard:TITLE ?title . " + "} " + "FROM <http://www.w3.org/People/Berners-Lee/card> " + "WHERE { " + "OPTIONAL { ?X foaf:name ?name . FILTER isLiteral(?name) . } " + "OPTIONAL { ?X foaf:homepage ?url . FILTER isURI(?url) . } " + "OPTIONAL { ?X foaf:title ?title . FILTER isLiteral(?title) . } " + "}";
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));
final String message = commands.addQuery(true, true);
// Verify the interactor was invoked with the provided input.
verify(addQuery).addQuery(sparql, false, true);
// 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.shell.util.SparqlPrompt in project incubator-rya by apache.
the class RyaStreamsCommandsTest method addQuery_doNotInsertInsertUpdate.
@Test
public void addQuery_doNotInsertInsertUpdate() 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 = "PREFIX Sensor: <http://example.com/Equipment.owl#> " + "INSERT { " + "?subject Sensor:test2 ?newValue " + "} WHERE {" + "values (?oldValue ?newValue) {" + "('testValue1' 'newValue1')" + "('testValue2' 'newValue2')" + "}" + "?subject Sensor:test1 ?oldValue" + "}";
final StreamsQuery addedQuery = new StreamsQuery(UUID.randomUUID(), sparql, true, false);
when(addQuery.addQuery(eq(sparql), eq(false), 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(true, false);
// Verify the interactor was invoked with the provided input.
verify(addQuery).addQuery(sparql, false, 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.shell.util.SparqlPrompt in project incubator-rya by apache.
the class RyaCommandsTest method testLoadData_specifyFormat.
@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."));
}
use of org.apache.rya.shell.util.SparqlPrompt in project incubator-rya by apache.
the class RyaCommandsTest method testSparqlQuery_fromPrompt_cancelled.
@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.
}
Aggregations