Search in sources :

Example 41 with SubjectAware

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

the class PullRequestRootResourceTest method shouldMarkAsNotReviewed.

@Test
@SubjectAware(username = "dent")
public void shouldMarkAsNotReviewed() throws URISyntaxException {
    initPullRequestRootResource();
    MockHttpRequest request = MockHttpRequest.delete("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo/1/review-mark/some/file");
    dispatcher.invoke(request, response);
    verify(pullRequestService).markAsNotReviewed(repository, "1", "some/file");
    assertThat(response.getStatus()).isEqualTo(204);
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 42 with SubjectAware

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

the class PullRequestRootResourceTest method shouldUpdatePullRequestSuccessfully.

@Test
@SubjectAware(username = "slarti")
public void shouldUpdatePullRequestSuccessfully() throws URISyntaxException {
    PullRequest existingPullRequest = new PullRequest();
    existingPullRequest.setAuthor("somebody");
    when(store.get("1")).thenReturn(existingPullRequest);
    MockHttpRequest request = MockHttpRequest.put("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo/1").content("{\"title\": \"new Title\", \"description\": \"new description\"}".getBytes()).contentType(PullRequestMediaType.PULL_REQUEST);
    dispatcher.invoke(request, response);
    assertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_NO_CONTENT);
    verify(store).update(argThat(pullRequest -> {
        assertThat(pullRequest.getTitle()).isEqualTo("new Title");
        assertThat(pullRequest.getDescription()).isEqualTo("new description");
        return true;
    }));
}
Also used : PullRequestMediaType(com.cloudogu.scm.review.PullRequestMediaType) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ShiroRule(com.github.sdorra.shiro.ShiroRule) URL(java.net.URL) RestDispatcher(sonia.scm.web.RestDispatcher) URISyntaxException(java.net.URISyntaxException) ScmEventBus(sonia.scm.event.ScmEventBus) DefaultPullRequestService(com.cloudogu.scm.review.pullrequest.service.DefaultPullRequestService) Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) PullRequestMapperImpl(com.cloudogu.scm.review.pullrequest.dto.PullRequestMapperImpl) Collections.singleton(java.util.Collections.singleton) Comment(com.cloudogu.scm.review.comment.service.Comment) Arrays.asList(java.util.Arrays.asList) After(org.junit.After) Duration(java.time.Duration) JsonNode(com.fasterxml.jackson.databind.JsonNode) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) RepositoryService(sonia.scm.repository.api.RepositoryService) PullRequestStore(com.cloudogu.scm.review.pullrequest.service.PullRequestStore) AssertionsForClassTypes.assertThat(org.assertj.core.api.AssertionsForClassTypes.assertThat) NotFoundException(sonia.scm.NotFoundException) RepositoryResolver(com.cloudogu.scm.review.RepositoryResolver) ImmutableSet(com.google.common.collect.ImmutableSet) Collections.emptyList(java.util.Collections.emptyList) Changeset(sonia.scm.repository.Changeset) ChannelRegistry(sonia.scm.sse.ChannelRegistry) Instant(java.time.Instant) MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) List(java.util.List) CommentService(com.cloudogu.scm.review.comment.service.CommentService) CommentType(com.cloudogu.scm.review.comment.service.CommentType) Lists(org.assertj.core.util.Lists) UserDisplayManager(sonia.scm.user.UserDisplayManager) REJECTED(com.cloudogu.scm.review.pullrequest.service.PullRequestStatus.REJECTED) Optional(java.util.Optional) Providers(com.google.inject.util.Providers) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) NamespaceAndName(sonia.scm.repository.NamespaceAndName) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PullRequestStatus(com.cloudogu.scm.review.pullrequest.service.PullRequestStatus) Mockito.mock(org.mockito.Mockito.mock) BranchResolver(com.cloudogu.scm.review.BranchResolver) Branch(sonia.scm.repository.Branch) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MockHttpResponse(org.jboss.resteasy.mock.MockHttpResponse) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Mockito.lenient(org.mockito.Mockito.lenient) DisplayUser(sonia.scm.user.DisplayUser) ArrayList(java.util.ArrayList) ChangesetPagingResult(sonia.scm.repository.ChangesetPagingResult) LogCommandBuilder(sonia.scm.repository.api.LogCommandBuilder) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) Subject(org.apache.shiro.subject.Subject) RepositoryServiceFactory(sonia.scm.repository.api.RepositoryServiceFactory) Collections.singletonMap(java.util.Collections.singletonMap) RETURNS_DEEP_STUBS(org.mockito.Mockito.RETURNS_DEEP_STUBS) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) Answers(org.mockito.Answers) BranchLinkProvider(sonia.scm.api.v2.resources.BranchLinkProvider) Resources(com.google.common.io.Resources) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpServletResponse(javax.servlet.http.HttpServletResponse) PullRequestStoreFactory(com.cloudogu.scm.review.pullrequest.service.PullRequestStoreFactory) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) User(sonia.scm.user.User) Mockito.verify(org.mockito.Mockito.verify) TestData.createPullRequest(com.cloudogu.scm.review.TestData.createPullRequest) Mockito.never(org.mockito.Mockito.never) SubjectAware(com.github.sdorra.shiro.SubjectAware) Rule(org.junit.Rule) ThreadContext(org.apache.shiro.util.ThreadContext) ReviewMark(com.cloudogu.scm.review.pullrequest.service.ReviewMark) Location(com.cloudogu.scm.review.comment.service.Location) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) TestData.createPullRequest(com.cloudogu.scm.review.TestData.createPullRequest) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 43 with SubjectAware

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

