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 + "\"");
}
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();
}
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();
}
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/");
}
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();
}
Aggregations