Search in sources :

Example 1 with Shell

use of org.apache.accumulo.shell.Shell in project accumulo by apache.

the class ListTabletsCommandTest method mockTest.

@Test
public void mockTest() throws Exception {
    ListTabletsCommand cmd = new TestListTabletsCommand();
    AccumuloClient client = EasyMock.createMock(AccumuloClient.class);
    ClientContext context = EasyMock.createMock(ClientContext.class);
    TableOperations tableOps = EasyMock.createMock(TableOperations.class);
    InstanceOperations instOps = EasyMock.createMock(InstanceOperations.class);
    Shell shellState = EasyMock.createMock(Shell.class);
    Options opts = cmd.getOptions();
    CommandLineParser parser = new DefaultParser();
    String[] args = { "-t", tableName };
    CommandLine cli = parser.parse(opts, args);
    EasyMock.expect(shellState.getAccumuloClient()).andReturn(client).anyTimes();
    EasyMock.expect(shellState.getContext()).andReturn(context).anyTimes();
    EasyMock.expect(client.tableOperations()).andReturn(tableOps).anyTimes();
    Map<String, String> idMap = new TreeMap<>();
    idMap.put(tableName, tableId.canonical());
    EasyMock.expect(tableOps.tableIdMap()).andReturn(idMap);
    assertEquals("Incorrect number of rows: " + rows, rows.size(), 3);
    EasyMock.replay(client, context, tableOps, instOps, shellState);
    cmd.execute("listTablets -t " + tableName, cli, shellState);
    EasyMock.verify(client, context, tableOps, instOps, shellState);
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) Options(org.apache.commons.cli.Options) ClientContext(org.apache.accumulo.core.clientImpl.ClientContext) TreeMap(java.util.TreeMap) Shell(org.apache.accumulo.shell.Shell) CommandLine(org.apache.commons.cli.CommandLine) TableOperations(org.apache.accumulo.core.client.admin.TableOperations) CommandLineParser(org.apache.commons.cli.CommandLineParser) InstanceOperations(org.apache.accumulo.core.client.admin.InstanceOperations) DefaultParser(org.apache.commons.cli.DefaultParser) Test(org.junit.Test)

Example 2 with Shell

use of org.apache.accumulo.shell.Shell in project accumulo by apache.

the class DeleteAuthsCommandTest method deleteNonExistingAuth.

@Test
public void deleteNonExistingAuth() throws Exception {
    AccumuloClient client = EasyMock.createMock(AccumuloClient.class);
    CommandLine cli = EasyMock.createMock(CommandLine.class);
    Shell shellState = EasyMock.createMock(Shell.class);
    LineReader reader = EasyMock.createMock(LineReader.class);
    SecurityOperations secOps = EasyMock.createMock(SecurityOperations.class);
    EasyMock.expect(shellState.getAccumuloClient()).andReturn(client);
    // We're the root user
    EasyMock.expect(client.whoami()).andReturn("root");
    EasyMock.expect(cli.getOptionValue("u", "root")).andReturn("foo");
    EasyMock.expect(cli.getOptionValue("s")).andReturn("def");
    EasyMock.expect(client.securityOperations()).andReturn(secOps);
    EasyMock.expect(client.securityOperations()).andReturn(secOps);
    EasyMock.expect(secOps.getUserAuthorizations("foo")).andReturn(new Authorizations("abc", "123"));
    secOps.changeUserAuthorizations("foo", new Authorizations("abc", "123"));
    EasyMock.expectLastCall();
    EasyMock.replay(client, cli, shellState, reader, secOps);
    cmd.execute("deleteauths -u foo -s def", cli, shellState);
    EasyMock.verify(client, cli, shellState, reader, secOps);
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) CommandLine(org.apache.commons.cli.CommandLine) Shell(org.apache.accumulo.shell.Shell) Authorizations(org.apache.accumulo.core.security.Authorizations) LineReader(org.jline.reader.LineReader) SecurityOperations(org.apache.accumulo.core.client.admin.SecurityOperations) Test(org.junit.Test)

Example 3 with Shell

use of org.apache.accumulo.shell.Shell in project accumulo by apache.

the class DeleteAuthsCommandTest method deleteAllAuth.

@Test
public void deleteAllAuth() throws Exception {
    AccumuloClient client = EasyMock.createMock(AccumuloClient.class);
    CommandLine cli = EasyMock.createMock(CommandLine.class);
    Shell shellState = EasyMock.createMock(Shell.class);
    LineReader reader = EasyMock.createMock(LineReader.class);
    SecurityOperations secOps = EasyMock.createMock(SecurityOperations.class);
    EasyMock.expect(shellState.getAccumuloClient()).andReturn(client);
    // We're the root user
    EasyMock.expect(client.whoami()).andReturn("root");
    EasyMock.expect(cli.getOptionValue("u", "root")).andReturn("foo");
    EasyMock.expect(cli.getOptionValue("s")).andReturn("abc,123");
    EasyMock.expect(client.securityOperations()).andReturn(secOps);
    EasyMock.expect(client.securityOperations()).andReturn(secOps);
    EasyMock.expect(secOps.getUserAuthorizations("foo")).andReturn(new Authorizations("abc", "123"));
    secOps.changeUserAuthorizations("foo", new Authorizations());
    EasyMock.expectLastCall();
    EasyMock.replay(client, cli, shellState, reader, secOps);
    cmd.execute("deleteauths -u foo -s abc,123", cli, shellState);
    EasyMock.verify(client, cli, shellState, reader, secOps);
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) CommandLine(org.apache.commons.cli.CommandLine) Shell(org.apache.accumulo.shell.Shell) Authorizations(org.apache.accumulo.core.security.Authorizations) LineReader(org.jline.reader.LineReader) SecurityOperations(org.apache.accumulo.core.client.admin.SecurityOperations) Test(org.junit.Test)

