use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class CommentRootResourceTest method shouldThrowConflictExceptionIfSingleExpectationInUrlIsWrong.
@Test
@SubjectAware(username = "slarti", password = "secret")
public void shouldThrowConflictExceptionIfSingleExpectationInUrlIsWrong() 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=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 com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class CommentRootResourceTest method shouldThrowConflictExceptionIfSourceRevisionNotEqualPullRequestSourceRevision.
@Test
@SubjectAware(username = "slarti", password = "secret")
public void shouldThrowConflictExceptionIfSourceRevisionNotEqualPullRequestSourceRevision() 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=other&targetRevision=target").content(commentJson).contentType(MediaType.APPLICATION_JSON);
dispatcher.invoke(request, response);
assertEquals(HttpServletResponse.SC_CONFLICT, response.getStatus());
assertThat(response.getContentAsString()).contains("modified concurrently");
}
use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class CommentRootResourceTest method shouldEmbedTransitions.
@Test
@SubjectAware(username = "slarti", password = "secret")
public void shouldEmbedTransitions() throws URISyntaxException, IOException {
mockExistingComments();
Comment commentWithTransitions = service.get("space", "name", "1", "1");
commentWithTransitions.addCommentTransition(new ExecutedTransition<>("1", CommentTransition.MAKE_TASK, System.currentTimeMillis(), "slarti"));
commentWithTransitions.addCommentTransition(new ExecutedTransition<>("2", CommentTransition.SET_DONE, System.currentTimeMillis(), "dent"));
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());
System.out.println(response.getContentAsString());
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readValue(response.getContentAsString(), JsonNode.class);
JsonNode prNode = jsonNode.get("_embedded").get("pullRequestComments").get(0);
JsonNode embeddedTransitionsNode = prNode.get("_embedded").get("transitions");
JsonNode transition_1 = embeddedTransitionsNode.path(0);
JsonNode transition_2 = embeddedTransitionsNode.path(1);
assertThat(transition_1.get("transition").asText()).isEqualTo("MAKE_TASK");
assertThat(transition_1.get("user").get("id").asText()).isEqualTo("slarti");
assertThat(transition_2.get("transition").asText()).isEqualTo("SET_DONE");
assertThat(transition_2.get("user").get("id").asText()).isEqualTo("dent");
}
use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class CommentRootResourceTest method shouldGetAllComments.
@Test
@SubjectAware(username = "slarti", password = "secret")
public void shouldGetAllComments() 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("comment").asText()).isEqualTo("1. comment");
assertThat(comment_1.get("context").get("lines").size()).isEqualTo(3);
assertThat(comment_2.get("comment").asText()).isEqualTo("2. comment");
JsonNode replies = comment_2.get("_embedded").get("replies");
JsonNode reply_1 = replies.path(0);
JsonNode reply_2 = replies.path(1);
assertThat(reply_1.get("comment").asText()).isEqualTo("1. reply");
assertThat(reply_2.get("comment").asText()).isEqualTo("2. reply");
}
use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class CommentRootResourceTest method shouldGetCreateLinkWithRevisions.
@Test
@SubjectAware(username = "slarti", password = "secret")
public void shouldGetCreateLinkWithRevisions() 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 createLinkNode = jsonNode.get("_links").get("create").get("href");
assertThat(createLinkNode.asText()).isEqualTo("/v2/pull-requests/space/name/1/comments/?sourceRevision=source&targetRevision=target");
}
Aggregations