use of org.apache.rya.api.client.RyaClient 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.api.client.RyaClient 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.api.client.RyaClient 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."));
}
use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.
the class RyaStreamsCommandsTest method printRyaStreamsDetails_configured.
@Test
public void printRyaStreamsDetails_configured() throws Exception {
// Mock the object that performs the configure operation.
final RyaClient mockCommands = mock(RyaClient.class);
final GetInstanceDetails getDetails = mock(GetInstanceDetails.class);
when(mockCommands.getGetInstanceDetails()).thenReturn(getDetails);
// When getting the instance details, ensure they do have RyaStreamsDetails to print.
final RyaDetails details = mock(RyaDetails.class);
when(details.getRyaStreamsDetails()).thenReturn(Optional.of(new RyaStreamsDetails("localhost", 6)));
when(getDetails.getDetails(eq("unitTest"))).thenReturn(Optional.of(details));
// Mock a shell state and connect it to a Rya instance.
final SharedShellState state = new SharedShellState();
state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), mockCommands);
state.connectedToInstance("unitTest");
// Execute the command.
final RyaStreamsCommands commands = new RyaStreamsCommands(state, mock(SparqlPrompt.class), mock(ConsolePrinter.class));
final String message = commands.printRyaStreamsDetails();
final String expected = "Kafka Hostname: localhost, Kafka Port: 6";
assertEquals(expected, message);
}
use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.
the class RyaAdminCommands method removeUser.
@CliCommand(value = REMOVE_USER_CMD, help = "Removes an authorized user from the Rya instance.")
public void removeUser(@CliOption(key = { "username" }, mandatory = true, help = "The username of the user whose access will be revoked.") final String username) {
// Fetch the Rya client that is connected to the store.
final ShellState shellState = state.getShellState();
final RyaClient ryaClient = shellState.getConnectedCommands().get();
final String ryaInstance = shellState.getRyaInstanceName().get();
try {
ryaClient.getRemoveUser().get().removeUser(ryaInstance, username);
} catch (final InstanceDoesNotExistException e) {
throw new RuntimeException(String.format("A Rya instance named '%s' does not exist.", ryaInstance), e);
} catch (final RyaClientException e) {
throw new RuntimeException("The user's access could not be revoked. Provided reason: " + e.getMessage(), e);
}
}
Aggregations