WorkspaceResource { @PUT @ApiOperation(value = "Set user access in workspace", response = UserDTO.class, authorizations = {@Authorization(value = "authorization")}) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of updated UserDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("/{workspaceId}/user-access") @Produces(MediaType.APPLICATION_JSON) public Response setUserAccess( @ApiParam(value = "Workspace id", required = true) @PathParam("workspaceId") String workspaceId, @ApiParam(value = "User to grant access in workspace", required = true) UserDTO userDTO) throws AccessRightException, EntityNotFoundException { if (userDTO.getMembership() == null) { return Response.status(Response.Status.BAD_REQUEST).build(); } WorkspaceUserMembership workspaceUserMembership = userManager.grantUserAccess(workspaceId, userDTO.getLogin(), userDTO.getMembership() == WorkspaceMembership.READ_ONLY); if(workspaceUserMembership == null) { return Response.status(Response.Status.BAD_REQUEST).build(); } return Response.ok(mapper.map(workspaceUserMembership.getMember(), UserDTO.class)).build(); } WorkspaceResource(); @PostConstruct void init(); @GET @ApiOperation(value = "Get workspace list for authenticated user", response = WorkspaceListDTO.class, authorizations = {@Authorization(value = "authorization")}) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of WorkspaceListDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) WorkspaceListDTO getWorkspacesForConnectedUser(); @GET @ApiOperation(value = "Get detailed workspace list for authenticated user", response = WorkspaceDetailsDTO.class, responseContainer = "List", authorizations = {@Authorization(value = "authorization")}) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of WorkspaceDetailsDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("/more") @Produces(MediaType.APPLICATION_JSON) Response getDetailedWorkspacesForConnectedUser(); @GET @ApiOperation(value = "Get online users visible by authenticated user", response = UserDTO.class, responseContainer = "List", authorizations = {@Authorization(value = "authorization")}) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of UserDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("reachable-users") @Produces(MediaType.APPLICATION_JSON) UserDTO[] getReachableUsersForCaller(); @PUT @ApiOperation(value = "Update a workspace", response = WorkspaceDTO.class, authorizations = {@Authorization(value = "authorization")}) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of updated WorkspaceDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("/{workspaceId}") @Produces(MediaType.APPLICATION_JSON) Response updateWorkspace(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Workspace values to update") WorkspaceDTO workspaceDTO); @PUT @Path("/{workspaceId}/index") @ApiOperation(value = "Re-Index a workspace", response = Response.class, authorizations = {@Authorization(value = "authorization")}) @ApiResponses(value = { @ApiResponse(code = 202, message = "Accepted indexation (asynchronous method)"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) Response synchronizeIndexer(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId); @DELETE @ApiOperation(value = "Delete a workspace", response = Response.class, authorizations = {@Authorization(value = "authorization")}) @ApiResponses(value = { @ApiResponse(code = 202, message = "Accepted deletion (asynchronous method)"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("/{workspaceId}") @Produces(MediaType.APPLICATION_JSON) Response deleteWorkspace(@ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId); @GET @ApiOperation(value = "Get user groups in given workspace", response = UserGroupDTO.class, responseContainer = "List", authorizations = {@Authorization(value = "authorization")}) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of UserGroupDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("/{workspaceId}/user-group") @Produces(MediaType.APPLICATION_JSON) UserGroupDTO[] getUserGroups(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId); @POST @ApiOperation(value = "Create a new user group", response = UserGroupDTO.class, authorizations = {@Authorization(value = "authorization")}) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of created UserGroupDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("/{workspaceId}/user-group") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) UserGroupDTO createGroup(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "UserGroup to create") UserGroupDTO userGroupDTO); @DELETE @ApiOperation(value = "Remove a user group", response = UserGroupDTO.class, authorizations = {@Authorization(value = "authorization")}) @ApiResponses(value = { @ApiResponse(code = 204, message = "Successful removal of user from UserGroupDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("/{workspaceId}/user-group/{groupId}") @Produces(MediaType.APPLICATION_JSON) Response removeGroup(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Group id") @PathParam("groupId") String groupId); @PUT @ApiOperation(value = "Add a user to workspace", response = Response.class, authorizations = {@Authorization(value = "authorization")}) @ApiResponses(value = { @ApiResponse(code = 204, message = "Successful addition of user in UserGroupDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("/{workspaceId}/add-user") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) Response addUser(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = false, value = "Group id") @QueryParam("group") String groupId,
            @ApiParam(required = true, value = "User to add") UserDTO userDTO); @PUT @ApiOperation(value = "Set a new admin for given workspace", response = WorkspaceDTO.class, authorizations = {@Authorization(value = "authorization")}) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of updated Workspace"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("/{workspaceId}/admin") @Produces(MediaType.APPLICATION_JSON) Response setNewAdmin(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "New admin user") UserDTO userDTO); @POST @ApiOperation(value = "Create a new workspace", response = WorkspaceDTO.class, authorizations = {@Authorization(value = "authorization")}) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of created Workspace"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) WorkspaceDTO createWorkspace(
            @ApiParam(value = "Login for workspace admin", required = false) @QueryParam("userLogin") String userLogin,
            @ApiParam(value = "Workspace to create", required = true) WorkspaceDTO workspaceDTO); @PUT @ApiOperation(value = "Set user access in workspace", response = UserDTO.class, authorizations = {@Authorization(value = "authorization")}) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of updated UserDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("/{workspaceId}/user-access") @Produces(MediaType.APPLICATION_JSON) Response setUserAccess(
            @ApiParam(value = "Workspace id", required = true) @PathParam("workspaceId") String workspaceId,
            @ApiParam(value = "User to grant access in workspace", required = true) UserDTO userDTO); @PUT @ApiOperation(value = "Set user group access in workspace", response = WorkspaceUserGroupMemberShipDTO.class, authorizations = {@Authorization(value = "authorization")}) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of updated WorkspaceUserGroupMemberShipDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("/{workspaceId}/group-access") @Produces(MediaType.APPLICATION_JSON) Response setGroupAccess(
            @ApiParam(value = "Workspace id", required = true) @PathParam("workspaceId") String workspaceId,
            @ApiParam(value = "User to grant access in group", required = true) WorkspaceUserGroupMemberShipDTO workspaceUserGroupMemberShipDTO); @PUT @ApiOperation(value = "Remove user from user group", response = UserGroupDTO.class, authorizations = {@Authorization(value = "authorization")}) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of updated UserGroupDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("/{workspaceId}/remove-from-group/{groupId}") @Produces(MediaType.APPLICATION_JSON) Response removeUserFromGroup(
            @ApiParam(value = "Workspace id", required = true) @PathParam("workspaceId") String workspaceId,
            @ApiParam(value = "Group id", required = true) @PathParam("groupId") String groupId,
            @ApiParam(value = "User to remove from group", required = true) UserDTO userDTO); @PUT @ApiOperation(value = "Remove user from workspace", response = WorkspaceDTO.class, authorizations = {@Authorization(value = "authorization")}) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of updated WorkspaceDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("/{workspaceId}/remove-from-workspace") @Produces(MediaType.APPLICATION_JSON) Response removeUserFromWorkspace(@ApiParam(value = "Workspace id", required = true) @PathParam("workspaceId") String workspaceId,
                                            @ApiParam(value = "User to remove from workspace", required = true) UserDTO userDTO); @PUT @ApiOperation(value = "Enable user in workspace", response = Response.class, authorizations = {@Authorization(value = "authorization")}) @ApiResponses(value = { @ApiResponse(code = 204, message = "Successful enable operation"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("/{workspaceId}/enable-user") @Produces(MediaType.APPLICATION_JSON) Response enableUser(
            @ApiParam(value = "Workspace id", required = true) @PathParam("workspaceId") String workspaceId,
            @ApiParam(value = "User to enable", required = true) UserDTO userDTO); @PUT @ApiOperation(value = "Disable user in workspace", response = Response.class, authorizations = {@Authorization(value = "authorization")}) @ApiResponses(value = { @ApiResponse(code = 204, message = "Successful disable operation"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("/{workspaceId}/disable-user") @Produces(MediaType.APPLICATION_JSON) Response disableUser(
            @ApiParam(value = "Workspace id", required = true) @PathParam("workspaceId") String workspaceId,
            @ApiParam(value = "User to disable", required = true) UserDTO userDTO); @PUT @ApiOperation(value = "Enable user group in workspace", response = Response.class, authorizations = {@Authorization(value = "authorization")}) @ApiResponses(value = { @ApiResponse(code = 204, message = "Successful enable operation"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("/{workspaceId}/enable-group") @Produces(MediaType.APPLICATION_JSON) Response enableGroup(
            @ApiParam(value = "Workspace id", required = true) @PathParam("workspaceId") String workspaceId,
            @ApiParam(value = "Group to enable", required = true) UserGroupDTO userGroupDTO); @PUT @ApiOperation(value = "Disable user group in workspace", response = Response.class, authorizations = {@Authorization(value = "authorization")}) @ApiResponses(value = { @ApiResponse(code = 204, message = "Successful disable operation"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("/{workspaceId}/disable-group") @Produces(MediaType.APPLICATION_JSON) Response disableGroup(
            @ApiParam(value = "Workspace id", required = true) @PathParam("workspaceId") String workspaceId,
            @ApiParam(value = "Group to disable", required = true) UserGroupDTO userGroupDTO); @GET @ApiOperation(value = "Get stats overview for workspace", response = StatsOverviewDTO.class, authorizations = {@Authorization(value = "authorization")}) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of StatsOverviewDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("/{workspaceId}/stats-overview") @Produces(MediaType.APPLICATION_JSON) StatsOverviewDTO getStatsOverview(
            @ApiParam(value = "Workspace id", required = true) @PathParam("workspaceId") String workspaceId); @GET @ApiOperation(value = "Get disk usage stats for workspace", response = DiskUsageSpaceDTO.class, authorizations = {@Authorization(value = "authorization")}) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of DiskUsageSpaceDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("/{workspaceId}/disk-usage-stats") @Produces(MediaType.APPLICATION_JSON) DiskUsageSpaceDTO getDiskSpaceUsageStats(
            @ApiParam(value = "Workspace id", required = true) @PathParam("workspaceId") String workspaceId); @GET @ApiOperation(value = "Get checked out documents stats for workspace", response = CheckedOutStatsResponseDTO.class, authorizations = {@Authorization(value = "authorization")}) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of documents stats"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("/{workspaceId}/checked-out-documents-stats") @Produces(MediaType.APPLICATION_JSON) Response getCheckedOutDocumentsStats(
            @ApiParam(value = "Workspace id", required = true) @PathParam("workspaceId") String workspaceId); @GET @ApiOperation(value = "Get checked out parts stats for workspace", response = CheckedOutStatsResponseDTO.class, authorizations = {@Authorization(value = "authorization")}) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of parts stats"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("/{workspaceId}/checked-out-parts-stats") @Produces(MediaType.APPLICATION_JSON) Response getCheckedOutPartsStats(
            @ApiParam(value = "Workspace id", required = true) @PathParam("workspaceId") String workspaceId); @GET @ApiOperation(value = "Get user stats for workspace", response = UserStatsDTO.class, authorizations = {@Authorization(value = "authorization")}) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of users stats"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("/{workspaceId}/users-stats") @Produces(MediaType.APPLICATION_JSON) UserStatsDTO getUsersStats(
            @ApiParam(value = "Workspace id", required = true) @PathParam("workspaceId") String workspaceId); @GET @ApiOperation(value = "Get workspace front-end options", response = WorkspaceFrontOptionsDTO.class, authorizations = {@Authorization(value = "authorization")}) @Path("/{workspaceId}/front-options") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieve of workspace front options"), @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) WorkspaceFrontOptionsDTO getWorkspaceFrontOptions(
            @ApiParam(value = "Workspace id", required = true) @PathParam("workspaceId") String workspaceId); @PUT @ApiOperation(value = "Update workspace front-end options", response = Response.class, authorizations = {@Authorization(value = "authorization")}) @Path("/{workspaceId}/front-options") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful update of workspace front options"), @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 updateWorkspaceFrontOptions(
            @ApiParam(value = "Workspace id", required = true) @PathParam("workspaceId") String workspaceId,
            @ApiParam(value = "Option values", required = true) WorkspaceFrontOptionsDTO workspaceFrontOptionsDTO); @GET @ApiOperation(value = "Get workspace back-end options", response = WorkspaceBackOptionsDTO.class, authorizations = {@Authorization(value = "authorization")} ) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of workspace back options"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("/{workspaceId}/back-options") @Produces(MediaType.APPLICATION_JSON) WorkspaceBackOptionsDTO getWorkspaceBackOptions(
            @ApiParam(value = "Workspace id", required = true) @PathParam("workspaceId") String workspaceId); @PUT @ApiOperation(value = "Update workspace back-end options", response = Response.class, authorizations = {@Authorization(value = "authorization")} ) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful update of workspace back options"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("/{workspaceId}/back-options") @Produces(MediaType.APPLICATION_JSON) Response updateWorkspaceBackOptions(
            @ApiParam(value = "Workspace id", required = true) @PathParam("workspaceId") String workspaceId,
            @ApiParam(value = "Option values", required = true) WorkspaceBackOptionsDTO workspaceBackOptionsDTO
    ); @ApiOperation(value = "DocumentsResource") @Path("/{workspaceId}/documents") DocumentsResource documents(); @ApiOperation(value = "FolderResource") @Path("/{workspaceId}/folders") FolderResource folders(); @ApiOperation(value = "DocumentTemplateResource") @Path("/{workspaceId}/document-templates") DocumentTemplateResource docTemplates(); @ApiOperation(value = "PartTemplateResource") @Path("/{workspaceId}/part-templates") PartTemplateResource partTemplates(); @ApiOperation(value = "ProductResource") @Path("/{workspaceId}/products") ProductResource products(); @ApiOperation(value = "ProductConfigurationResource") @Path("/{workspaceId}/product-configurations") ProductConfigurationsResource productConfigurations(); @ApiOperation(value = "ProductBaselinesResource") @Path("/{workspaceId}/product-baselines") ProductBaselinesResource productBaselines(); @ApiOperation(value = "Get all ProductInstancesResource") @Path("/{workspaceId}/product-instances") ProductInstancesResource getProductInstances(); @ApiOperation(value = "PartsResource") @Path("/{workspaceId}/parts") PartsResource parts(); @ApiOperation(value = "TagResource") @Path("/{workspaceId}/tags") TagResource tags(); @ApiOperation(value = "TaskResource") @Path("/{workspaceId}/tasks") TaskResource tasks(); @ApiOperation(value = "ModificationNotificationResource") @Path("/{workspaceId}/notifications") ModificationNotificationResource notifications(); @ApiOperation(value = "WorkflowModelResource") @Path("/{workspaceId}/workflow-models") WorkflowModelResource workflowModels(); @ApiOperation(value = "WorkflowResource") @Path("/{workspaceId}/workflow-instances") WorkflowResource workflowsInstances(); @ApiOperation(value = "WorkspaceWorkflowResource") @Path("/{workspaceId}/workspace-workflows") WorkspaceWorkflowResource workspaceWorkflows(); @ApiOperation(value = "UserResource") @Path("/{workspaceId}/users") UserResource users(); @ApiOperation(value = "UserGroupResource") @Path("/{workspaceId}/groups") UserGroupResource groups(); @ApiOperation(value = "RoleResource", hidden = false) @Path("/{workspaceId}/roles") RoleResource roles(); @ApiOperation(value = "WorkspaceMembershipResource") @Path("/{workspaceId}/memberships") WorkspaceMembershipResource workspaceMemberships(); @ApiOperation(value = "ChangeItemsResource") @Path("/{workspaceId}/changes") ChangeItemsResource changeItems(); @ApiOperation(value = "DocumentBaselinesResource") @Path("/{workspaceId}/document-baselines") DocumentBaselinesResource documentBaselines(); @ApiOperation(value = "LOVResource") @Path("/{workspaceId}/lov") LOVResource lov(); @ApiOperation(hidden = true, value = "AttributesResource") @Path("/{workspaceId}/attributes") AttributesResource attributes(); @ApiOperation(value = "EffectivityResource") @Path("/{workspaceId}/effectivities") EffectivityResource effectivities(); @ApiOperation(value = "WebhookResource") @Path("/{workspaceId}/webhooks") WebhookResource webhooks();  }
@Test public void setUserAccessTest() throws EntityNotFoundException, AccessRightException { Mockito.when(userDTO.getMembership()).thenReturn(WorkspaceMembership.READ_ONLY); Mockito.when(userManager.grantUserAccess("wks-0001", userDTO.getLogin(), userDTO.getMembership() == WorkspaceMembership.READ_ONLY)).thenReturn(null); Response response = workspaceResource.setUserAccess("wks-0001",userDTO); Assert.assertEquals(Response.Status.BAD_REQUEST.getStatusCode(),response.getStatus()); Mockito.when(userDTO.getMembership()).thenReturn(null); response = workspaceResource.setUserAccess("wks-0001",userDTO); Assert.assertEquals(Response.Status.BAD_REQUEST.getStatusCode(),response.getStatus()); Mockito.when(userDTO.getMembership()).thenReturn(WorkspaceMembership.READ_ONLY); Mockito.when(userManager.grantUserAccess("wks-0001", userDTO.getLogin(), userDTO.getMembership() == WorkspaceMembership.READ_ONLY)) .thenReturn(workspaceUserMembership); Mockito.when(workspaceUserMembership.getMember()).thenReturn(new User()); response = workspaceResource.setUserAccess("wks-0001",userDTO); Assert.assertNotNull(response.getEntity()); }