use of org.jboss.resteasy.mock.MockHttpRequest in project scm-review-plugin by scm-manager.
the class CommentRootResourceTest method shouldNotThrowConflictExceptionIfOnlyOneExpectationInUrl.
@Test
@SubjectAware(username = "slarti", password = "secret")
public void shouldNotThrowConflictExceptionIfOnlyOneExpectationInUrl() throws URISyntaxException, UnsupportedEncodingException {
when(pullRequestService.get(any(), any(), any())).thenReturn(PULL_REQUEST);
when(branchRevisionResolver.getRevisions(any(), eq(PULL_REQUEST))).thenReturn(new BranchRevisionResolver.RevisionResult("source", "target"));
byte[] commentJson = "{\"comment\" : \"this is my comment\"}".getBytes();
MockHttpRequest request = MockHttpRequest.post("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/space/name/1/comments?sourceRevision=source").content(commentJson).contentType(MediaType.APPLICATION_JSON);
dispatcher.invoke(request, response);
assertEquals(HttpServletResponse.SC_CREATED, response.getStatus());
}
use of org.jboss.resteasy.mock.MockHttpRequest in project scm-review-plugin by scm-manager.
the class CommentRootResourceTest method shouldGetAllLinks.
@Test
@SubjectAware(username = "slarti", password = "secret")
public void shouldGetAllLinks() throws URISyntaxException, IOException {
mockExistingComments();
MockHttpRequest request = MockHttpRequest.get("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/space/name/1/comments").contentType(MediaType.APPLICATION_JSON);
dispatcher.invoke(request, response);
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readValue(response.getContentAsString(), JsonNode.class);
JsonNode prNode = jsonNode.get("_embedded").get("pullRequestComments");
JsonNode comment_1 = prNode.path(0);
JsonNode comment_2 = prNode.path(1);
assertThat(comment_1.get("_links").get("self").get("href").asText()).isEqualTo("/v2/pull-requests/space/name/1/comments/1");
assertThat(comment_2.get("_links").get("self").get("href").asText()).isEqualTo("/v2/pull-requests/space/name/1/comments/2");
assertThat(comment_1.get("_links").get("update").get("href").asText()).isEqualTo("/v2/pull-requests/space/name/1/comments/1");
assertThat(comment_2.get("_links").get("update").get("href").asText()).isEqualTo("/v2/pull-requests/space/name/1/comments/2");
assertThat(comment_1.get("_links").get("delete").get("href").asText()).isEqualTo("/v2/pull-requests/space/name/1/comments/1");
// must not delete comment with responses
assertThat(comment_2.get("_links").get("delete")).isNull();
// root comments have reply links
assertThat(comment_1.get("_links").get("reply").get("href").asText()).isEqualTo("/v2/pull-requests/space/name/1/comments/1/reply");
assertThat(comment_2.get("_links").get("reply").get("href").asText()).isEqualTo("/v2/pull-requests/space/name/1/comments/2/reply");
JsonNode replies = comment_2.get("_embedded").get("replies");
JsonNode reply_1 = replies.path(0);
JsonNode reply_2 = replies.path(1);
assertThat(reply_1.get("_links").get("self").get("href").asText()).isEqualTo("/v2/pull-requests/space/name/1/comments/2/replies/2_1");
assertThat(reply_2.get("_links").get("self").get("href").asText()).isEqualTo("/v2/pull-requests/space/name/1/comments/2/replies/2_2");
assertThat(reply_1.get("_links").get("update").get("href").asText()).isEqualTo("/v2/pull-requests/space/name/1/comments/2/replies/2_1");
assertThat(reply_2.get("_links").get("update").get("href").asText()).isEqualTo("/v2/pull-requests/space/name/1/comments/2/replies/2_2");
assertThat(reply_1.get("_links").get("delete").get("href").asText()).isEqualTo("/v2/pull-requests/space/name/1/comments/2/replies/2_1");
assertThat(reply_2.get("_links").get("delete").get("href").asText()).isEqualTo("/v2/pull-requests/space/name/1/comments/2/replies/2_2");
// replies no longer have a reply link
assertThat(reply_1.get("_links").get("reply")).isNull();
assertThat(reply_2.get("_links").get("reply")).isNull();
}
use of org.jboss.resteasy.mock.MockHttpRequest in project scm-review-plugin by scm-manager.
the class CommentRootResourceTest method shouldThrowConflictExceptionIfTargetRevisionNotEqualPullRequestTargetRevision.
@Test
@SubjectAware(username = "slarti", password = "secret")
public void shouldThrowConflictExceptionIfTargetRevisionNotEqualPullRequestTargetRevision() throws URISyntaxException, UnsupportedEncodingException {
when(pullRequestService.get(any(), any(), any())).thenReturn(PULL_REQUEST);
when(branchRevisionResolver.getRevisions(any(), eq(PULL_REQUEST))).thenReturn(new BranchRevisionResolver.RevisionResult("source", "target"));
byte[] commentJson = "{\"comment\" : \"this is my comment\"}".getBytes();
MockHttpRequest request = MockHttpRequest.post("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/space/name/1/comments?sourceRevision=source&targetRevision=other").content(commentJson).contentType(MediaType.APPLICATION_JSON);
dispatcher.invoke(request, response);
assertEquals(HttpServletResponse.SC_CONFLICT, response.getStatus());
assertThat(response.getContentAsString()).contains("modified concurrently");
}
use of org.jboss.resteasy.mock.MockHttpRequest in project scm-review-plugin by scm-manager.
the class CommentRootResourceTest method shouldCreateNewComment.
@Test
@SubjectAware(username = "slarti", password = "secret")
public void shouldCreateNewComment() throws URISyntaxException {
when(pullRequestService.get(any(), any(), any())).thenReturn(PULL_REQUEST);
when(service.add(eq(REPOSITORY_NAMESPACE), eq(REPOSITORY_NAME), eq("1"), argThat(t -> t.getComment().equals("this is my comment")))).thenReturn("1");
byte[] commentJson = "{\"comment\" : \"this is my comment\"}".getBytes();
MockHttpRequest request = MockHttpRequest.post("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/space/name/1/comments?sourceRevision=source&targetRevision=target").content(commentJson).contentType(MediaType.APPLICATION_JSON);
dispatcher.invoke(request, response);
assertEquals(HttpServletResponse.SC_CREATED, response.getStatus());
assertThat(response.getOutputHeaders().getFirst("Location")).hasToString("/v2/pull-requests/space/name/1/comments/1");
}
use of org.jboss.resteasy.mock.MockHttpRequest in project scm-review-plugin by scm-manager.
the class CommentResourceTest method shouldNotDeleteReplyIfPullRequestHasChanged.
@Test
public void shouldNotDeleteReplyIfPullRequestHasChanged() throws URISyntaxException, UnsupportedEncodingException {
MockHttpRequest request = MockHttpRequest.delete("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/space/name/1/comments/1/replies/x?sourceRevision=wrong").contentType(MediaType.APPLICATION_JSON);
dispatcher.invoke(request, response);
verify(service, never()).delete(any(), any(), any(), any());
Assertions.assertThat(response.getContentAsString()).contains("modified concurrently");
}
Aggregations