MilestonesResource { @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") public Response getRequestsByMilestone( @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId, @ApiParam(required = true, value = "Milestone id") @PathParam("milestoneId") int milestoneId) throws EntityNotFoundException, UserNotActiveException, AccessRightException, WorkspaceNotEnabledException { List<ChangeRequest> changeRequests = changeManager.getChangeRequestsByMilestone(workspaceId, milestoneId); List<ChangeRequestDTO> changeRequestDTOs = new ArrayList<>(); for (ChangeRequest changeRequest : changeRequests) { changeRequestDTOs.add(mapper.map(changeRequest, ChangeRequestDTO.class)); } return Response.ok(new GenericEntity<List<ChangeRequestDTO>>((List<ChangeRequestDTO>) changeRequestDTOs) { }).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 getRequestsByMilestoneTest() throws ApplicationException { int milestoneId = 22; List<ChangeRequest> requests = new ArrayList<>(); ChangeRequest request = new ChangeRequest(); Workspace workspace = new Workspace(workspaceId); request.setWorkspace(workspace); Account account = new Account("foo"); User author = new User(workspace, account); request.setAuthor(author); request.setName("name"); requests.add(request); Mockito.when(changeManager.getChangeRequestsByMilestone(workspaceId, milestoneId)) .thenReturn(requests); Response response = milestonesResource.getRequestsByMilestone(workspaceId, milestoneId); Object entity = response.getEntity(); Assert.assertNotNull(entity); Assert.assertTrue(entity.getClass().isAssignableFrom(ArrayList.class)); List requestList = (ArrayList) entity; Assert.assertFalse(requestList.isEmpty()); Object o = requestList.get(0); Assert.assertTrue(o.getClass().isAssignableFrom(ChangeRequestDTO.class)); ChangeRequestDTO dto = (ChangeRequestDTO) o; Assert.assertEquals(request.getName(), dto.getName()); }