UserManagementServiceImpl implements UserManagementService { @DELETE @Path("/{username}") @Override public Response removeUser(@PathParam("username") String username, @QueryParam("domain") String domain) { if (domain != null && !domain.isEmpty()) { username = domain + '/' + username; } try { UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); if (!userStoreManager.isExistingUser(username)) { if (log.isDebugEnabled()) { log.debug("User by username: " + username + " does not exist for removal."); } return Response.status(Response.Status.NOT_FOUND).entity( new ErrorResponse.ErrorResponseBuilder().setMessage("User '" + username + "' does not exist for removal.").build()).build(); } DeviceManagementProviderService deviceManagementService = DeviceMgtAPIUtils.getDeviceManagementService(); deviceManagementService.setStatus(username, EnrolmentInfo.Status.REMOVED); userStoreManager.deleteUser(username); if (log.isDebugEnabled()) { log.debug("User '" + username + "' was successfully removed."); } return Response.status(Response.Status.OK).build(); } catch (DeviceManagementException | UserStoreException e) { String msg = "Exception in trying to remove user by username: " + username; log.error(msg, e); return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); } }  @POST @Override Response addUser(UserInfo userInfo); @GET @Path("/{username}") @Override Response getUser(@PathParam("username") String username, @QueryParam("domain") String domain,
                            @HeaderParam("If-Modified-Since") String ifModifiedSince); @PUT @Path("/{username}") @Override Response updateUser(@PathParam("username") String username, @QueryParam("domain") String domain, UserInfo userInfo); @DELETE @Path("/{username}") @Override Response removeUser(@PathParam("username") String username, @QueryParam("domain") String domain); @GET @Path("/{username}/roles") @Override Response getRolesOfUser(@PathParam("username") String username, @QueryParam("domain") String domain); @GET @Override Response getUsers(@QueryParam("filter") String filter, @HeaderParam("If-Modified-Since") String timestamp,
                             @QueryParam("offset") int offset,
                             @QueryParam("limit") int limit); @GET @Path("/count") @Override Response getUserCount(); @GET @Path("/checkUser") @Override Response isUserExists(@QueryParam("username") String userName); @GET @Path("/search/usernames") @Override Response getUserNames(@QueryParam("filter") String filter, @QueryParam("domain") String domain,
                                 @HeaderParam("If-Modified-Since") String timestamp,
                                 @QueryParam("offset") int offset, @QueryParam("limit") int limit); @PUT @Path("/credentials") @Override Response resetPassword(OldPasswordResetWrapper credentials); @POST @Path("/send-invitation") @Produces({MediaType.APPLICATION_JSON}) Response inviteExistingUsersToEnrollDevice(List<String> usernames); @POST @Path("/enrollment-invite") @Override Response inviteToEnrollDevice(EnrollmentInvitation enrollmentInvitation);  }
@Test(description = "This method tests the removeUser method of UserManagementService", dependsOnMethods = "testInviteToEnrollDevice") public void testRemoveUser() throws DeviceManagementException, UserStoreException { PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserStoreManager")) .toReturn(this.userStoreManager); PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService")) .toReturn(this.deviceManagementProviderService); Mockito.doReturn(true).when(deviceManagementProviderService).setStatus(Mockito.anyString(), Mockito.any()); Mockito.doNothing().when(userStoreManager).deleteUser(Mockito.anyString()); Response response = userManagementService.removeUser(TEST_USERNAME, null); Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "Cannot remove user, the request failed"); response = userManagementService.removeUser(TEST2_USERNAME, null); Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(), "Successfully removed non-existing user"); }