use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method shouldGetEventsLink.
@Test
@SubjectAware(username = "slarti", password = "secret")
public void shouldGetEventsLink() throws URISyntaxException, IOException {
initRepoWithPRs("ns", "repo");
MockHttpRequest request = MockHttpRequest.get("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo");
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");
prNode.elements().forEachRemaining(node -> {
String actualCollectionLink = node.path("_links").path("events").path("href").asText();
assertThat(actualCollectionLink).isEqualTo("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo/" + node.get("id").asText() + "/events");
});
}
use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method shouldRejectWithoutDiff.
@Test
@SubjectAware(username = "slarti")
public void shouldRejectWithoutDiff() throws URISyntaxException, IOException {
mockPrincipal();
mockChangesets("sourceBranch", "targetBranch");
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_BAD_REQUEST, response.getStatus());
verify(store, never()).add(any());
}
use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method shouldReturnBranchesNotDifferResultIfNoChangesetsInDiff.
@Test
@SubjectAware(username = "dent")
public void shouldReturnBranchesNotDifferResultIfNoChangesetsInDiff() throws URISyntaxException, IOException {
mockLoggedInUser(new User("dent"));
mockLogCommandForPullRequestCheck(emptyList());
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\":\"BRANCHES_NOT_DIFFER\"");
assertThat(response.getContentAsString()).contains("\"_links\":{\"self\":{\"href\":\"/v2/pull-requests/ns/repo/check?source=feature&target=master\"}}");
}
use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method shouldGetUpdateLink.
@Test
@SubjectAware(username = "slarti")
public void shouldGetUpdateLink() throws URISyntaxException, IOException {
initRepoWithPRs("ns", "repo");
MockHttpRequest request = MockHttpRequest.get("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo");
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");
prNode.elements().forEachRemaining(node -> {
String actual = node.path("_links").path("update").path("href").asText();
assertThat(actual).isEqualTo("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo/" + node.get("id").asText());
});
}
use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method shouldApprove.
@Test
@SubjectAware(username = "dent")
public void shouldApprove() throws URISyntaxException {
initPullRequestRootResource();
MockHttpRequest request = MockHttpRequest.post("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo/1/approve");
dispatcher.invoke(request, response);
verify(pullRequestService).approve(new NamespaceAndName("ns", "repo"), "1");
assertThat(response.getStatus()).isEqualTo(204);
}
Aggregations