Search in sources :

Example 26 with PullRequest

use of com.cloudogu.scm.review.pullrequest.service.PullRequest in project scm-review-plugin by scm-manager.

the class PullRequestRootResourceTest method initRepoWithPRs.

private void initRepoWithPRs(String namespace, String name) throws IOException {
    mockChangesets("develop", "master", new Changeset());
    when(repository.getNamespace()).thenReturn(namespace);
    when(repository.getName()).thenReturn(name);
    PullRequest openedPR1 = createPullRequest("opened_1", PullRequestStatus.OPEN);
    PullRequest openedPR2 = createPullRequest("opened_2", PullRequestStatus.OPEN);
    PullRequest mergedPR1 = createPullRequest("merged_1", PullRequestStatus.MERGED);
    PullRequest mergedPR2 = createPullRequest("merged_2", PullRequestStatus.MERGED);
    PullRequest rejectedPR1 = createPullRequest("rejected_1", REJECTED);
    PullRequest rejectedPR2 = createPullRequest("rejected_2", REJECTED);
    openedPR2.setAuthor("author");
    mergedPR2.setAuthor("author");
    openedPR1.setReviewer(singletonMap("reviewer", false));
    mergedPR1.setReviewer(singletonMap("reviewer", true));
    when(store.getAll()).thenReturn(Lists.newArrayList(openedPR1, openedPR2, rejectedPR1, rejectedPR2, mergedPR1, mergedPR2));
    when(commentService.getAll(any(), any(), any())).thenReturn(Collections.emptyList());
}
Also used : PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) TestData.createPullRequest(com.cloudogu.scm.review.TestData.createPullRequest) Changeset(sonia.scm.repository.Changeset)

Example 27 with PullRequest

use of com.cloudogu.scm.review.pullrequest.service.PullRequest 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 28 with PullRequest

use of com.cloudogu.scm.review.pullrequest.service.PullRequest 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 29 with PullRequest

use of com.cloudogu.scm.review.pullrequest.service.PullRequest 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)

Example 30 with PullRequest

use of com.cloudogu.scm.review.pullrequest.service.PullRequest in project scm-review-plugin by scm-manager.

the class PullRequestRootResourceTest method shouldGetMarkedAsReviewedPaths.

@Test
@SubjectAware(username = "dent")
public void shouldGetMarkedAsReviewedPaths() throws URISyntaxException, IOException {
    mockLoggedInUser(new User("dent"));
    PullRequest pullRequest = createPullRequest();
    pullRequest.setAuthor("slarti");
    pullRequest.setReviewMarks(ImmutableSet.of(new ReviewMark("/some/file", "dent"), new ReviewMark("/some/other/file", "trillian")));
    when(store.get("1")).thenReturn(pullRequest);
    MockHttpRequest request = MockHttpRequest.get("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo/1");
    dispatcher.invoke(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getContentAsString()).contains("\"markedAsReviewed\":[\"/some/file\"]");
}
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) ReviewMark(com.cloudogu.scm.review.pullrequest.service.ReviewMark) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Aggregations

PullRequest (com.cloudogu.scm.review.pullrequest.service.PullRequest)82 Repository (sonia.scm.repository.Repository)27 Test (org.junit.jupiter.api.Test)20 Test (org.junit.Test)18 TestData.createPullRequest (com.cloudogu.scm.review.TestData.createPullRequest)17 MockHttpRequest (org.jboss.resteasy.mock.MockHttpRequest)16 Subscribe (com.github.legman.Subscribe)13 SubjectAware (com.github.sdorra.shiro.SubjectAware)13 NamespaceAndName (sonia.scm.repository.NamespaceAndName)13 User (sonia.scm.user.User)11 DisplayUser (sonia.scm.user.DisplayUser)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 Optional (java.util.Optional)7 Comment (com.cloudogu.scm.review.comment.service.Comment)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 PermissionCheck (com.cloudogu.scm.review.PermissionCheck)5 PullRequestService (com.cloudogu.scm.review.pullrequest.service.PullRequestService)5 Operation (io.swagger.v3.oas.annotations.Operation)5 List (java.util.List)5