RoleResource { @GET @ApiOperation(value = "Get roles in given workspace", response = RoleDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of RoleDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) public Response getRolesInWorkspace( @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId) throws EntityNotFoundException, UserNotActiveException, WorkspaceNotEnabledException { Role[] roles = roleService.getRoles(workspaceId); List<RoleDTO> rolesDTO = new ArrayList<>(); for (Role role :roles) { rolesDTO.add(mapRoleToDTO(role)); } return Response.ok(new GenericEntity<List<RoleDTO>>((List<RoleDTO>) rolesDTO) { }).build(); } RoleResource(); @PostConstruct void init(); @GET @ApiOperation(value = "Get roles in given workspace", response = RoleDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of RoleDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) Response getRolesInWorkspace(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId); @GET @ApiOperation(value = "Get roles in use in given workspace", response = RoleDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of RoleDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("inuse") @Produces(MediaType.APPLICATION_JSON) Response getRolesInUseInWorkspace(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId); @POST @ApiOperation(value = "Create a new role", response = RoleDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of created RoleDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) Response createRole(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Role to create") RoleDTO roleDTO); @PUT @ApiOperation(value = "Update a role", response = RoleDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of updated RoleDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("{roleName}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) Response updateRole(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Role name") @PathParam("roleName") String roleName,
            @ApiParam(required = true, value = "Role to update") RoleDTO roleDTO); @DELETE @ApiOperation(value = "Delete a role", response = Response.class) @ApiResponses(value = { @ApiResponse(code = 204, message = "Successful deletion of RoleDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("{roleName}") @Produces(MediaType.APPLICATION_JSON) Response deleteRole(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Role name") @PathParam("roleName") String roleName);  }
@Test public void getRolesInWorkspaceTest() throws ApplicationException{ Role role = new Role(); role.setWorkspace(workspace); role.setName("role"); Role[] roles = new Role[]{role}; Mockito.when(roleService.getRoles(workspaceId)) .thenReturn(roles); Response res = roleResource.getRolesInWorkspace(workspaceId); Object entity = res.getEntity(); Assert.assertTrue(entity.getClass().isAssignableFrom(ArrayList.class)); ArrayList result = (ArrayList) entity; Assert.assertEquals(roles.length, result.size()); Object o = result.get(0); Assert.assertTrue(o.getClass().isAssignableFrom(RoleDTO.class)); RoleDTO roleDTO = (RoleDTO) o; Assert.assertEquals(role.getName(), roleDTO.getName()); Assert.assertEquals(role.getWorkspace().getId(), roleDTO.getWorkspaceId()); }