Search in sources :

Example 21 with SubjectAware

use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.

the class CommentServiceTest method shouldPostEventForNewRootComment.

@Test
@SubjectAware(username = "createCommentUser")
public void shouldPostEventForNewRootComment() {
    when(store.add(eq(PULL_REQUEST_ID), rootCommentCaptor.capture())).thenReturn("newId");
    Comment comment = createComment("2", "2. comment", author, new Location());
    commentService.add(NAMESPACE, NAME, PULL_REQUEST_ID, comment);
    assertThat(eventCaptor.getAllValues()).hasSize(1);
    assertThat(eventCaptor.getValue().getEventType()).isEqualTo(HandlerEventType.CREATE);
}
Also used : Comment.createComment(com.cloudogu.scm.review.comment.service.Comment.createComment) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 22 with SubjectAware

use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.

the class CommentServiceTest method shouldTriggerMentionEventIfNewMentionAddedOnCreateComment.

@Test
@SubjectAware(username = "dent")
public void shouldTriggerMentionEventIfNewMentionAddedOnCreateComment() {
    when(store.add(eq(PULL_REQUEST_ID), rootCommentCaptor.capture())).thenReturn("newId");
    when(mentionMapper.extractMentionsFromComment("2. comment @[dent]")).thenReturn(ImmutableSet.of("dent"));
    Comment comment = createComment("2", "2. comment @[dent]", author, new Location());
    String parsedCommentText = "2. comment @Arthur Dent";
    Comment parsedComment = createComment("2", parsedCommentText, author, new Location());
    when(mentionMapper.parseMentionsUserIdsToDisplayNames(comment)).thenReturn(parsedComment);
    commentService.add(NAMESPACE, NAME, PULL_REQUEST_ID, comment);
    assertThat(eventCaptor.getAllValues().size()).isEqualTo(2);
    assertMentionEventFiredAndMentionsParsedToDisplayNames(parsedCommentText);
}
Also used : Comment.createComment(com.cloudogu.scm.review.comment.service.Comment.createComment) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 23 with SubjectAware

use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.

the class CommentServiceTest method shouldExtractMentionsOnAddComment.

@Test
@SubjectAware(username = "createCommentUser")
public void shouldExtractMentionsOnAddComment() {
    when(store.add(eq(PULL_REQUEST_ID), rootCommentCaptor.capture())).thenReturn("newId");
    when(mentionMapper.extractMentionsFromComment(anyString())).thenReturn(ImmutableSet.of("trillian"));
    Comment comment = createComment("2", "2. comment @[trillian]", author, new Location());
    commentService.add(NAMESPACE, NAME, PULL_REQUEST_ID, comment);
    assertThat(rootCommentCaptor.getAllValues()).hasSize(1);
    Comment storedComment = rootCommentCaptor.getValue();
    assertThat(storedComment.getMentionUserIds()).contains("trillian");
}
Also used : Comment.createComment(com.cloudogu.scm.review.comment.service.Comment.createComment) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 24 with SubjectAware

use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.

the class CommentServiceTest method shouldAddCommentOnMergeEvent.

@Test
@SubjectAware(username = "dent")
public void shouldAddCommentOnMergeEvent() {
    when(store.add(eq(PULL_REQUEST_ID), rootCommentCaptor.capture())).thenReturn("newId");
    commentService.addCommentOnMerge(new PullRequestMergedEvent(REPOSITORY, mockPullRequest()));
    assertThat(rootCommentCaptor.getAllValues()).hasSize(1);
    Comment storedComment = rootCommentCaptor.getValue();
    assertThat(storedComment.getComment()).isEqualTo("merged");
}
Also used : Comment.createComment(com.cloudogu.scm.review.comment.service.Comment.createComment) PullRequestMergedEvent(com.cloudogu.scm.review.pullrequest.service.PullRequestMergedEvent) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 25 with SubjectAware

use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.

the class CommentServiceTest method shouldExtractMentionsOnModifyRootCommentText.

@Test
@SubjectAware(username = "dent")
public void shouldExtractMentionsOnModifyRootCommentText() {
    doNothing().when(store).update(eq(PULL_REQUEST_ID), rootCommentCaptor.capture());
    when(mentionMapper.extractMentionsFromComment(anyString())).thenReturn(ImmutableSet.of("trillian"));
    Comment changedRootComment = EXISTING_COMMENT.clone();
    changedRootComment.setComment("new comment @[trillian]");
    changedRootComment.setMentionUserIds(EMPTY_SET);
    commentService.modifyComment(NAMESPACE, NAME, PULL_REQUEST_ID, EXISTING_COMMENT.getId(), changedRootComment);
    assertThat(rootCommentCaptor.getAllValues()).hasSize(1);
    Comment storedComment = rootCommentCaptor.getValue();
    assertThat(storedComment.getComment()).isEqualTo("new comment @[trillian]");
    assertThat(storedComment.getMentionUserIds()).contains("trillian");
}
Also used : Comment.createComment(com.cloudogu.scm.review.comment.service.Comment.createComment) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Aggregations

SubjectAware (com.github.sdorra.shiro.SubjectAware)91 Test (org.junit.Test)91 MockHttpRequest (org.jboss.resteasy.mock.MockHttpRequest)45 Comment.createComment (com.cloudogu.scm.review.comment.service.Comment.createComment)27 JsonNode (com.fasterxml.jackson.databind.JsonNode)18 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)16 PullRequest (com.cloudogu.scm.review.pullrequest.service.PullRequest)14 Reply.createReply (com.cloudogu.scm.review.comment.service.Reply.createReply)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 TestData.createPullRequest (com.cloudogu.scm.review.TestData.createPullRequest)11 Repository (sonia.scm.repository.Repository)9 BasicComment (com.cloudogu.scm.review.comment.service.BasicComment)6 BranchRevisionResolver (com.cloudogu.scm.review.pullrequest.dto.BranchRevisionResolver)6 HalEnricherContext (sonia.scm.api.v2.resources.HalEnricherContext)6 NamespaceAndName (sonia.scm.repository.NamespaceAndName)6 DisplayUser (sonia.scm.user.DisplayUser)6 User (sonia.scm.user.User)6 Changeset (sonia.scm.repository.Changeset)5 Comment (com.cloudogu.scm.review.comment.service.Comment)4 ShiroRule (com.github.sdorra.shiro.ShiroRule)3