Search in sources :

Example 31 with PullRequest

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

the class PullRequestRootResourceTest method shouldGetAllPullRequests.

@Test
@SubjectAware(username = "rr")
public void shouldGetAllPullRequests() throws URISyntaxException, UnsupportedEncodingException {
    when(repositoryResolver.resolve(new NamespaceAndName(REPOSITORY_NAMESPACE, REPOSITORY_NAME))).thenReturn(repository);
    String id_1 = "id_1";
    String id_2 = "ABC ID 2";
    List<PullRequest> pullRequests = Lists.newArrayList(createPullRequest(id_1), createPullRequest(id_2));
    when(store.getAll()).thenReturn(pullRequests);
    // request all PRs without filter
    MockHttpRequest request = MockHttpRequest.get("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/" + REPOSITORY_NAMESPACE + "/" + REPOSITORY_NAME + "");
    dispatcher.invoke(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getContentAsString()).contains("\"id\":\"" + id_1 + "\"");
    assertThat(response.getContentAsString()).contains("\"id\":\"" + id_2 + "\"");
    // request all PRs with filter: status=ALL
    request = MockHttpRequest.get("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/" + REPOSITORY_NAMESPACE + "/" + REPOSITORY_NAME + "?status=ALL");
    response.reset();
    dispatcher.invoke(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getContentAsString()).contains("\"id\":\"" + id_1 + "\"");
    assertThat(response.getContentAsString()).contains("\"id\":\"" + id_2 + "\"");
}
Also used : 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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 32 with PullRequest

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

the class PullRequestMapperTest method shouldMapPullRequestWithMergeLink.

@Test
void shouldMapPullRequestWithMergeLink() {
    when(serviceFactory.create(REPOSITORY)).thenReturn(service);
    when(service.isSupported(Command.MERGE)).thenReturn(true);
    when(service.getMergeCommand().getSupportedMergeStrategies()).thenReturn(ImmutableSet.of(MergeStrategy.MERGE_COMMIT));
    when(subject.isPermitted("repository:commentPullRequest:id-1")).thenReturn(true);
    when(subject.isPermitted("repository:push:id-1")).thenReturn(true);
    when(subject.isPermitted("repository:mergePullRequest:id-1")).thenReturn(true);
    PullRequest pullRequest = TestData.createPullRequest();
    PullRequestDto dto = mapper.map(pullRequest, REPOSITORY);
    assertThat(dto.getLinks().isEmpty()).isFalse();
    assertThat(dto.getLinks().getLinkBy("merge")).isPresent();
    assertThat(dto.getLinks().getLinkBy("defaultCommitMessage")).isPresent();
}
Also used : PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) Test(org.junit.jupiter.api.Test)

Example 33 with PullRequest

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

the class PullRequestMapperTest method shouldMapPullRequestWithEmergencyMergeLink.

@Test
void shouldMapPullRequestWithEmergencyMergeLink() {
    when(serviceFactory.create(REPOSITORY)).thenReturn(service);
    when(service.isSupported(Command.MERGE)).thenReturn(true);
    when(service.getMergeCommand().getSupportedMergeStrategies()).thenReturn(ImmutableSet.of(MergeStrategy.MERGE_COMMIT));
    when(subject.isPermitted("repository:commentPullRequest:id-1")).thenReturn(true);
    when(subject.isPermitted("repository:push:id-1")).thenReturn(true);
    when(subject.isPermitted("repository:mergePullRequest:id-1")).thenReturn(true);
    when(subject.isPermitted("repository:performEmergencyMerge:id-1")).thenReturn(true);
    PullRequest pullRequest = TestData.createPullRequest();
    PullRequestDto dto = mapper.map(pullRequest, REPOSITORY);
    assertThat(dto.getLinks().isEmpty()).isFalse();
    assertThat(dto.getLinks().getLinkBy("emergencyMerge")).isPresent();
}
Also used : PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) Test(org.junit.jupiter.api.Test)

Example 34 with PullRequest

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

the class PullRequestMapperTest method shouldAddLinkForWorkflowResultIfPullRequestIsOpen.

@Test
void shouldAddLinkForWorkflowResultIfPullRequestIsOpen() {
    PullRequest pullRequest = TestData.createPullRequest();
    PullRequestDto dto = mapper.map(pullRequest, REPOSITORY);
    assertThat(dto.getLinks().getLinkBy("workflowResult")).get().extracting("href").isEqualTo("/v2/pull-requests/space/x/id/workflow/");
}
Also used : PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) Test(org.junit.jupiter.api.Test)

Example 35 with PullRequest

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

the class PullRequestMapperTest method shouldNotAddLinkForWorkflowResultIfPullRequestIsRejected.

@Test
void shouldNotAddLinkForWorkflowResultIfPullRequestIsRejected() {
    PullRequest pullRequest = TestData.createPullRequest();
    pullRequest.setStatus(PullRequestStatus.REJECTED);
    PullRequestDto dto = mapper.map(pullRequest, REPOSITORY);
    assertThat(dto.getLinks().getLinkBy("workflowResult")).isEmpty();
}
Also used : PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) Test(org.junit.jupiter.api.Test)

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