use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method shouldGetMinePullRequests.
@Test
@SubjectAware(username = "author")
public void shouldGetMinePullRequests() throws URISyntaxException, IOException {
initRepoWithPRs("ns", "repo");
MockHttpRequest request = MockHttpRequest.get("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo?status=MINE");
dispatcher.invoke(request, response);
assertThat(response.getStatus()).isEqualTo(200);
JsonNode jsonNode = new ObjectMapper().readValue(response.getContentAsString(), JsonNode.class);
JsonNode prNode = jsonNode.get("_embedded").get("pullRequests");
assertThat(prNode.elements().hasNext()).isTrue();
prNode.elements().forEachRemaining(node -> assertThat(node.get("author").get("id").asText()).isEqualTo("author"));
}
use of com.github.sdorra.shiro.SubjectAware 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.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method shouldNotGetUpdateLinkForUserWithoutPushPermission.
@Test
@SubjectAware(username = "rr")
public void shouldNotGetUpdateLinkForUserWithoutPushPermission() 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 -> assertThat(node.path("_links").get("update")).isNull());
}
use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method shouldMarkAsReviewed.
@Test
@SubjectAware(username = "dent")
public void shouldMarkAsReviewed() throws URISyntaxException {
initPullRequestRootResource();
MockHttpRequest request = MockHttpRequest.post("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo/1/review-mark/some/file");
dispatcher.invoke(request, response);
verify(pullRequestService).markAsReviewed(repository, "1", "some/file");
assertThat(response.getStatus()).isEqualTo(204);
}
use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method shouldRejectChangingStatusOfMergedPullRequest.
@Test
@SubjectAware(username = "slarti")
public void shouldRejectChangingStatusOfMergedPullRequest() throws URISyntaxException {
when(store.get("1")).thenReturn(createPullRequest("opened_1", PullRequestStatus.MERGED));
MockHttpRequest request = MockHttpRequest.post("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo/1/reject");
dispatcher.invoke(request, response);
assertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_BAD_REQUEST);
verify(store, never()).update(any());
}
Aggregations