@Test public void updateRole() { final Role requestRole = new Role(); requestRole.setId("role-1"); requestRole.setName("Role 1"); requestRole.setPermissions(Sets.newHashSet("test:create", "test:updated", "test:delete")); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { String argRoleId = (String) invocation.getArguments()[0]; Role argRole = (Role) invocation.getArguments()[1]; assertEquals("Service role ID should match the requested role ID", argRoleId, requestRole.getId()); assertEquals("Service role should match the requested role", argRole, requestRole); return null; } }).when(roleServiceMock).updateRole(anyString(), any(Role.class)); ClientResponse clientResponse = resource().path("/api/roles/" + requestRole.getId()) .accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON) .put(ClientResponse.class, requestRole); assertEquals("Response HTTP status code should be 200 (OK)", clientResponse.getStatus(), 200); verify(roleServiceMock).updateRole(anyString(), any(Role.class)); }
@PUT @Path("/{roleId}") @Consumes(MediaType.APPLICATION_JSON) public Response updateRole(@PathParam("roleId") String roleId, Role role) { roleService.updateRole(roleId, role); return Response.ok().build(); }
RoleResource { @PUT @Path("/{roleId}") @Consumes(MediaType.APPLICATION_JSON) public Response updateRole(@PathParam("roleId") String roleId, Role role) { roleService.updateRole(roleId, role); return Response.ok().build(); } }
RoleResource { @PUT @Path("/{roleId}") @Consumes(MediaType.APPLICATION_JSON) public Response updateRole(@PathParam("roleId") String roleId, Role role) { roleService.updateRole(roleId, role); return Response.ok().build(); } @Inject  RoleResource(RoleService roleService); }
RoleResource { @PUT @Path("/{roleId}") @Consumes(MediaType.APPLICATION_JSON) public Response updateRole(@PathParam("roleId") String roleId, Role role) { roleService.updateRole(roleId, role); return Response.ok().build(); } @Inject  RoleResource(RoleService roleService); @GET @Produces(MediaType.APPLICATION_JSON) Collection<Role> listRoles(); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Role createRole(Role role); @GET @Path("/{roleId}") @Produces(MediaType.APPLICATION_JSON) Role getRole(@PathParam("roleId") String roleId); @PUT @Path("/{roleId}") @Consumes(MediaType.APPLICATION_JSON) Response updateRole(@PathParam("roleId") String roleId, Role role); @DELETE @Path("/{roleId}") Response deleteRole(@PathParam("roleId") String roleId); }
RoleResource { @PUT @Path("/{roleId}") @Consumes(MediaType.APPLICATION_JSON) public Response updateRole(@PathParam("roleId") String roleId, Role role) { roleService.updateRole(roleId, role); return Response.ok().build(); } @Inject  RoleResource(RoleService roleService); @GET @Produces(MediaType.APPLICATION_JSON) Collection<Role> listRoles(); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Role createRole(Role role); @GET @Path("/{roleId}") @Produces(MediaType.APPLICATION_JSON) Role getRole(@PathParam("roleId") String roleId); @PUT @Path("/{roleId}") @Consumes(MediaType.APPLICATION_JSON) Response updateRole(@PathParam("roleId") String roleId, Role role); @DELETE @Path("/{roleId}") Response deleteRole(@PathParam("roleId") String roleId);  }