MilestonesResource { @GET @ApiOperation(value = "Get milestones for given parameters", response = MilestoneDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of MilestoneDTOs. 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 getMilestones( @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId) throws EntityNotFoundException, UserNotActiveException, WorkspaceNotEnabledException { List<Milestone> milestones = changeManager.getMilestones(workspaceId); List<MilestoneDTO> milestoneDTOs = new ArrayList<>(); for (Milestone milestone : milestones) { MilestoneDTO milestoneDTO = mapper.map(milestone, MilestoneDTO.class); milestoneDTO.setWritable(changeManager.isMilestoneWritable(milestone)); milestoneDTO.setNumberOfRequests(changeManager.getNumberOfRequestByMilestone(milestone.getWorkspaceId(), milestone.getId())); milestoneDTO.setNumberOfOrders(changeManager.getNumberOfOrderByMilestone(milestone.getWorkspaceId(), milestone.getId())); milestoneDTOs.add(milestoneDTO); } return Response.ok(new GenericEntity<List<MilestoneDTO>>((List<MilestoneDTO>) milestoneDTOs) { }).build(); } MilestonesResource(); @PostConstruct void init(); @GET @ApiOperation(value = "Get milestones for given parameters", response = MilestoneDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of MilestoneDTOs. 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 getMilestones(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId); @POST @ApiOperation(value = "Create a new milestone", response = MilestoneDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of created MilestoneDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) MilestoneDTO createMilestone(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Milestone to create") MilestoneDTO milestoneDTO); @GET @ApiOperation(value = "Get a milestone by id", response = MilestoneDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of MilestoneDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) @Path("{milestoneId}") MilestoneDTO getMilestone(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Milestone id") @PathParam("milestoneId") int milestoneId); @PUT @ApiOperation(value = "Update milestone", response = MilestoneDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of updated MilestoneDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path("{milestoneId}") MilestoneDTO updateMilestone(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Milestone id") @PathParam("milestoneId") int milestoneId,
            @ApiParam(required = true, value = "Milestone to update") MilestoneDTO pMilestoneDTO); @DELETE @ApiOperation(value = "Delete milestone", response = Response.class) @ApiResponses(value = { @ApiResponse(code = 204, message = "Successful deletion of MilestoneDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Consumes(MediaType.APPLICATION_JSON) @Path("{milestoneId}") Response removeMilestone(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Milestone id") @PathParam("milestoneId") int milestoneId); @GET @ApiOperation(value = "Get change requests for a given milestone", response = ChangeRequestDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of created ChangeRequestDTOs. 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) @Path("{milestoneId}/requests") Response getRequestsByMilestone(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Milestone id") @PathParam("milestoneId") int milestoneId); @GET @ApiOperation(value = "Get change orders for a given milestone", response = ChangeOrderDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of created ChangeOrderDTOs. 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) @Path("{milestoneId}/orders") Response getOrdersByMilestone(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Milestone id") @PathParam("milestoneId") int milestoneId); @PUT @ApiOperation(value = "Update ACL of a milestone", response = Response.class) @ApiResponses(value = { @ApiResponse(code = 204, message = "Successful ACL update of MilestoneDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("{milestoneId}/acl") @Consumes(MediaType.APPLICATION_JSON) Response updateMilestoneACL(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Milestone id") @PathParam("milestoneId") int milestoneId,
            @ApiParam(required = true, value = "ACL rules to set") ACLDTO acl);  }
@Test public void getMilestonesTest() throws ApplicationException { List<Milestone> list = new ArrayList<>(); Workspace workspace = new Workspace(workspaceId); Milestone milestone = new Milestone(workspace, "title"); list.add(milestone); Mockito.when(changeManager.getMilestones(workspaceId)) .thenReturn(list); Mockito.when(changeManager.isMilestoneWritable(milestone)) .thenReturn(true); Mockito.when(changeManager.getNumberOfRequestByMilestone(workspaceId, milestone.getId())) .thenReturn(1); Mockito.when(changeManager.getNumberOfOrderByMilestone(workspaceId, milestone.getId())) .thenReturn(1); Response res = milestonesResource.getMilestones(workspaceId); Assert.assertEquals(Response.Status.OK.getStatusCode(), res.getStatus()); Assert.assertTrue(res.getEntity().getClass().isAssignableFrom(ArrayList.class)); }