use of com.cloudogu.scm.review.pullrequest.service.PullRequest in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method shouldGetTheUnsubscribeLink.
@Test
public void shouldGetTheUnsubscribeLink() throws URISyntaxException, IOException {
PullRequest pullRequest = createPullRequest();
pullRequest.setSubscriber(singleton("user1"));
when(store.get("1")).thenReturn(pullRequest);
mockLoggedInUser(new User("user1", "User 1", "email@d.de"));
MockHttpRequest request = MockHttpRequest.get("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo/1/subscription");
dispatcher.invoke(request, response);
assertThat(response.getStatus()).isEqualTo(200);
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readValue(response.getContentAsString(), JsonNode.class);
assertThat(jsonNode.path("_links").get("subscribe")).isNull();
assertThat(jsonNode.path("_links").get("unsubscribe")).isNotNull();
}
use of com.cloudogu.scm.review.pullrequest.service.PullRequest in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method shouldGetTheApproveButNoSubscriptionLinkWithoutMail.
@Test
public void shouldGetTheApproveButNoSubscriptionLinkWithoutMail() throws URISyntaxException, IOException {
PullRequest pullRequest = createPullRequest();
when(store.get("1")).thenReturn(pullRequest);
mockLoggedInUser(new User("user1", "User 1", null));
MockHttpRequest request = MockHttpRequest.get("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo/1");
dispatcher.invoke(request, response);
assertThat(response.getStatus()).isEqualTo(200);
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readValue(response.getContentAsString(), JsonNode.class);
assertThat(jsonNode.path("_links").get("approve")).isNotNull();
assertThat(jsonNode.path("_links").get("subscription")).isNull();
}
use of com.cloudogu.scm.review.pullrequest.service.PullRequest in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method shouldGetMarkAsReviewedLink.
@Test
@SubjectAware(username = "dent")
public void shouldGetMarkAsReviewedLink() throws URISyntaxException, IOException {
PullRequest pullRequest = createPullRequest();
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);
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readValue(response.getContentAsString(), JsonNode.class);
assertThat(jsonNode.path("_links").get("reviewMark")).isNotNull();
}
use of com.cloudogu.scm.review.pullrequest.service.PullRequest in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method shouldSetPullRequestToStatusRejected.
@Test
public void shouldSetPullRequestToStatusRejected() throws URISyntaxException {
Subject subject = mock(Subject.class, RETURNS_DEEP_STUBS);
shiroRule.setSubject(subject);
User currentUser = new User("currentUser");
when(subject.getPrincipals().oneByType(User.class)).thenReturn(currentUser);
when(store.get("1")).thenReturn(createPullRequest("opened_1", PullRequestStatus.OPEN));
when(branchResolver.resolve(any(), any())).thenReturn(Branch.normalBranch("master", "123"));
MockHttpRequest request = MockHttpRequest.post("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo/1/reject");
dispatcher.invoke(request, response);
assertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_NO_CONTENT);
verify(store).update(argThat(pullRequest -> {
assertThat(pullRequest.getStatus()).isEqualTo(REJECTED);
return true;
}));
}
use of com.cloudogu.scm.review.pullrequest.service.PullRequest in project scm-review-plugin by scm-manager.
the class PullRequestMapperTest method shouldAppendSourceAndTargetBranchLinks.
@Test
void shouldAppendSourceAndTargetBranchLinks() {
String sourceLink = "/api/v2/source";
String targetLink = "/api/v2/target";
when(branchLinkProvider.get(REPOSITORY.getNamespaceAndName(), "develop")).thenReturn(sourceLink);
when(branchLinkProvider.get(REPOSITORY.getNamespaceAndName(), "master")).thenReturn(targetLink);
PullRequest pullRequest = TestData.createPullRequest();
PullRequestDto dto = mapper.map(pullRequest, REPOSITORY);
assertThat(dto.getLinks().isEmpty()).isFalse();
Optional<Link> sourceBranch = dto.getLinks().getLinkBy("sourceBranch");
assertThat(sourceBranch).isPresent();
assertThat(sourceBranch.get().getHref()).isEqualTo(sourceLink);
Optional<Link> targetBranch = dto.getLinks().getLinkBy("targetBranch");
assertThat(targetBranch).isPresent();
assertThat(targetBranch.get().getHref()).isEqualTo(targetLink);
}
Aggregations