use of org.apache.rya.shell.util.ConsolePrinter 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.
}
use of org.apache.rya.shell.util.ConsolePrinter 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);
}
use of org.apache.rya.shell.util.ConsolePrinter 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."));
}
use of org.apache.rya.shell.util.ConsolePrinter in project incubator-rya by apache.
the class RyaCommandsTest method loadData_relativePath.
@Test
public void loadData_relativePath() throws Exception {
// Mock the object that performs the create operation.
final String instanceName = "unitTest";
final String statementsFile = "~/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
// using a user rooted filename.
String rootedFile = System.getProperty("user.home") + "/statements.nt";
verify(mockLoadStatementsFile).loadStatements(instanceName, Paths.get(rootedFile), 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."));
}
Aggregations