use of com.cloudogu.scm.review.comment.service.Location in project scm-review-plugin by scm-manager.
the class CommentRootResourceTest method shouldCreateNewComment.
@Test
@SubjectAware(username = "slarti", password = "secret")
public void shouldCreateNewComment() throws URISyntaxException {
when(pullRequestService.get(any(), any(), any())).thenReturn(PULL_REQUEST);
when(service.add(eq(REPOSITORY_NAMESPACE), eq(REPOSITORY_NAME), eq("1"), argThat(t -> t.getComment().equals("this is my comment")))).thenReturn("1");
byte[] commentJson = "{\"comment\" : \"this is my comment\"}".getBytes();
MockHttpRequest request = MockHttpRequest.post("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/space/name/1/comments?sourceRevision=source&targetRevision=target").content(commentJson).contentType(MediaType.APPLICATION_JSON);
dispatcher.invoke(request, response);
assertEquals(HttpServletResponse.SC_CREATED, response.getStatus());
assertThat(response.getOutputHeaders().getFirst("Location")).hasToString("/v2/pull-requests/space/name/1/comments/1");
}
use of com.cloudogu.scm.review.comment.service.Location in project scm-review-plugin by scm-manager.
the class CommentRootResourceTest method mockExistingComments.
private void mockExistingComments() {
Comment comment1 = createComment("1", "1. comment", "author", new Location("file.txt", "123", 0, 3));
Comment comment2 = createComment("2", "2. comment", "author", new Location("", "", 0, 0));
comment1.setContext(new InlineContext(ImmutableList.of(copy(new MockedDiffLine.Builder().newLineNumber(1).get()), copy(new MockedDiffLine.Builder().newLineNumber(2).get()), copy(new MockedDiffLine.Builder().newLineNumber(3).get()))));
Reply reply1 = createReply("2_1", "1. reply", "author");
Reply reply2 = createReply("2_2", "2. reply", "author");
comment2.setReplies(asList(reply1, reply2));
ArrayList<Comment> list = Lists.newArrayList(comment1, comment2);
when(service.getAll("space", "name", "1")).thenReturn(list);
when(service.get("space", "name", "1", "1")).thenReturn(comment1);
when(service.get("space", "name", "1", "2")).thenReturn(comment2);
}
use of com.cloudogu.scm.review.comment.service.Location in project scm-review-plugin by scm-manager.
the class CommentResourceTest method shouldReply.
@Test
public void shouldReply() throws URISyntaxException {
String newComment = "haha ";
when(service.reply(eq("space"), eq("name"), eq("1"), eq("1"), argThat(t -> t.getComment().equals(newComment)))).thenReturn("new");
byte[] pullRequestCommentJson = ("{\"comment\" : \"" + newComment + "\"}").getBytes();
MockHttpRequest request = MockHttpRequest.post("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/space/name/1/comments/1/replies").content(pullRequestCommentJson).contentType(MediaType.APPLICATION_JSON);
dispatcher.invoke(request, response);
verify(service).reply(eq("space"), eq("name"), eq("1"), any(), any());
assertEquals(create("https://scm-manager.org/scm/api/v2/pull-requests/space/name/1/comments/1/replies/new"), response.getOutputHeaders().getFirst("Location"));
assertEquals(HttpServletResponse.SC_CREATED, response.getStatus());
}
use of com.cloudogu.scm.review.comment.service.Location in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method createCommentWithType.
private Comment createCommentWithType(CommentType commentType) {
Comment comment = Comment.createComment("1", "trillian", "tricia", new Location());
comment.setType(commentType);
return comment;
}
use of com.cloudogu.scm.review.comment.service.Location in project scm-review-plugin by scm-manager.
the class RemoveReviewMarksOnChangedCommentsHookTest method shouldRemoveMarksOnNewReplyOnCommentWithSameLocation.
@Test
void shouldRemoveMarksOnNewReplyOnCommentWithSameLocation() {
Reply reply = Reply.createReply("321", "reply", "trillian");
comment.setLocation(new Location("some/file"));
comment.setReplies(singletonList(reply));
pullRequest.setReviewMarks(of(new ReviewMark("some/file", "dent")));
when(commentService.getAll(repository.getNamespace(), repository.getName(), pullRequest.getId())).thenReturn(singletonList(comment));
ReplyEvent event = new ReplyEvent(repository, pullRequest, reply, null, comment, HandlerEventType.CREATE);
hook.handleReplyEvents(event);
verify(pullRequestService).removeReviewMarks(repository, pullRequest.getId(), singletonList(new ReviewMark("some/file", "dent")));
}
Aggregations