Search in sources :

Example 1 with SparqlPrompt

use of org.apache.rya.shell.util.SparqlPrompt in project incubator-rya by apache.

the class RyaAdminCommandsTest method createPCJ.

@Test
public void createPCJ() throws InstanceDoesNotExistException, RyaClientException, IOException {
    // Mock the object that performs the create operation.
    final String instanceName = "unitTest";
    final String sparql = "SELECT * WHERE { ?person <http://isA> ?noun }";
    final String pcjId = "123412342";
    final CreatePCJ mockCreatePCJ = mock(CreatePCJ.class);
    final Set<ExportStrategy> strategies = Sets.newHashSet(ExportStrategy.RYA);
    when(mockCreatePCJ.createPCJ(eq(instanceName), eq(sparql), eq(strategies))).thenReturn(pcjId);
    final RyaClient mockCommands = mock(RyaClient.class);
    when(mockCommands.getCreatePCJ()).thenReturn(mockCreatePCJ);
    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(sparql));
    // Execute the command.
    final RyaAdminCommands commands = new RyaAdminCommands(state, mock(InstallPrompt.class), mockSparqlPrompt, mock(UninstallPrompt.class));
    final String message = commands.createPcj(true, false);
    // Verify the values that were provided to the command were passed through to CreatePCJ.
    verify(mockCreatePCJ).createPCJ(eq(instanceName), eq(sparql), eq(strategies));
    // Verify a message is returned that explains what was created.
    final String expected = "The PCJ has been created. Its ID is '123412342'.";
    assertEquals(expected, message);
}
Also used : ExportStrategy(org.apache.rya.api.client.CreatePCJ.ExportStrategy) AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) SparqlPrompt(org.apache.rya.shell.util.SparqlPrompt) CreatePCJ(org.apache.rya.api.client.CreatePCJ) RyaClient(org.apache.rya.api.client.RyaClient) InstallPrompt(org.apache.rya.shell.util.InstallPrompt) UninstallPrompt(org.apache.rya.shell.util.UninstallPrompt) Test(org.junit.Test)

Example 2 with SparqlPrompt

use of org.apache.rya.shell.util.SparqlPrompt in project incubator-rya by apache.

the class RyaAdminCommandsTest method createPeriodicPCJ.

@Test
public void createPeriodicPCJ() throws InstanceDoesNotExistException, RyaClientException, IOException {
    // Mock the object that performs the create operation.
    final String instanceName = "unitTest";
    final String sparql = "SELECT * WHERE { ?person <http://isA> ?noun }";
    final String topic = "topic";
    final String brokers = "brokers";
    final String pcjId = "12341234";
    final CreatePeriodicPCJ mockCreatePCJ = mock(CreatePeriodicPCJ.class);
    when(mockCreatePCJ.createPeriodicPCJ(eq(instanceName), eq(sparql), eq(topic), eq(brokers))).thenReturn(pcjId);
    final RyaClient mockCommands = mock(RyaClient.class);
    when(mockCommands.getCreatePeriodicPCJ()).thenReturn(java.util.Optional.of(mockCreatePCJ));
    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(sparql));
    // Execute the command.
    final RyaAdminCommands commands = new RyaAdminCommands(state, mock(InstallPrompt.class), mockSparqlPrompt, mock(UninstallPrompt.class));
    final String message = commands.createPeriodicPcj(topic, brokers);
    // Verify the values that were provided to the command were passed through to CreatePCJ.
    verify(mockCreatePCJ).createPeriodicPCJ(eq(instanceName), eq(sparql), eq(topic), eq(brokers));
    // Verify a message is returned that explains what was created.
    final String expected = "The Periodic PCJ has been created. Its ID is '12341234'.";
    assertEquals(expected, message);
}
Also used : AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) SparqlPrompt(org.apache.rya.shell.util.SparqlPrompt) RyaClient(org.apache.rya.api.client.RyaClient) CreatePeriodicPCJ(org.apache.rya.api.client.CreatePeriodicPCJ) InstallPrompt(org.apache.rya.shell.util.InstallPrompt) UninstallPrompt(org.apache.rya.shell.util.UninstallPrompt) Test(org.junit.Test)

Example 3 with SparqlPrompt

use of org.apache.rya.shell.util.SparqlPrompt in project incubator-rya by apache.

the class RyaCommandsTest method testLoadData_specifyInvalidFilenameFormat.

@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);
}
Also used : ConsolePrinter(org.apache.rya.shell.util.ConsolePrinter) LoadStatementsFile(org.apache.rya.api.client.LoadStatementsFile) AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) SparqlPrompt(org.apache.rya.shell.util.SparqlPrompt) RyaClient(org.apache.rya.api.client.RyaClient) Test(org.junit.Test)

Example 4 with SparqlPrompt

use of org.apache.rya.shell.util.SparqlPrompt in project incubator-rya by apache.

the class RyaCommandsTest method testSparqlQuery_fromPrompt.

@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.
}
Also used : ConsolePrinter(org.apache.rya.shell.util.ConsolePrinter) ExecuteSparqlQuery(org.apache.rya.api.client.ExecuteSparqlQuery) AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) SparqlPrompt(org.apache.rya.shell.util.SparqlPrompt) RyaClient(org.apache.rya.api.client.RyaClient) Test(org.junit.Test)

Example 5 with SparqlPrompt

use of org.apache.rya.shell.util.SparqlPrompt in project incubator-rya by apache.

the class RyaCommandsTest method testSparqlQuery_nonexistentFile.

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

Aggregations

RyaClient (org.apache.rya.api.client.RyaClient)17 AccumuloConnectionDetails (org.apache.rya.api.client.accumulo.AccumuloConnectionDetails)17 SparqlPrompt (org.apache.rya.shell.util.SparqlPrompt)17 Test (org.junit.Test)17 ConsolePrinter (org.apache.rya.shell.util.ConsolePrinter)14 LoadStatementsFile (org.apache.rya.api.client.LoadStatementsFile)6 RyaStreamsClient (org.apache.rya.streams.api.RyaStreamsClient)5 AddQuery (org.apache.rya.streams.api.interactor.AddQuery)5 StreamsQuery (org.apache.rya.streams.api.entity.StreamsQuery)4 InstallPrompt (org.apache.rya.shell.util.InstallPrompt)3 UninstallPrompt (org.apache.rya.shell.util.UninstallPrompt)3 ExecuteSparqlQuery (org.apache.rya.api.client.ExecuteSparqlQuery)2 File (java.io.File)1 CreatePCJ (org.apache.rya.api.client.CreatePCJ)1 ExportStrategy (org.apache.rya.api.client.CreatePCJ.ExportStrategy)1 CreatePeriodicPCJ (org.apache.rya.api.client.CreatePeriodicPCJ)1