use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class CommentServiceTest method shouldModifyCommentWhenUserHasNoModifyPermissionButCommentIsHerOwn.
@Test
@SubjectAware(username = "createCommentUser")
public void shouldModifyCommentWhenUserHasNoModifyPermissionButCommentIsHerOwn() {
doNothing().when(store).update(eq(PULL_REQUEST_ID), rootCommentCaptor.capture());
EXISTING_COMMENT.setAuthor("createCommentUser");
Comment changedRootComment = EXISTING_COMMENT.clone();
changedRootComment.setMentionUserIds(EMPTY_SET);
commentService.modifyComment(NAMESPACE, NAME, PULL_REQUEST_ID, EXISTING_COMMENT.getId(), changedRootComment);
assertThat(rootCommentCaptor.getAllValues()).hasSize(1);
}
use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class CommentServiceTest method shouldTriggerMentionEventIfNewMentionAddedOnCreateReply.
@Test
@SubjectAware(username = "createCommentUser")
public void shouldTriggerMentionEventIfNewMentionAddedOnCreateReply() {
doNothing().when(store).update(eq(PULL_REQUEST_ID), rootCommentCaptor.capture());
when(mentionMapper.extractMentionsFromComment("1. comment @[dent]")).thenReturn(ImmutableSet.of("dent"));
Reply reply = createReply("new reply", "1. comment @[dent]", author);
String parsedCommentText = "2. comment @Arthur Dent";
Reply parsedReply = createReply("2", parsedCommentText, author);
when(mentionMapper.parseMentionsUserIdsToDisplayNames(reply)).thenReturn(parsedReply);
commentService.reply(NAMESPACE, NAME, PULL_REQUEST_ID, "1", reply);
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 shouldFailIfUserHasNoPermissionToCreateComment.
@Test(expected = UnauthorizedException.class)
@SubjectAware(username = "trillian")
public void shouldFailIfUserHasNoPermissionToCreateComment() {
Comment comment = createComment("2", "2. comment", author, new Location());
commentService.add(REPOSITORY.getNamespace(), REPOSITORY.getName(), PULL_REQUEST_ID, comment);
}
use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method shouldReturnAlreadyExistsResult.
@Test
@SubjectAware(username = "dent")
public void shouldReturnAlreadyExistsResult() throws URISyntaxException, IOException {
mockLoggedInUser(new User("dent"));
mockLogCommandForPullRequestCheck(ImmutableList.of(new Changeset()));
PullRequest pullRequest = createPullRequest();
when(store.getAll()).thenReturn(ImmutableList.of(pullRequest));
MockHttpRequest request = MockHttpRequest.get("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo/check?source=develop&target=master");
dispatcher.invoke(request, response);
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getContentAsString()).contains("\"status\":\"PR_ALREADY_EXISTS\"");
assertThat(response.getContentAsString()).contains("\"_links\":{\"self\":{\"href\":\"/v2/pull-requests/ns/repo/check?source=develop&target=master\"}}");
}
use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method shouldGetReviewerPullRequests.
@Test
@SubjectAware(username = "reviewer")
public void shouldGetReviewerPullRequests() throws URISyntaxException, IOException {
initRepoWithPRs("ns", "repo");
MockHttpRequest request = MockHttpRequest.get("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo?status=REVIEWER");
dispatcher.invoke(request, response);
assertThat(response.getStatus()).isEqualTo(200);
JsonNode jsonNode = new ObjectMapper().readValue(response.getContentAsString(), JsonNode.class);
JsonNode prNode = jsonNode.get("_embedded").get("pullRequests");
assertThat(prNode.elements().hasNext()).isTrue();
prNode.elements().forEachRemaining(node -> {
assertThat(node.get("reviewer").get(0).get("id").asText()).isEqualTo("reviewer");
assertThat(node.get("status").asText()).isEqualTo("OPEN");
});
}
Aggregations