@Test public void changeUserPassword() { final String requestUserId = "USER_TO_CHANGE"; final PasswordChange requestPassword = new PasswordChange(); requestPassword.setCurrentPassword("OLD_PASSWORD"); requestPassword.setNewPassword("NEW_PASSWORD"); requestPassword.setConfirmPassword("NEW_PASSWORD"); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { String argUserId = (String) invocation.getArguments()[0]; PasswordChange argPassword = (PasswordChange) invocation.getArguments()[1]; assertEquals("Service user id should match the requested user id", argUserId, requestUserId); assertEquals("Service password change should match the requested password change", argPassword, requestPassword); return null; } }).when(userServiceMock).updateUserPassword(anyString(), any(PasswordChange.class)); ClientResponse clientResponse = resource().path("/api/users/" + requestUserId + "/password") .accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON) .put(ClientResponse.class, requestPassword); assertEquals("Response HTTP status code should be 200 (OK)", clientResponse.getStatus(), 200); verify(userServiceMock).updateUserPassword(anyString(), any(PasswordChange.class)); }
@PUT @Path("/{userId}/password") @Consumes(MediaType.APPLICATION_JSON) public Response updateUserPassword(@PathParam("userId") String userId, PasswordChange passwordChange) { userService.updateUserPassword(userId, passwordChange); return Response.ok().build(); }
UserResource { @PUT @Path("/{userId}/password") @Consumes(MediaType.APPLICATION_JSON) public Response updateUserPassword(@PathParam("userId") String userId, PasswordChange passwordChange) { userService.updateUserPassword(userId, passwordChange); return Response.ok().build(); } }
UserResource { @PUT @Path("/{userId}/password") @Consumes(MediaType.APPLICATION_JSON) public Response updateUserPassword(@PathParam("userId") String userId, PasswordChange passwordChange) { userService.updateUserPassword(userId, passwordChange); return Response.ok().build(); } @Inject  UserResource(UserService userService); }
UserResource { @PUT @Path("/{userId}/password") @Consumes(MediaType.APPLICATION_JSON) public Response updateUserPassword(@PathParam("userId") String userId, PasswordChange passwordChange) { userService.updateUserPassword(userId, passwordChange); return Response.ok().build(); } @Inject  UserResource(UserService userService); @GET @Produces(MediaType.APPLICATION_JSON) Collection<User> listUsers(); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) User createUser(User user); @GET @Path("/{userId}") @Produces(MediaType.APPLICATION_JSON) User getUser(@PathParam("userId") String userId); @PUT @Path("/{userId}") @Consumes(MediaType.APPLICATION_JSON) Response updateUser(@PathParam("userId") String userId, User user); @DELETE @Path("/{userId}") Response deleteUser(@PathParam("userId") String userId); @PUT @Path("/{userId}/password") @Consumes(MediaType.APPLICATION_JSON) Response updateUserPassword(@PathParam("userId") String userId,
            PasswordChange passwordChange); }
UserResource { @PUT @Path("/{userId}/password") @Consumes(MediaType.APPLICATION_JSON) public Response updateUserPassword(@PathParam("userId") String userId, PasswordChange passwordChange) { userService.updateUserPassword(userId, passwordChange); return Response.ok().build(); } @Inject  UserResource(UserService userService); @GET @Produces(MediaType.APPLICATION_JSON) Collection<User> listUsers(); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) User createUser(User user); @GET @Path("/{userId}") @Produces(MediaType.APPLICATION_JSON) User getUser(@PathParam("userId") String userId); @PUT @Path("/{userId}") @Consumes(MediaType.APPLICATION_JSON) Response updateUser(@PathParam("userId") String userId, User user); @DELETE @Path("/{userId}") Response deleteUser(@PathParam("userId") String userId); @PUT @Path("/{userId}/password") @Consumes(MediaType.APPLICATION_JSON) Response updateUserPassword(@PathParam("userId") String userId,
            PasswordChange passwordChange);  }