use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method shouldGetMarkedAsReviewedPaths.
@Test
@SubjectAware(username = "dent")
public void shouldGetMarkedAsReviewedPaths() throws URISyntaxException, IOException {
mockLoggedInUser(new User("dent"));
PullRequest pullRequest = createPullRequest();
pullRequest.setAuthor("slarti");
pullRequest.setReviewMarks(ImmutableSet.of(new ReviewMark("/some/file", "dent"), new ReviewMark("/some/other/file", "trillian")));
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);
assertThat(response.getContentAsString()).contains("\"markedAsReviewed\":[\"/some/file\"]");
}
use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method shouldGetAllPullRequests.
@Test
@SubjectAware(username = "rr")
public void shouldGetAllPullRequests() throws URISyntaxException, UnsupportedEncodingException {
when(repositoryResolver.resolve(new NamespaceAndName(REPOSITORY_NAMESPACE, REPOSITORY_NAME))).thenReturn(repository);
String id_1 = "id_1";
String id_2 = "ABC ID 2";
List<PullRequest> pullRequests = Lists.newArrayList(createPullRequest(id_1), createPullRequest(id_2));
when(store.getAll()).thenReturn(pullRequests);
// request all PRs without filter
MockHttpRequest request = MockHttpRequest.get("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/" + REPOSITORY_NAMESPACE + "/" + REPOSITORY_NAME + "");
dispatcher.invoke(request, response);
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getContentAsString()).contains("\"id\":\"" + id_1 + "\"");
assertThat(response.getContentAsString()).contains("\"id\":\"" + id_2 + "\"");
// request all PRs with filter: status=ALL
request = MockHttpRequest.get("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/" + REPOSITORY_NAMESPACE + "/" + REPOSITORY_NAME + "?status=ALL");
response.reset();
dispatcher.invoke(request, response);
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getContentAsString()).contains("\"id\":\"" + id_1 + "\"");
assertThat(response.getContentAsString()).contains("\"id\":\"" + id_2 + "\"");
}
use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method shouldHandleMissingRepository.
@Test
@SubjectAware(username = "trillian")
public void shouldHandleMissingRepository() throws URISyntaxException, IOException {
when(repositoryResolver.resolve(new NamespaceAndName("space", "X"))).thenThrow(new NotFoundException("x", "y"));
byte[] pullRequestJson = loadJson("com/cloudogu/scm/review/pullRequest.json");
MockHttpRequest request = MockHttpRequest.post("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/space/X").content(pullRequestJson).contentType(PullRequestMediaType.PULL_REQUEST);
dispatcher.invoke(request, response);
assertThat(response.getContentAsString()).containsPattern("could not find.*");
}
use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method shouldDisapprove.
@Test
@SubjectAware(username = "dent")
public void shouldDisapprove() throws URISyntaxException {
initPullRequestRootResource();
MockHttpRequest request = MockHttpRequest.post("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo/1/disapprove");
dispatcher.invoke(request, response);
verify(pullRequestService).disapprove(any(), any());
assertThat(response.getStatus()).isEqualTo(204);
}
use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method shouldRejectSameBranches.
@Test
@SubjectAware(username = "slarti")
public void shouldRejectSameBranches() throws URISyntaxException, IOException {
byte[] pullRequestJson = loadJson("com/cloudogu/scm/review/pullRequest_sameBranches.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());
}
Aggregations