WorkspaceMembershipResource { @GET @ApiOperation(value = "Get workspace's group membership for authenticated user", response = WorkspaceUserGroupMemberShipDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of WorkspaceUserGroupMemberShipDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("usergroups/me") @Produces(MediaType.APPLICATION_JSON) public Response getWorkspaceSpecificUserGroupMemberShips( @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId) throws EntityNotFoundException, UserNotActiveException, WorkspaceNotEnabledException { WorkspaceUserGroupMembership[] workspaceUserGroupMemberships = userManager.getWorkspaceSpecificUserGroupMemberships(workspaceId); List<WorkspaceUserGroupMemberShipDTO> workspaceUserGroupMemberShipDTO = new ArrayList<>(); for (WorkspaceUserGroupMembership workspaceUserGroupMembership : workspaceUserGroupMemberships) { if (workspaceUserGroupMembership != null) { workspaceUserGroupMemberShipDTO.add(mapper.map(workspaceUserGroupMembership, WorkspaceUserGroupMemberShipDTO.class)); } } return Response.ok(new GenericEntity<List<WorkspaceUserGroupMemberShipDTO>>((List<WorkspaceUserGroupMemberShipDTO>) workspaceUserGroupMemberShipDTO) { }).build(); } WorkspaceMembershipResource(); @PostConstruct void init(); @GET @ApiOperation(value = "Get workspace's user memberships", response = WorkspaceUserMemberShipDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of WorkspaceUserMemberShipDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("users") @Produces(MediaType.APPLICATION_JSON) WorkspaceUserMemberShipDTO[] getWorkspaceUserMemberShips(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId); @GET @ApiOperation(value = "Get workspace's user membership for authenticated user", response = WorkspaceUserMemberShipDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of WorkspaceUserMemberShipDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("users/me") @Produces(MediaType.APPLICATION_JSON) WorkspaceUserMemberShipDTO getWorkspaceSpecificUserMemberShips(@ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId); @GET @ApiOperation(value = "Get workspace's group membership for authenticated user", response = WorkspaceUserGroupMemberShipDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of WorkspaceUserGroupMemberShipDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("usergroups") @Produces(MediaType.APPLICATION_JSON) WorkspaceUserGroupMemberShipDTO[] getWorkspaceUserGroupMemberShips(
            @ApiParam(required = true, value = "Workspace id")  @PathParam("workspaceId") String workspaceId); @GET @ApiOperation(value = "Get workspace's group membership for authenticated user", response = WorkspaceUserGroupMemberShipDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of WorkspaceUserGroupMemberShipDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("usergroups/me") @Produces(MediaType.APPLICATION_JSON) Response getWorkspaceSpecificUserGroupMemberShips(
            @ApiParam(required = true, value = "Workspace id")  @PathParam("workspaceId") String workspaceId);  }
@Test public void getWorkspaceSpecificUserGroupMemberShipsTest() throws ApplicationException { WorkspaceUserGroupMembership membership = new WorkspaceUserGroupMembership(workspace, group); WorkspaceUserGroupMembership[] list = new WorkspaceUserGroupMembership[]{membership, null}; Mockito.when(userManager.getWorkspaceSpecificUserGroupMemberships(workspaceId)) .thenReturn(list); Response res = workspaceMembershipResource.getWorkspaceSpecificUserGroupMemberShips(workspaceId); Object entity = res.getEntity(); Assert.assertTrue(entity.getClass().isAssignableFrom(ArrayList.class)); ArrayList resultList = (ArrayList) entity; Assert.assertEquals(1, resultList.size()); Object o = resultList.get(0); Assert.assertNotNull(o); Assert.assertTrue(o.getClass().isAssignableFrom(WorkspaceUserGroupMemberShipDTO.class)); WorkspaceUserGroupMemberShipDTO result = (WorkspaceUserGroupMemberShipDTO) o; Assert.assertEquals(groupId,result.getMemberId()); }