the class PullRequestRootResourceTest method shouldGetPullRequest.

@Test
@SubjectAware(username = "rr")
public void shouldGetPullRequest() throws URISyntaxException, UnsupportedEncodingException {
    when(repositoryResolver.resolve(new NamespaceAndName(REPOSITORY_NAMESPACE, REPOSITORY_NAME))).thenReturn(repository);
    PullRequest pullRequest = createPullRequest();
    List<Comment> comments = new ArrayList<>();
    comments.add(createCommentWithType(CommentType.TASK_TODO));
    when(commentService.getAll(REPOSITORY_NAMESPACE, REPOSITORY_NAME, pullRequest.getId())).thenReturn(comments);
    when(store.get("123")).thenReturn(pullRequest);
    MockHttpRequest request = MockHttpRequest.get("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/" + REPOSITORY_NAMESPACE + "/" + REPOSITORY_NAME + "/123");
    dispatcher.invoke(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getContentAsString()).contains("_links");
    assertThat(response.getContentAsString()).contains("\"tasks\":{\"todo\":1");
    assertThat(response.getContentAsString()).contains("\"done\":0");
}
Also used : Comment(com.cloudogu.scm.review.comment.service.Comment) MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) NamespaceAndName(sonia.scm.repository.NamespaceAndName) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) TestData.createPullRequest(com.cloudogu.scm.review.TestData.createPullRequest) ArrayList(java.util.ArrayList) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 44 with SubjectAware

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

the class PullRequestRootResourceTest method shouldGetCommentLink.

@Test
@SubjectAware(username = "slarti")
public void shouldGetCommentLink() throws URISyntaxException, IOException {
    initRepoWithPRs("ns", "repo");
    MockHttpRequest request = MockHttpRequest.get("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo");
    dispatcher.invoke(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonNode = mapper.readValue(response.getContentAsString(), JsonNode.class);
    JsonNode prNode = jsonNode.get("_embedded").get("pullRequests");
    prNode.elements().forEachRemaining(node -> {
        String actualCollectionLink = node.path("_links").path("comments").path("href").asText();
        assertThat(actualCollectionLink).isEqualTo("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo/" + node.get("id").asText() + "/comments/");
    });
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 45 with SubjectAware

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

the class PullRequestRootResourceTest method shouldReturnPullRequestIsValidResult.

@Test
@SubjectAware(username = "dent")
public void shouldReturnPullRequestIsValidResult() 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=feature&target=master");
    dispatcher.invoke(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getContentAsString()).contains("\"status\":\"PR_VALID\"");
    assertThat(response.getContentAsString()).contains("\"_links\":{\"self\":{\"href\":\"/v2/pull-requests/ns/repo/check?source=feature&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)

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