UserManagementServiceImpl implements UserManagementService { @GET @Path("/{username}") @Override public Response getUser(@PathParam("username") String username, @QueryParam("domain") String domain, @HeaderParam("If-Modified-Since") String ifModifiedSince) { 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."); } return Response.status(Response.Status.NOT_FOUND).entity( new ErrorResponse.ErrorResponseBuilder().setMessage( "User doesn't exist.").build()).build(); } BasicUserInfo user = this.getBasicUserInfo(username); return Response.status(Response.Status.OK).entity(user).build(); } catch (UserStoreException e) { String msg = "Error occurred while retrieving information of the user '" + 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 getUser method of UserManagementService", dependsOnMethods = "testAddUser") public void testGetUser() throws UserStoreException { PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserStoreManager")) .toReturn(this.userStoreManager); Response response = userManagementService.getUser(TEST_USERNAME, null, null); Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "User retrieval failed"); BasicUserInfo userInfo = (BasicUserInfo) response.getEntity(); Assert.assertEquals(userInfo.getFirstname(), TEST_USERNAME, "Retrieved user object is different from the original one " + "saved"); Mockito.doReturn(false).when(userStoreManager).isExistingUser(TEST2_USERNAME); response = userManagementService.getUser(TEST2_USERNAME, null, null); Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(), "Non-existing user was retrieved successfully"); }