UserManagementServiceImpl implements UserManagementService { @GET @Path("/checkUser") @Override public Response isUserExists(@QueryParam("username") String userName) { try { UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); if (userStoreManager.isExistingUser(userName)) { return Response.status(Response.Status.OK).entity(true).build(); } else { return Response.status(Response.Status.OK).entity(false).build(); } } catch (UserStoreException e) { String msg = "Error while retrieving the user."; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).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 IsUserExists method of UserManagementService", dependsOnMethods = {"testGetRolesOfUser"}) public void testIsUserExists() { PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserStoreManager")) .toReturn(this.userStoreManager); Response response = userManagementService.isUserExists(TEST2_USERNAME); boolean responseEntity = (boolean) response.getEntity(); Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "Check for existence of user failed"); Assert.assertFalse(responseEntity, "Non-existing user is identified as already existing user"); response = userManagementService.isUserExists(TEST_USERNAME); responseEntity = (boolean) response.getEntity(); Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "Check for existence of user failed"); Assert.assertTrue(responseEntity, "Existing user is identified as non-existing user"); }