@Test public void testRemoveRole(){ final RepositoryHandler repositoryHandler = mock(RepositoryHandler.class); final RemoveRoleTask task = new RemoveRoleTask(repositoryHandler); final ImmutableMultimap.Builder<String, String> builder = new ImmutableMultimap.Builder<String, String>(); builder.put(ServerAPI.USER_PARAM, "user"); builder.put(ServerAPI.USER_ROLE_PARAM, "data_updater"); Exception exception = null; try { task.execute(builder.build(), mock(PrintWriter.class)); } catch (Exception e) { exception = e; } assertNull(exception); verify(repositoryHandler, times(1)).removeUserRole("user", AvailableRoles.DATA_UPDATER); }
@Override public void execute(final ImmutableMultimap<String, String> args, final PrintWriter printer) throws AuthenticationException, UnknownHostException { printer.println("Removing role..."); final String user = args.get(ServerAPI.USER_PARAM).asList().get(0); final String roleParam = args.get(ServerAPI.USER_ROLE_PARAM).asList().get(0); final AvailableRoles role = DbCredential.getRole(roleParam); if(user == null || role == null){ printer.println("ERROR: Bad request! The provided credential are unhealthy or incomplete."); return; } repoHandler.removeUserRole(user, role); printer.println("Task performed successfully."); }
RemoveRoleTask extends Task { @Override public void execute(final ImmutableMultimap<String, String> args, final PrintWriter printer) throws AuthenticationException, UnknownHostException { printer.println("Removing role..."); final String user = args.get(ServerAPI.USER_PARAM).asList().get(0); final String roleParam = args.get(ServerAPI.USER_ROLE_PARAM).asList().get(0); final AvailableRoles role = DbCredential.getRole(roleParam); if(user == null || role == null){ printer.println("ERROR: Bad request! The provided credential are unhealthy or incomplete."); return; } repoHandler.removeUserRole(user, role); printer.println("Task performed successfully."); } }
RemoveRoleTask extends Task { @Override public void execute(final ImmutableMultimap<String, String> args, final PrintWriter printer) throws AuthenticationException, UnknownHostException { printer.println("Removing role..."); final String user = args.get(ServerAPI.USER_PARAM).asList().get(0); final String roleParam = args.get(ServerAPI.USER_ROLE_PARAM).asList().get(0); final AvailableRoles role = DbCredential.getRole(roleParam); if(user == null || role == null){ printer.println("ERROR: Bad request! The provided credential are unhealthy or incomplete."); return; } repoHandler.removeUserRole(user, role); printer.println("Task performed successfully."); } RemoveRoleTask(final RepositoryHandler repoHandler); }
RemoveRoleTask extends Task { @Override public void execute(final ImmutableMultimap<String, String> args, final PrintWriter printer) throws AuthenticationException, UnknownHostException { printer.println("Removing role..."); final String user = args.get(ServerAPI.USER_PARAM).asList().get(0); final String roleParam = args.get(ServerAPI.USER_ROLE_PARAM).asList().get(0); final AvailableRoles role = DbCredential.getRole(roleParam); if(user == null || role == null){ printer.println("ERROR: Bad request! The provided credential are unhealthy or incomplete."); return; } repoHandler.removeUserRole(user, role); printer.println("Task performed successfully."); } RemoveRoleTask(final RepositoryHandler repoHandler); @Override void execute(final ImmutableMultimap<String, String> args, final PrintWriter printer); }
RemoveRoleTask extends Task { @Override public void execute(final ImmutableMultimap<String, String> args, final PrintWriter printer) throws AuthenticationException, UnknownHostException { printer.println("Removing role..."); final String user = args.get(ServerAPI.USER_PARAM).asList().get(0); final String roleParam = args.get(ServerAPI.USER_ROLE_PARAM).asList().get(0); final AvailableRoles role = DbCredential.getRole(roleParam); if(user == null || role == null){ printer.println("ERROR: Bad request! The provided credential are unhealthy or incomplete."); return; } repoHandler.removeUserRole(user, role); printer.println("Task performed successfully."); } RemoveRoleTask(final RepositoryHandler repoHandler); @Override void execute(final ImmutableMultimap<String, String> args, final PrintWriter printer);  }