Search in sources :

Example 1 with AddQuery

use of org.apache.rya.streams.api.interactor.AddQuery 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);
}
Also used : RyaStreamsClient(org.apache.rya.streams.api.RyaStreamsClient) ConsolePrinter(org.apache.rya.shell.util.ConsolePrinter) StreamsQuery(org.apache.rya.streams.api.entity.StreamsQuery) SparqlPrompt(org.apache.rya.shell.util.SparqlPrompt) AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) AddQuery(org.apache.rya.streams.api.interactor.AddQuery) RyaClient(org.apache.rya.api.client.RyaClient) Test(org.junit.Test)

Example 2 with AddQuery

use of org.apache.rya.streams.api.interactor.AddQuery 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);
}
Also used : RyaStreamsClient(org.apache.rya.streams.api.RyaStreamsClient) ConsolePrinter(org.apache.rya.shell.util.ConsolePrinter) StreamsQuery(org.apache.rya.streams.api.entity.StreamsQuery) SparqlPrompt(org.apache.rya.shell.util.SparqlPrompt) AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) AddQuery(org.apache.rya.streams.api.interactor.AddQuery) RyaClient(org.apache.rya.api.client.RyaClient) Test(org.junit.Test)

Example 3 with AddQuery

use of org.apache.rya.streams.api.interactor.AddQuery 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);
}
Also used : RyaStreamsClient(org.apache.rya.streams.api.RyaStreamsClient) ConsolePrinter(org.apache.rya.shell.util.ConsolePrinter) SparqlPrompt(org.apache.rya.shell.util.SparqlPrompt) AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) AddQuery(org.apache.rya.streams.api.interactor.AddQuery) RyaClient(org.apache.rya.api.client.RyaClient) Test(org.junit.Test)

Example 4 with AddQuery

use of org.apache.rya.streams.api.interactor.AddQuery 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);
}
Also used : RyaStreamsClient(org.apache.rya.streams.api.RyaStreamsClient) ConsolePrinter(org.apache.rya.shell.util.ConsolePrinter) StreamsQuery(org.apache.rya.streams.api.entity.StreamsQuery) SparqlPrompt(org.apache.rya.shell.util.SparqlPrompt) AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) AddQuery(org.apache.rya.streams.api.interactor.AddQuery) RyaClient(org.apache.rya.api.client.RyaClient) Test(org.junit.Test)

Example 5 with AddQuery

use of org.apache.rya.streams.api.interactor.AddQuery 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);
}
Also used : RyaStreamsClient(org.apache.rya.streams.api.RyaStreamsClient) ConsolePrinter(org.apache.rya.shell.util.ConsolePrinter) StreamsQuery(org.apache.rya.streams.api.entity.StreamsQuery) SparqlPrompt(org.apache.rya.shell.util.SparqlPrompt) AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) AddQuery(org.apache.rya.streams.api.interactor.AddQuery) RyaClient(org.apache.rya.api.client.RyaClient) Test(org.junit.Test)

Aggregations

AddQuery (org.apache.rya.streams.api.interactor.AddQuery)8 Test (org.junit.Test)7 RyaClient (org.apache.rya.api.client.RyaClient)5 AccumuloConnectionDetails (org.apache.rya.api.client.accumulo.AccumuloConnectionDetails)5 ConsolePrinter (org.apache.rya.shell.util.ConsolePrinter)5 SparqlPrompt (org.apache.rya.shell.util.SparqlPrompt)5 RyaStreamsClient (org.apache.rya.streams.api.RyaStreamsClient)5 StreamsQuery (org.apache.rya.streams.api.entity.StreamsQuery)5 QueryRepository (org.apache.rya.streams.api.queries.QueryRepository)3 JCommander (com.beust.jcommander.JCommander)1 ParameterException (com.beust.jcommander.ParameterException)1 Scheduler (com.google.common.util.concurrent.AbstractScheduledService.Scheduler)1 RyaStreamsException (org.apache.rya.streams.api.exception.RyaStreamsException)1 DefaultAddQuery (org.apache.rya.streams.api.interactor.defaults.DefaultAddQuery)1 InMemoryQueryRepository (org.apache.rya.streams.api.queries.InMemoryQueryRepository)1 QueryChangeLog (org.apache.rya.streams.api.queries.QueryChangeLog)1 MalformedQueryException (org.openrdf.query.MalformedQueryException)1