Example 4 with Shell

use of org.apache.accumulo.shell.Shell in project accumulo by apache.

the class DeleteAuthsCommandTest method deleteExistingAuth.

@Test
public void deleteExistingAuth() throws Exception {
    AccumuloClient client = EasyMock.createMock(AccumuloClient.class);
    CommandLine cli = EasyMock.createMock(CommandLine.class);
    Shell shellState = EasyMock.createMock(Shell.class);
    LineReader reader = EasyMock.createMock(LineReader.class);
    SecurityOperations secOps = EasyMock.createMock(SecurityOperations.class);
    EasyMock.expect(shellState.getAccumuloClient()).andReturn(client);
    // We're the root user
    EasyMock.expect(client.whoami()).andReturn("root");
    EasyMock.expect(cli.getOptionValue("u", "root")).andReturn("foo");
    EasyMock.expect(cli.getOptionValue("s")).andReturn("abc");
    EasyMock.expect(client.securityOperations()).andReturn(secOps);
    EasyMock.expect(client.securityOperations()).andReturn(secOps);
    EasyMock.expect(secOps.getUserAuthorizations("foo")).andReturn(new Authorizations("abc", "123"));
    secOps.changeUserAuthorizations("foo", new Authorizations("123"));
    EasyMock.expectLastCall();
    EasyMock.replay(client, cli, shellState, reader, secOps);
    cmd.execute("deleteauths -u foo -s abc", cli, shellState);
    EasyMock.verify(client, cli, shellState, reader, secOps);
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) CommandLine(org.apache.commons.cli.CommandLine) Shell(org.apache.accumulo.shell.Shell) Authorizations(org.apache.accumulo.core.security.Authorizations) LineReader(org.jline.reader.LineReader) SecurityOperations(org.apache.accumulo.core.client.admin.SecurityOperations) Test(org.junit.Test)

Example 5 with Shell

use of org.apache.accumulo.shell.Shell in project accumulo by apache.

the class DropUserCommandTest method dropUserWithoutForcePrompts.

@Test
public void dropUserWithoutForcePrompts() throws Exception {
    AccumuloClient client = EasyMock.createMock(AccumuloClient.class);
    CommandLine cli = EasyMock.createMock(CommandLine.class);
    Shell shellState = EasyMock.createMock(Shell.class);
    LineReader reader = EasyMock.createMock(LineReader.class);
    PrintWriter pw = EasyMock.createMock(PrintWriter.class);
    SecurityOperations secOps = EasyMock.createMock(SecurityOperations.class);
    EasyMock.expect(shellState.getAccumuloClient()).andReturn(client);
    // The user we want to remove
    EasyMock.expect(cli.getArgs()).andReturn(new String[] { "user" });
    // We're the root user
    EasyMock.expect(client.whoami()).andReturn("root");
    // Force option was not provided
    EasyMock.expect(cli.hasOption("f")).andReturn(false);
    EasyMock.expect(shellState.getReader()).andReturn(reader);
    EasyMock.expect(shellState.getWriter()).andReturn(pw);
    pw.flush();
    EasyMock.expectLastCall().once();
    // Fake a "yes" response
    EasyMock.expect(reader.readLine(EasyMock.anyObject(String.class))).andReturn("yes");
    EasyMock.expect(shellState.getAccumuloClient()).andReturn(client);
    EasyMock.expect(client.securityOperations()).andReturn(secOps);
    secOps.dropLocalUser("user");
    EasyMock.expectLastCall();
    EasyMock.replay(client, cli, shellState, reader, secOps);
    cmd.execute("dropuser foo -f", cli, shellState);
    EasyMock.verify(client, cli, shellState, reader, secOps);
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) CommandLine(org.apache.commons.cli.CommandLine) Shell(org.apache.accumulo.shell.Shell) LineReader(org.jline.reader.LineReader) SecurityOperations(org.apache.accumulo.core.client.admin.SecurityOperations) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

Shell (org.apache.accumulo.shell.Shell)8 CommandLine (org.apache.commons.cli.CommandLine)7 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)6 Test (org.junit.Test)6 LineReader (org.jline.reader.LineReader)5 SecurityOperations (org.apache.accumulo.core.client.admin.SecurityOperations)4 Authorizations (org.apache.accumulo.core.security.Authorizations)3 PrintWriter (java.io.PrintWriter)2 TableOperations (org.apache.accumulo.core.client.admin.TableOperations)2 Before (org.junit.Before)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 TreeMap (java.util.TreeMap)1 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)1 InstanceOperations (org.apache.accumulo.core.client.admin.InstanceOperations)1 ClientContext (org.apache.accumulo.core.clientImpl.ClientContext)1 SortedKeyValueIterator (org.apache.accumulo.core.iterators.SortedKeyValueIterator)1 CommandLineParser (org.apache.commons.cli.CommandLineParser)1 DefaultParser (org.apache.commons.cli.DefaultParser)1 Options (org.apache.commons.cli.Options)1