Search in sources :

Example 1 with LoadStatementsFile

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

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

Example 3 with LoadStatementsFile

use of org.apache.rya.api.client.LoadStatementsFile 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."));
}
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 LoadStatementsFile

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

the class RyaCommandsTest method testLoadData_specifyInvalidFormat.

@Test(expected = RuntimeException.class)
public void testLoadData_specifyInvalidFormat() 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 = "INVALID_FORMAT_NAME";
    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 5 with LoadStatementsFile

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

the class RyaCommandsTest method testLoadData.

@Test
public void testLoadData() 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 = 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);
    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."));
}
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)

Aggregations

LoadStatementsFile (org.apache.rya.api.client.LoadStatementsFile)6 RyaClient (org.apache.rya.api.client.RyaClient)6 AccumuloConnectionDetails (org.apache.rya.api.client.accumulo.AccumuloConnectionDetails)6 ConsolePrinter (org.apache.rya.shell.util.ConsolePrinter)6 SparqlPrompt (org.apache.rya.shell.util.SparqlPrompt)6 Test (org.junit.Test)6 File (java.io.File)1 ExecuteSparqlQuery (org.apache.rya.api.client.ExecuteSparqlQuery)1