Search in sources :

Example 61 with SubjectAware

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

the class CommentRootResourceTest method shouldGetOnlyTheSelfLinkÍfTheAuthorIsNotTheCurrentUser.

@Test
@SubjectAware(username = "createCommentUser", password = "secret")
public void shouldGetOnlyTheSelfLinkÍfTheAuthorIsNotTheCurrentUser() throws URISyntaxException, IOException {
    mockExistingComments();
    MockHttpRequest request = MockHttpRequest.get("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/space/name/1/comments").contentType(MediaType.APPLICATION_JSON);
    dispatcher.invoke(request, response);
    assertEquals(HttpServletResponse.SC_OK, response.getStatus());
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonNode = mapper.readValue(response.getContentAsString(), JsonNode.class);
    JsonNode prNode = jsonNode.get("_embedded").get("pullRequestComments");
    JsonNode comment_1 = prNode.path(0);
    JsonNode comment_2 = prNode.path(1);
    assertThat(comment_1.get("_links").get("self").get("href").asText()).isEqualTo("/v2/pull-requests/space/name/1/comments/1");
    assertThat(comment_2.get("_links").get("self").get("href").asText()).isEqualTo("/v2/pull-requests/space/name/1/comments/2");
    assertThat(comment_1.get("_links").get("update")).isNull();
    assertThat(comment_2.get("_links").get("update")).isNull();
    assertThat(comment_1.get("_links").get("delete")).isNull();
    assertThat(comment_2.get("_links").get("delete")).isNull();
    JsonNode replies = comment_2.get("_embedded").get("replies");
    JsonNode reply_1 = replies.path(0);
    JsonNode reply_2 = replies.path(1);
    assertThat(reply_1.get("_links").get("self").get("href").asText()).isEqualTo("/v2/pull-requests/space/name/1/comments/2/replies/2_1");
    assertThat(reply_2.get("_links").get("self").get("href").asText()).isEqualTo("/v2/pull-requests/space/name/1/comments/2/replies/2_2");
    assertThat(reply_1.get("_links").get("update")).isNull();
    assertThat(reply_2.get("_links").get("update")).isNull();
    assertThat(reply_1.get("_links").get("delete")).isNull();
    assertThat(reply_2.get("_links").get("delete")).isNull();
    assertThat(reply_1.get("_links").get("reply")).isNull();
    assertThat(reply_2.get("_links").get("reply")).isNull();
}
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)

Example 62 with SubjectAware

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

the class RepositoryLinkEnricherTest method shouldNotEnrichRepositoriesForConfigWhenRepositoryConfigIsDisabled.

@Test
@SubjectAware(username = "dent", password = "secret")
public void shouldNotEnrichRepositoriesForConfigWhenRepositoryConfigIsDisabled() {
    enricher = new RepositoryLinkEnricher(scmPathInfoStoreProvider, pullRequestService, configService, globalEngineConfigurator);
    when(pullRequestService.supportsPullRequests(any())).thenReturn(true);
    mockGlobalConfig(true);
    Repository repo = new Repository("id", "type", "space", "name");
    HalEnricherContext context = HalEnricherContext.of(repo);
    enricher.enrich(context, appender);
    verify(appender).appendLink("pullRequest", "https://scm-manager.org/scm/api/v2/pull-requests/space/name");
    verify(appender, never()).appendLink(eq("pullRequestConfig"), any());
}
Also used : Repository(sonia.scm.repository.Repository) HalEnricherContext(sonia.scm.api.v2.resources.HalEnricherContext) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 63 with SubjectAware

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

the class RepositoryLinkEnricherTest method shouldEnrichPullRequestCheckLink.

@Test
@SubjectAware(username = "dent", password = "secret")
public void shouldEnrichPullRequestCheckLink() {
    when(pullRequestService.supportsPullRequests(any())).thenReturn(true);
    mockGlobalConfig(true);
    enricher = new RepositoryLinkEnricher(scmPathInfoStoreProvider, pullRequestService, configService, globalEngineConfigurator);
    Repository repo = new Repository("id", "type", "space", "name");
    HalEnricherContext context = HalEnricherContext.of(repo);
    enricher.enrich(context, appender);
    verify(appender).appendLink("pullRequestCheck", "https://scm-manager.org/scm/api/v2/pull-requests/space/name/check");
}
Also used : Repository(sonia.scm.repository.Repository) HalEnricherContext(sonia.scm.api.v2.resources.HalEnricherContext) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 64 with SubjectAware

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

the class CommentServiceTest method shouldMarkCommentAsOutdated.

@Test
@SubjectAware(username = "trillian")
public void shouldMarkCommentAsOutdated() {
    doNothing().when(store).update(eq(PULL_REQUEST_ID), rootCommentCaptor.capture());
    Comment comment = EXISTING_COMMENT.clone();
    commentService.markAsOutdated(NAMESPACE, NAME, PULL_REQUEST_ID, comment.getId());
    assertThat(rootCommentCaptor.getAllValues()).hasSize(1);
    Comment storedComment = rootCommentCaptor.getValue();
    assertThat(storedComment.isOutdated()).isTrue();
}
Also used : Comment.createComment(com.cloudogu.scm.review.comment.service.Comment.createComment) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 65 with SubjectAware

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

the class CommentServiceTest method shouldAddCommentOnRejectEventByDeletedBranch.

@Test
@SubjectAware(username = "dent")
public void shouldAddCommentOnRejectEventByDeletedBranch() {
    PullRequest pullRequest = mockPullRequest();
    when(store.add(eq(PULL_REQUEST_ID), rootCommentCaptor.capture())).thenReturn("newId");
    commentService.addCommentOnReject(new PullRequestRejectedEvent(REPOSITORY, pullRequest, PullRequestRejectedEvent.RejectionCause.BRANCH_DELETED));
    assertThat(rootCommentCaptor.getAllValues()).hasSize(1);
    Comment storedComment = rootCommentCaptor.getValue();
    assertThat(storedComment.getComment()).isEqualTo("sourceDeleted");
}
Also used : PullRequestRejectedEvent(com.cloudogu.scm.review.pullrequest.service.PullRequestRejectedEvent) Comment.createComment(com.cloudogu.scm.review.comment.service.Comment.createComment) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) 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