MergeRequestRest { @PUT @Path("{requestId}/comments/{commentId}") @Consumes(MediaType.TEXT_PLAIN) @RolesAllowed("user") @ApiOperation("Updates a Comment by its ID using the provided String") public Response updateComment(@PathParam("commentId") String commentId, String newCommentStr) { Resource commentIdResource = createIRI(commentId, vf); Comment comment = manager.getComment(commentIdResource).orElseThrow(() -> ErrorUtils.sendError("Comment " + commentId + " could not be found", Response.Status.BAD_REQUEST)); checkStringParam(newCommentStr, "Comment string is required"); comment.setProperty(vf.createLiteral(newCommentStr), vf.createIRI(_Thing.description_IRI)); try { manager.updateComment(commentIdResource, comment); return Response.ok().build(); } catch (IllegalArgumentException ex) { throw ErrorUtils.sendError(ex, ex.getMessage(), Response.Status.BAD_REQUEST); } catch (IllegalStateException | MobiException ex) { throw ErrorUtils.sendError(ex, ex.getMessage(), Response.Status.INTERNAL_SERVER_ERROR); } }  @GET @Produces(MediaType.APPLICATION_JSON) @RolesAllowed("user") @ApiOperation("Retrieves all MergeRequests in the application") Response getMergeRequests(@QueryParam("sort") String sort,
                              @DefaultValue("false") @QueryParam("ascending") boolean asc,
                              @DefaultValue("false") @QueryParam("accepted") boolean accepted); @POST @Produces(MediaType.TEXT_PLAIN) @Consumes(MediaType.MULTIPART_FORM_DATA) @RolesAllowed("user") @ApiOperation("Creates a new MergeRequest in the application with the provided information") Response createMergeRequests(@Context ContainerRequestContext context,
                                 @FormDataParam("title") String title,
                                 @FormDataParam("description") String description,
                                 @FormDataParam("recordId") String recordId,
                                 @FormDataParam("sourceBranchId") String sourceBranchId,
                                 @FormDataParam("targetBranchId") String targetBranchId,
                                 @FormDataParam("assignees") List<FormDataBodyPart> assignees,
                                 @FormDataParam("removeSource") @DefaultValue("false") boolean removeSource); @GET @Path("{requestId}") @Produces(MediaType.APPLICATION_JSON) @RolesAllowed("user") @ApiOperation("Retrieves a MergeRequest from the application by its ID") Response getMergeRequest(@PathParam("requestId") String requestId); @PUT @Path("{requestId}") @Consumes(MediaType.APPLICATION_JSON) @RolesAllowed("user") @ApiOperation("Updates a MergeRequest by its ID using the provided JSON-LD") Response updateMergeRequest(@PathParam("requestId") String requestId, String newMergeRequest); @POST @Path("{requestId}") @RolesAllowed("user") @ApiOperation("Accepts a MergeRequest by performing the merge and changing the type") @ActionId(Modify.TYPE) @ResourceId(type = ValueType.PROP_PATH, value = "<" + MergeRequest.onRecord_IRI + ">", start = @Value(type = ValueType.PATH, value = "requestId")) @ActionAttributes(@AttributeValue(type = ValueType.PROP_PATH, value = "<" + MergeRequest.targetBranch_IRI + ">", id = VersionedRDFRecord.branch_IRI, start = @Value(type = ValueType.PATH, value = "requestId"))) Response acceptMergeRequest(@Context ContainerRequestContext context,
                                @PathParam("requestId") String requestId); @DELETE @Path("{requestId}") @RolesAllowed("user") @ApiOperation("Deletes a MergeRequest that has the provided requestId") Response deleteMergeRequest(@PathParam("requestId") String requestId); @GET @Path("{requestId}/comments") @Produces(MediaType.APPLICATION_JSON) @RolesAllowed("user") @ApiOperation("Retrieves all Comment threads on a MergeRequest") Response getComments(@PathParam("requestId") String requestId); @GET @Path("{requestId}/comments/{commentId}") @Produces(MediaType.APPLICATION_JSON) @RolesAllowed("user") @ApiOperation("Retrieves a Comment from the application by its ID") Response getComment(@PathParam("requestId") String requestId, @PathParam("commentId") String commentId); @POST @Path("{requestId}/comments") @Consumes(MediaType.TEXT_PLAIN) @Produces(MediaType.TEXT_PLAIN) @RolesAllowed("user") @ApiOperation("Creates a new Comment on the MergeRequest in the application with the provided information") Response createComment(@Context ContainerRequestContext context,
                           @PathParam("requestId") String requestId,
                           @QueryParam("commentId") String commentId,
                           String commentStr); @PUT @Path("{requestId}/comments/{commentId}") @Consumes(MediaType.TEXT_PLAIN) @RolesAllowed("user") @ApiOperation("Updates a Comment by its ID using the provided String") Response updateComment(@PathParam("commentId") String commentId, String newCommentStr); @DELETE @Path("{requestId}/comments/{commentId}") @RolesAllowed("user") @ApiOperation("Deletes a Comment that has the provided commentId") Response deleteComment(@Context ContainerRequestContext context,
                           @PathParam("requestId") String requestId,
                           @PathParam("commentId") String commentId);  }
