Search in sources :

Example 1 with Location

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");
}
Also used : ContextLine.copy(com.cloudogu.scm.review.comment.service.ContextLine.copy) Provider(javax.inject.Provider) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ShiroRule(com.github.sdorra.shiro.ShiroRule) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) RestDispatcher(sonia.scm.web.RestDispatcher) URISyntaxException(java.net.URISyntaxException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BranchRevisionResolver(com.cloudogu.scm.review.pullrequest.dto.BranchRevisionResolver) Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) PullRequestRootResource(com.cloudogu.scm.review.pullrequest.api.PullRequestRootResource) PullRequestMapperImpl(com.cloudogu.scm.review.pullrequest.dto.PullRequestMapperImpl) MediaType(javax.ws.rs.core.MediaType) Comment(com.cloudogu.scm.review.comment.service.Comment) Arrays.asList(java.util.Arrays.asList) JsonNode(com.fasterxml.jackson.databind.JsonNode) UriBuilder(javax.ws.rs.core.UriBuilder) PullRequestService(com.cloudogu.scm.review.pullrequest.service.PullRequestService) RepositoryResolver(com.cloudogu.scm.review.RepositoryResolver) PullRequestResource(com.cloudogu.scm.review.pullrequest.api.PullRequestResource) ExecutedTransition(com.cloudogu.scm.review.comment.service.ExecutedTransition) ChannelRegistry(sonia.scm.sse.ChannelRegistry) MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) CommentService(com.cloudogu.scm.review.comment.service.CommentService) UserDisplayManager(sonia.scm.user.UserDisplayManager) InlineContext(com.cloudogu.scm.review.comment.service.InlineContext) Providers(com.google.inject.util.Providers) UriInfo(javax.ws.rs.core.UriInfo) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MockHttpResponse(org.jboss.resteasy.mock.MockHttpResponse) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) ArrayList(java.util.ArrayList) Reply(com.cloudogu.scm.review.comment.service.Reply) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Reply.createReply(com.cloudogu.scm.review.comment.service.Reply.createReply) RepositoryServiceFactory(sonia.scm.repository.api.RepositoryServiceFactory) MockedDiffLine(com.cloudogu.scm.review.comment.service.MockedDiffLine) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) TestData(com.cloudogu.scm.review.TestData) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) CommentTransition(com.cloudogu.scm.review.comment.service.CommentTransition) SubjectAware(com.github.sdorra.shiro.SubjectAware) Rule(org.junit.Rule) Location(com.cloudogu.scm.review.comment.service.Location) Comment.createComment(com.cloudogu.scm.review.comment.service.Comment.createComment) Assert.assertEquals(org.junit.Assert.assertEquals) MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 2 with Location

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);
}
Also used : Comment(com.cloudogu.scm.review.comment.service.Comment) Comment.createComment(com.cloudogu.scm.review.comment.service.Comment.createComment) UriBuilder(javax.ws.rs.core.UriBuilder) Reply(com.cloudogu.scm.review.comment.service.Reply) Reply.createReply(com.cloudogu.scm.review.comment.service.Reply.createReply) InlineContext(com.cloudogu.scm.review.comment.service.InlineContext) Location(com.cloudogu.scm.review.comment.service.Location)

Example 3 with Location

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());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MockHttpResponse(org.jboss.resteasy.mock.MockHttpResponse) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) RestDispatcher(sonia.scm.web.RestDispatcher) URISyntaxException(java.net.URISyntaxException) RunWith(org.junit.runner.RunWith) BranchRevisionResolver(com.cloudogu.scm.review.pullrequest.dto.BranchRevisionResolver) Repository(sonia.scm.repository.Repository) PullRequestRootResource(com.cloudogu.scm.review.pullrequest.api.PullRequestRootResource) Reply(com.cloudogu.scm.review.comment.service.Reply) PullRequestMapperImpl(com.cloudogu.scm.review.pullrequest.dto.PullRequestMapperImpl) MediaType(javax.ws.rs.core.MediaType) Comment(com.cloudogu.scm.review.comment.service.Comment) RepositoryServiceFactory(sonia.scm.repository.api.RepositoryServiceFactory) Assertions(org.assertj.core.api.Assertions) UriBuilder(javax.ws.rs.core.UriBuilder) PullRequestService(com.cloudogu.scm.review.pullrequest.service.PullRequestService) Before(org.junit.Before) RepositoryResolver(com.cloudogu.scm.review.RepositoryResolver) PullRequestResource(com.cloudogu.scm.review.pullrequest.api.PullRequestResource) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.junit.Test) ChannelRegistry(sonia.scm.sse.ChannelRegistry) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) Mockito.never(org.mockito.Mockito.never) URI.create(java.net.URI.create) CommentService(com.cloudogu.scm.review.comment.service.CommentService) Providers(com.google.inject.util.Providers) UriInfo(javax.ws.rs.core.UriInfo) Location(com.cloudogu.scm.review.comment.service.Location) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Comment.createComment(com.cloudogu.scm.review.comment.service.Comment.createComment) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) Test(org.junit.Test)

Example 4 with Location

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;
}
Also used : Comment(com.cloudogu.scm.review.comment.service.Comment) Location(com.cloudogu.scm.review.comment.service.Location)

Example 5 with Location

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")));
}
Also used : ReplyEvent(com.cloudogu.scm.review.comment.service.ReplyEvent) Reply(com.cloudogu.scm.review.comment.service.Reply) Location(com.cloudogu.scm.review.comment.service.Location) Test(org.junit.jupiter.api.Test)

Aggregations

Location (com.cloudogu.scm.review.comment.service.Location)10 Comment (com.cloudogu.scm.review.comment.service.Comment)5 Reply (com.cloudogu.scm.review.comment.service.Reply)5 Test (org.junit.jupiter.api.Test)5 Comment.createComment (com.cloudogu.scm.review.comment.service.Comment.createComment)3 CommentEvent (com.cloudogu.scm.review.comment.service.CommentEvent)3 CommentService (com.cloudogu.scm.review.comment.service.CommentService)3 UriBuilder (javax.ws.rs.core.UriBuilder)3 Repository (sonia.scm.repository.Repository)3 RepositoryResolver (com.cloudogu.scm.review.RepositoryResolver)2 BasicComment (com.cloudogu.scm.review.comment.service.BasicComment)2 InlineContext (com.cloudogu.scm.review.comment.service.InlineContext)2 Reply.createReply (com.cloudogu.scm.review.comment.service.Reply.createReply)2 PullRequestResource (com.cloudogu.scm.review.pullrequest.api.PullRequestResource)2 PullRequestRootResource (com.cloudogu.scm.review.pullrequest.api.PullRequestRootResource)2 BranchRevisionResolver (com.cloudogu.scm.review.pullrequest.dto.BranchRevisionResolver)2 PullRequestMapperImpl (com.cloudogu.scm.review.pullrequest.dto.PullRequestMapperImpl)2 PullRequestService (com.cloudogu.scm.review.pullrequest.service.PullRequestService)2 Providers (com.google.inject.util.Providers)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2