Search in sources :

Example 76 with SubjectAware

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);
}
Also used : Comment.createComment(com.cloudogu.scm.review.comment.service.Comment.createComment) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 77 with SubjectAware

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);
}
Also used : Reply.createReply(com.cloudogu.scm.review.comment.service.Reply.createReply) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 78 with SubjectAware

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);
}
Also used : Comment.createComment(com.cloudogu.scm.review.comment.service.Comment.createComment) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 79 with SubjectAware

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\"}}");
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) DisplayUser(sonia.scm.user.DisplayUser) User(sonia.scm.user.User) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) TestData.createPullRequest(com.cloudogu.scm.review.TestData.createPullRequest) Changeset(sonia.scm.repository.Changeset) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 80 with SubjectAware

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");
    });
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) 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