use of com.cloudogu.scm.review.pullrequest.service.PullRequest in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method shouldFailUpdatingOnMissingModifyPushPermission.
@Test
@SubjectAware(username = "rr")
public void shouldFailUpdatingOnMissingModifyPushPermission() throws URISyntaxException {
MockHttpRequest request = MockHttpRequest.put("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo/1").content("{\"title\": \"new Title\", \"description\": \"new description\"}".getBytes()).contentType(PullRequestMediaType.PULL_REQUEST);
PullRequest pullRequest = createPullRequest();
when(store.get("1")).thenReturn(pullRequest);
dispatcher.invoke(request, response);
assertEquals(403, response.getStatus());
verify(store, never()).update(any());
}
use of com.cloudogu.scm.review.pullrequest.service.PullRequest in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method shouldCreateNewValidPullRequest.
@Test
@SubjectAware(username = "slarti")
public void shouldCreateNewValidPullRequest() throws URISyntaxException, IOException {
mockPrincipal();
mockChangesets("sourceBranch", "targetBranch", new Changeset());
byte[] pullRequestJson = loadJson("com/cloudogu/scm/review/pullRequest.json");
MockHttpRequest request = MockHttpRequest.post("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/space/name").content(pullRequestJson).contentType(PullRequestMediaType.PULL_REQUEST);
dispatcher.invoke(request, response);
assertEquals(HttpServletResponse.SC_CREATED, response.getStatus());
assertThat(response.getOutputHeaders().getFirst("Location")).hasToString("/v2/pull-requests/space/name/1");
PullRequest pullRequest = pullRequestStoreCaptor.getValue();
assertThat(pullRequest.getAuthor()).isEqualTo("user1");
}
use of com.cloudogu.scm.review.pullrequest.service.PullRequest in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method shouldSortPullRequestsByLastModified.
@Test
@SubjectAware(username = "rr")
public void shouldSortPullRequestsByLastModified() throws URISyntaxException, IOException {
when(repositoryResolver.resolve(new NamespaceAndName(REPOSITORY_NAMESPACE, REPOSITORY_NAME))).thenReturn(repository);
String firstPR = "first_PR";
String toDayUpdatedPR = "to_day_updated_PR";
String lastPR = "last_PR";
Instant firstCreation = Instant.MIN;
Instant firstCreationPlusOneDay = firstCreation.plus(Duration.ofDays(1));
Instant lastCreation = Instant.MAX;
PullRequest firstPullRequest = createPullRequest(firstPR);
firstPullRequest.setCreationDate(firstCreationPlusOneDay);
firstPullRequest.setLastModified(firstCreationPlusOneDay);
PullRequest toDayUpdatedPullRequest = createPullRequest(toDayUpdatedPR);
toDayUpdatedPullRequest.setCreationDate(firstCreation);
toDayUpdatedPullRequest.setLastModified(Instant.now());
PullRequest lastPullRequest = createPullRequest(lastPR);
lastPullRequest.setCreationDate(lastCreation);
lastPullRequest.setLastModified(lastCreation);
when(store.getAll()).thenReturn(Lists.newArrayList(lastPullRequest, firstPullRequest, toDayUpdatedPullRequest));
MockHttpRequest request = MockHttpRequest.get("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/" + REPOSITORY_NAMESPACE + "/" + REPOSITORY_NAME + "");
dispatcher.invoke(request, response);
assertThat(response.getStatus()).isEqualTo(200);
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readValue(response.getContentAsString(), JsonNode.class);
JsonNode prNode = jsonNode.get("_embedded").get("pullRequests");
JsonNode pr_1 = prNode.path(0);
JsonNode pr_2 = prNode.path(1);
JsonNode pr_3 = prNode.path(2);
assertThat(pr_1.get("id").asText()).isEqualTo(lastPR);
assertThat(pr_2.get("id").asText()).isEqualTo(toDayUpdatedPR);
assertThat(pr_3.get("id").asText()).isEqualTo(firstPR);
}
use of com.cloudogu.scm.review.pullrequest.service.PullRequest in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method shouldGetAlreadyExistsExceptionOnCreatePR.
@Test
@SubjectAware(username = "slarti")
public void shouldGetAlreadyExistsExceptionOnCreatePR() throws URISyntaxException, IOException {
PullRequest pr = new PullRequest();
pr.setStatus(PullRequestStatus.OPEN);
pr.setSource("source");
pr.setTarget("target");
pr.setTitle("title");
pr.setId("id");
when(store.getAll()).thenReturn(Lists.newArrayList(pr));
byte[] pullRequestJson = "{\"source\": \"source\", \"target\": \"target\", \"title\": \"pull request\"}".getBytes();
when(repositoryResolver.resolve(new NamespaceAndName(REPOSITORY_NAMESPACE, REPOSITORY_NAME))).thenReturn(repository);
MockHttpRequest request = MockHttpRequest.post("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/" + REPOSITORY_NAMESPACE + "/" + REPOSITORY_NAME).content(pullRequestJson).contentType(PullRequestMediaType.PULL_REQUEST);
dispatcher.invoke(request, response);
assertThat(response.getContentAsString()).containsPattern("pull request with id id in repository with id .* already exists");
}
use of com.cloudogu.scm.review.pullrequest.service.PullRequest in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method shouldGetTheApproveAndSubscriptionLink.
@Test
public void shouldGetTheApproveAndSubscriptionLink() throws URISyntaxException, IOException {
PullRequest pullRequest = createPullRequest();
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");
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")).isNotNull();
}
Aggregations