use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class CommentServiceTest method shouldTriggerMentionEventIfNewMentionAddedOnModify.
@Test
@SubjectAware(username = "dent")
public void shouldTriggerMentionEventIfNewMentionAddedOnModify() {
doNothing().when(store).update(eq(PULL_REQUEST_ID), rootCommentCaptor.capture());
when(mentionMapper.extractMentionsFromComment("new comment @[dent]")).thenReturn(ImmutableSet.of("dent"));
Comment changedRootComment = EXISTING_COMMENT.clone();
changedRootComment.setComment("new comment @[dent]");
changedRootComment.setMentionUserIds(EMPTY_SET);
String parsedCommentText = "2. comment @Arthur Dent";
Comment parsedComment = EXISTING_COMMENT.clone();
parsedComment.setComment(parsedCommentText);
when(mentionMapper.parseMentionsUserIdsToDisplayNames(any(Comment.class))).thenReturn(parsedComment);
commentService.modifyComment(NAMESPACE, NAME, PULL_REQUEST_ID, changedRootComment.getId(), changedRootComment);
assertThat(eventCaptor.getAllValues().size()).isEqualTo(2);
assertMentionEventFiredAndMentionsParsedToDisplayNames(parsedCommentText);
}
use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class CommentServiceTest method shouldExtractMentionsOnCreateReply.
@Test
@SubjectAware(username = "createCommentUser")
public void shouldExtractMentionsOnCreateReply() {
doNothing().when(store).update(eq(PULL_REQUEST_ID), rootCommentCaptor.capture());
when(mentionMapper.extractMentionsFromComment(anyString())).thenReturn(ImmutableSet.of("dent"));
Reply reply = createReply("new reply", "1. comment @[dent]", author);
commentService.reply(NAMESPACE, NAME, PULL_REQUEST_ID, "1", reply);
assertThat(rootCommentCaptor.getAllValues()).hasSize(1);
Comment storedComment = rootCommentCaptor.getValue();
assertThat(storedComment.getReplies()).hasSize(2);
assertThat(storedComment.getReplies()).contains(reply);
assertThat(storedComment.getReplies().get(1).getId()).isNotEqualTo("new reply @[dent]");
}
use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class CommentServiceTest method shouldFailModifyingReplyWhenUserHasNoPermission.
@Test(expected = UnauthorizedException.class)
@SubjectAware(username = "createCommentUser")
public void shouldFailModifyingReplyWhenUserHasNoPermission() {
Reply changedReply = EXISTING_REPLY.clone();
commentService.modifyReply(NAMESPACE, NAME, PULL_REQUEST_ID, EXISTING_REPLY.getId(), changedReply);
}
use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class CommentServiceTest method shouldModifyReplyDoneFlag.
@Test
@SubjectAware(username = "dent")
public void shouldModifyReplyDoneFlag() {
doNothing().when(store).update(eq(PULL_REQUEST_ID), rootCommentCaptor.capture());
Reply changedReply = EXISTING_REPLY.clone();
commentService.modifyReply(NAMESPACE, NAME, PULL_REQUEST_ID, EXISTING_REPLY.getId(), changedReply);
assertThat(rootCommentCaptor.getAllValues()).hasSize(1);
Comment storedComment = rootCommentCaptor.getValue();
assertThat(storedComment.getReplies()).hasSize(1);
}
use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class CommentServiceTest method shouldModifyRootCommentText.
@Test
@SubjectAware(username = "dent")
public void shouldModifyRootCommentText() {
doNothing().when(store).update(eq(PULL_REQUEST_ID), rootCommentCaptor.capture());
Comment changedRootComment = EXISTING_COMMENT.clone();
changedRootComment.setComment("new comment");
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");
}
Aggregations