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