@Test public void updateCommentTest() { Response response = target().path("merge-requests/" + encode(request1.getResource().stringValue()) + "/comments/" + encode(comment1.getResource().stringValue())) .request() .put(Entity.text(updateCommentText)); ArgumentCaptor<Comment> commentArgumentCaptor = ArgumentCaptor.forClass(Comment.class); verify(requestManager).updateComment(eq(comment1.getResource()), commentArgumentCaptor.capture()); Comment comment = commentArgumentCaptor.getValue(); assertNotEquals(comment.getProperty(vf.createIRI(_Thing.description_IRI)), Optional.empty()); assertEquals(comment.getProperty(vf.createIRI(_Thing.description_IRI)).get().stringValue(), updateCommentText); assertEquals(response.getStatus(), 200); }
@Test public void updateCommentEmptyStringTest() { Response response = target().path("merge-requests/" + encode(request1.getResource().stringValue()) + "/comments/" + encode(comment1.getResource().stringValue())) .request() .put(Entity.text("")); verify(requestManager, never()).updateComment(eq(comment1.getResource()), any(Comment.class)); assertEquals(response.getStatus(), 400); }
@Test public void updateCommentWithInvalidCommentSizeTest() { doThrow(new IllegalArgumentException()).when(requestManager).updateComment(any(Resource.class), any(Comment.class)); Response response = target().path("merge-requests/" + encode(request1.getResource().stringValue()) + "/comments/" + encode(comment1.getResource().stringValue())) .request() .put(Entity.text(largeComment)); ArgumentCaptor<Comment> commentArgumentCaptor = ArgumentCaptor.forClass(Comment.class); verify(requestManager).updateComment(eq(comment1.getResource()), commentArgumentCaptor.capture()); Comment comment = commentArgumentCaptor.getValue(); assertNotEquals(comment.getProperty(vf.createIRI(_Thing.description_IRI)), Optional.empty()); assertEquals(comment.getProperty(vf.createIRI(_Thing.description_IRI)).get().stringValue(), largeComment); assertEquals(response.getStatus(), 400); }
@Test public void updateCommentWithErrorTest() { doThrow(new MobiException()).when(requestManager).updateComment(eq(comment1.getResource()), any(Comment.class)); Response response = target().path("merge-requests/"+ encode(request1.getResource().stringValue()) + "/comments/" + encode(comment1.getResource().stringValue())) .request() .put(Entity.text(updateCommentText)); ArgumentCaptor<Comment> commentArgumentCaptor = ArgumentCaptor.forClass(Comment.class); verify(requestManager).updateComment(eq(comment1.getResource()), commentArgumentCaptor.capture()); Comment comment = commentArgumentCaptor.getValue(); assertNotEquals(comment.getProperty(vf.createIRI(_Thing.description_IRI)), Optional.empty()); assertEquals(comment.getProperty(vf.createIRI(_Thing.description_IRI)).get().stringValue(), updateCommentText); assertEquals(response.getStatus(), 500); }