Search in sources :

Example 16 with RyaClient

use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.

the class SharedShellStateTest method ConnectedToInstanceAgain.

@Test
public void ConnectedToInstanceAgain() {
    final SharedShellState state = new SharedShellState();
    // Connect to Accumulo.
    final AccumuloConnectionDetails connectionDetails = mock(AccumuloConnectionDetails.class);
    final RyaClient connectedCommands = mock(RyaClient.class);
    state.connectedToAccumulo(connectionDetails, connectedCommands);
    // Connect to an Instance.
    state.connectedToInstance("instance");
    // Connect to another instance.
    state.connectedToInstance("secondInstance");
    // Verify the state.
    final ShellState expected = ShellState.builder().setConnectionState(ConnectionState.CONNECTED_TO_INSTANCE).setAccumuloDetails(connectionDetails).setConnectedCommands(connectedCommands).setRyaInstanceName("secondInstance").build();
    assertEquals(expected, state.getShellState());
}
Also used : AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) ShellState(org.apache.rya.shell.SharedShellState.ShellState) RyaClient(org.apache.rya.api.client.RyaClient) Test(org.junit.Test)

Example 17 with RyaClient

use of org.apache.rya.api.client.RyaClient 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 18 with RyaClient

use of org.apache.rya.api.client.RyaClient 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 19 with RyaClient

use of org.apache.rya.api.client.RyaClient 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)

Example 20 with RyaClient

use of org.apache.rya.api.client.RyaClient 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.
}
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) File(java.io.File) LoadStatementsFile(org.apache.rya.api.client.LoadStatementsFile) Test(org.junit.Test)

Aggregations

RyaClient (org.apache.rya.api.client.RyaClient)105 Test (org.junit.Test)76 AccumuloConnectionDetails (org.apache.rya.api.client.accumulo.AccumuloConnectionDetails)41 SparqlPrompt (org.apache.rya.shell.util.SparqlPrompt)29 InstallConfiguration (org.apache.rya.api.client.Install.InstallConfiguration)26 CliCommand (org.springframework.shell.core.annotation.CliCommand)20 RyaClientException (org.apache.rya.api.client.RyaClientException)18 Install (org.apache.rya.api.client.Install)17 ShellState (org.apache.rya.shell.SharedShellState.ShellState)16 InstallPrompt (org.apache.rya.shell.util.InstallPrompt)16 UninstallPrompt (org.apache.rya.shell.util.UninstallPrompt)16 RyaDetails (org.apache.rya.api.instance.RyaDetails)14 ConsolePrinter (org.apache.rya.shell.util.ConsolePrinter)13 IOException (java.io.IOException)11 InstanceDoesNotExistException (org.apache.rya.api.client.InstanceDoesNotExistException)9 Sail (org.openrdf.sail.Sail)9 ValueFactory (org.openrdf.model.ValueFactory)8 HashSet (java.util.HashSet)7 Connector (org.apache.accumulo.core.client.Connector)7 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)7