use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method shouldMarkAsNotReviewed.
@Test
@SubjectAware(username = "dent")
public void shouldMarkAsNotReviewed() throws URISyntaxException {
initPullRequestRootResource();
MockHttpRequest request = MockHttpRequest.delete("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo/1/review-mark/some/file");
dispatcher.invoke(request, response);
verify(pullRequestService).markAsNotReviewed(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 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.github.sdorra.shiro.SubjectAware 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.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method shouldGetCommentLink.
@Test
@SubjectAware(username = "slarti")
public void shouldGetCommentLink() 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("comments").path("href").asText();
assertThat(actualCollectionLink).isEqualTo("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo/" + node.get("id").asText() + "/comments/");
});
}
use of com.github.sdorra.shiro.SubjectAware 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\"}}");
}
Aggregations