@Test public void getMembersTest() throws EntityNotFoundException, AccessRightException { organization.addMember(account); Mockito.when(organizationManager.getMyOrganization()).thenReturn(organization); Response response = organizationResource.getMembers(); Object entity = response.getEntity(); Assert.assertTrue(entity.getClass().isAssignableFrom(ArrayList.class)); List objects = (ArrayList) entity; Assert.assertEquals(1, objects.size()); Object o = objects.get(0); Assert.assertNotNull(o); Assert.assertTrue(o.getClass().isAssignableFrom(AccountDTO.class)); AccountDTO fetchedAccount = (AccountDTO) o; Assert.assertNotNull(fetchedAccount); Assert.assertEquals(account.getLogin(), fetchedAccount.getLogin()); }
@GET @Path("members") @ApiOperation(value = "Get members of the authenticated user's organization", response = AccountDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of AccountDTOs. 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 getMembers() throws EntityNotFoundException, AccessRightException { Organization organization = organizationManager.getMyOrganization(); List<Account> accounts = organization.getMembers(); List<AccountDTO> accountsDTOs = new ArrayList<>(); for (Account account : accounts) { accountsDTOs.add(mapper.map(account, AccountDTO.class)); } return Response.ok(new GenericEntity<List<AccountDTO>>((List<AccountDTO>) accountsDTOs) { }).build(); }
OrganizationResource { @GET @Path("members") @ApiOperation(value = "Get members of the authenticated user's organization", response = AccountDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of AccountDTOs. 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 getMembers() throws EntityNotFoundException, AccessRightException { Organization organization = organizationManager.getMyOrganization(); List<Account> accounts = organization.getMembers(); List<AccountDTO> accountsDTOs = new ArrayList<>(); for (Account account : accounts) { accountsDTOs.add(mapper.map(account, AccountDTO.class)); } return Response.ok(new GenericEntity<List<AccountDTO>>((List<AccountDTO>) accountsDTOs) { }).build(); } }
OrganizationResource { @GET @Path("members") @ApiOperation(value = "Get members of the authenticated user's organization", response = AccountDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of AccountDTOs. 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 getMembers() throws EntityNotFoundException, AccessRightException { Organization organization = organizationManager.getMyOrganization(); List<Account> accounts = organization.getMembers(); List<AccountDTO> accountsDTOs = new ArrayList<>(); for (Account account : accounts) { accountsDTOs.add(mapper.map(account, AccountDTO.class)); } return Response.ok(new GenericEntity<List<AccountDTO>>((List<AccountDTO>) accountsDTOs) { }).build(); } OrganizationResource(); }
OrganizationResource { @GET @Path("members") @ApiOperation(value = "Get members of the authenticated user's organization", response = AccountDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of AccountDTOs. 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 getMembers() throws EntityNotFoundException, AccessRightException { Organization organization = organizationManager.getMyOrganization(); List<Account> accounts = organization.getMembers(); List<AccountDTO> accountsDTOs = new ArrayList<>(); for (Account account : accounts) { accountsDTOs.add(mapper.map(account, AccountDTO.class)); } return Response.ok(new GenericEntity<List<AccountDTO>>((List<AccountDTO>) accountsDTOs) { }).build(); } OrganizationResource(); @PostConstruct void init(); @GET @ApiOperation(value = "Get organization for authenticated user", response = OrganizationDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of OrganizationDTO. It may be a null object"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) OrganizationDTO getOrganization(); @POST @ApiOperation(value = "Create authenticated user's organization", response = OrganizationDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of created OrganizationDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) OrganizationDTO createOrganization(
            @ApiParam(required = true, value = "Organization to create") OrganizationDTO organizationDTO); @PUT @ApiOperation(value = "Update authenticated user's organization", response = OrganizationDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of updated OrganizationDTO"), @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) OrganizationDTO updateOrganization(
            @ApiParam(required = true, value = "Updated organization") OrganizationDTO organizationDTO); @DELETE @ApiOperation(value = "Delete authenticated user's organization", response = Response.class) @ApiResponses(value = { @ApiResponse(code = 204, message = "Successful deletion of OrganizationDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) Response deleteOrganization(); @GET @Path("members") @ApiOperation(value = "Get members of the authenticated user's organization", response = AccountDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of AccountDTOs. 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 getMembers(); @PUT @Path("add-member") @ApiOperation(value = "Add a member to the authenticated user's organization", response = Response.class) @ApiResponses(value = { @ApiResponse(code = 204, message = "Successful member add operation"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) Response addMember(
            @ApiParam(required = true, value = "User to add") UserDTO userDTO); @PUT @Path("remove-member") @ApiOperation(value = "Remove a member to the authenticated user's organization", response = Response.class) @ApiResponses(value = { @ApiResponse(code = 204, message = "Successful member removal operation"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) Response removeMember(
            @ApiParam(required = true, value = "User to remove") UserDTO userDTO); @PUT @Path("move-member") @ApiOperation(value = "Move a member up or down in the authenticated user's organization", response = Response.class) @ApiResponses(value = { @ApiResponse(code = 204, message = "Successful member moved operation"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) Response moveMember(
            @ApiParam(required = true, value = "User to move up") UserDTO userDTO,
            @ApiParam(required = true, value = "Direction (up/down)") @QueryParam("direction") String direction); }
OrganizationResource { @GET @Path("members") @ApiOperation(value = "Get members of the authenticated user's organization", response = AccountDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of AccountDTOs. 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 getMembers() throws EntityNotFoundException, AccessRightException { Organization organization = organizationManager.getMyOrganization(); List<Account> accounts = organization.getMembers(); List<AccountDTO> accountsDTOs = new ArrayList<>(); for (Account account : accounts) { accountsDTOs.add(mapper.map(account, AccountDTO.class)); } return Response.ok(new GenericEntity<List<AccountDTO>>((List<AccountDTO>) accountsDTOs) { }).build(); } OrganizationResource(); @PostConstruct void init(); @GET @ApiOperation(value = "Get organization for authenticated user", response = OrganizationDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of OrganizationDTO. It may be a null object"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) OrganizationDTO getOrganization(); @POST @ApiOperation(value = "Create authenticated user's organization", response = OrganizationDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of created OrganizationDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) OrganizationDTO createOrganization(
            @ApiParam(required = true, value = "Organization to create") OrganizationDTO organizationDTO); @PUT @ApiOperation(value = "Update authenticated user's organization", response = OrganizationDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of updated OrganizationDTO"), @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) OrganizationDTO updateOrganization(
            @ApiParam(required = true, value = "Updated organization") OrganizationDTO organizationDTO); @DELETE @ApiOperation(value = "Delete authenticated user's organization", response = Response.class) @ApiResponses(value = { @ApiResponse(code = 204, message = "Successful deletion of OrganizationDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) Response deleteOrganization(); @GET @Path("members") @ApiOperation(value = "Get members of the authenticated user's organization", response = AccountDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of AccountDTOs. 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 getMembers(); @PUT @Path("add-member") @ApiOperation(value = "Add a member to the authenticated user's organization", response = Response.class) @ApiResponses(value = { @ApiResponse(code = 204, message = "Successful member add operation"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) Response addMember(
            @ApiParam(required = true, value = "User to add") UserDTO userDTO); @PUT @Path("remove-member") @ApiOperation(value = "Remove a member to the authenticated user's organization", response = Response.class) @ApiResponses(value = { @ApiResponse(code = 204, message = "Successful member removal operation"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) Response removeMember(
            @ApiParam(required = true, value = "User to remove") UserDTO userDTO); @PUT @Path("move-member") @ApiOperation(value = "Move a member up or down in the authenticated user's organization", response = Response.class) @ApiResponses(value = { @ApiResponse(code = 204, message = "Successful member moved operation"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) Response moveMember(
            @ApiParam(required = true, value = "User to move up") UserDTO userDTO,
            @ApiParam(required = true, value = "Direction (up/down)") @QueryParam("direction") String direction);  }