Search in sources :

Example 6 with Comment

use of com.cloudogu.scm.review.comment.service.Comment 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 7 with Comment

use of com.cloudogu.scm.review.comment.service.Comment 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 8 with Comment

use of com.cloudogu.scm.review.comment.service.Comment in project scm-review-plugin by scm-manager.

the class CommentResourceTest method shouldNotReplyIfPullRequestHasChanged.

@Test
public void shouldNotReplyIfPullRequestHasChanged() throws URISyntaxException, UnsupportedEncodingException {
    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?sourceRevision=wrong").content(pullRequestCommentJson).contentType(MediaType.APPLICATION_JSON);
    dispatcher.invoke(request, response);
    verify(service, never()).reply(any(), any(), any(), any(), any());
    Assertions.assertThat(response.getContentAsString()).contains("modified concurrently");
}
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 9 with Comment

use of com.cloudogu.scm.review.comment.service.Comment in project scm-review-plugin by scm-manager.

the class EventListenerTest method createCommentEvent.

private CommentEvent createCommentEvent() {
    Repository repository = RepositoryTestData.createHeartOfGold();
    PullRequest pullRequest = TestData.createPullRequest();
    mockChannel(repository, pullRequest);
    Comment comment = new Comment();
    comment.setId("c42");
    return new CommentEvent(repository, pullRequest, null, comment, HandlerEventType.DELETE);
}
Also used : Comment(com.cloudogu.scm.review.comment.service.Comment) CommentEvent(com.cloudogu.scm.review.comment.service.CommentEvent) Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest)

Example 10 with Comment

use of com.cloudogu.scm.review.comment.service.Comment in project scm-review-plugin by scm-manager.

the class EmailNotificationHookTest method shouldNotSendSystemEmails.

@Test
void shouldNotSendSystemEmails() throws Exception {
    Comment systemComment = Comment.createSystemComment("1");
    CommentEvent commentEvent = new CommentEvent(repository, pullRequest, systemComment, oldComment, HandlerEventType.CREATE);
    emailNotificationHook.handleCommentEvents(commentEvent);
    verify(service, never()).sendEmail(any(), any());
    verify(service, never()).sendEmail(any(), any());
    reset(service);
}
Also used : Comment(com.cloudogu.scm.review.comment.service.Comment) CommentEvent(com.cloudogu.scm.review.comment.service.CommentEvent) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Aggregations

Comment (com.cloudogu.scm.review.comment.service.Comment)18 Repository (sonia.scm.repository.Repository)7 Comment.createComment (com.cloudogu.scm.review.comment.service.Comment.createComment)6 BranchRevisionResolver (com.cloudogu.scm.review.pullrequest.dto.BranchRevisionResolver)6 MockHttpRequest (org.jboss.resteasy.mock.MockHttpRequest)6 Test (org.junit.Test)6 Location (com.cloudogu.scm.review.comment.service.Location)5 Reply (com.cloudogu.scm.review.comment.service.Reply)5 PullRequest (com.cloudogu.scm.review.pullrequest.service.PullRequest)5 Operation (io.swagger.v3.oas.annotations.Operation)5 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)5 Path (javax.ws.rs.Path)5 NamespaceAndName (sonia.scm.repository.NamespaceAndName)5 RepositoryResolver (com.cloudogu.scm.review.RepositoryResolver)4 CommentService (com.cloudogu.scm.review.comment.service.CommentService)4 PullRequestService (com.cloudogu.scm.review.pullrequest.service.PullRequestService)4 GET (javax.ws.rs.GET)4 Produces (javax.ws.rs.Produces)4 MediaType (javax.ws.rs.core.MediaType)4 UriBuilder (javax.ws.rs.core.UriBuilder)4