@Test public void listRoles() { Role role1 = new Role(); role1.setId("role-1"); role1.setName("Role 1"); role1.setPermissions(Sets.newHashSet("test:create", "test:updated", "test:delete")); Role role2 = new Role(); role2.setId("role-2"); role2.setName("Role 2"); role2.setPermissions(Sets.newHashSet("test:read", "test:query", "test:create")); List<Role> mockedRoles = new ArrayList<Role>(); mockedRoles.add(role1); mockedRoles.add(role2); when(roleServiceMock.listRoles()).thenReturn(mockedRoles); List<Role> responseRoles = resource().path("/api/roles") .accept(MediaType.APPLICATION_JSON).get(new GenericType<List<Role>>(){}); assertEquals("Response roles should be equal to the mocked roles", mockedRoles, responseRoles); verify(roleServiceMock).listRoles(); }
@GET @Produces(MediaType.APPLICATION_JSON) public Collection<Role> listRoles() { return roleService.listRoles(); }
RoleResource { @GET @Produces(MediaType.APPLICATION_JSON) public Collection<Role> listRoles() { return roleService.listRoles(); } }
RoleResource { @GET @Produces(MediaType.APPLICATION_JSON) public Collection<Role> listRoles() { return roleService.listRoles(); } @Inject  RoleResource(RoleService roleService); }
RoleResource { @GET @Produces(MediaType.APPLICATION_JSON) public Collection<Role> listRoles() { return roleService.listRoles(); } @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 { @GET @Produces(MediaType.APPLICATION_JSON) public Collection<Role> listRoles() { return roleService.listRoles(); } @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);  }