use of com.cloudogu.scm.review.comment.service.Comment in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method createCommentWithType.
private Comment createCommentWithType(CommentType commentType) {
Comment comment = Comment.createComment("1", "trillian", "tricia", new Location());
comment.setType(commentType);
return comment;
}
use of com.cloudogu.scm.review.comment.service.Comment 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.cloudogu.scm.review.comment.service.Comment in project scm-review-plugin by scm-manager.
the class CommentResource method getComment.
@GET
@Path("")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(PullRequestMediaType.PULL_REQUEST)
@Operation(summary = "Pull request comment", description = "Returns a single pull request comment.", tags = "Pull Request Comment")
@ApiResponse(responseCode = "200", description = "success", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = CommentDto.class)))
@ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials")
@ApiResponse(responseCode = "403", description = "not authorized, the current user does not have the \"commentPullRequest\" privilege")
@ApiResponse(responseCode = "404", description = "not found, a comment with the given id is not available for this pull request")
@ApiResponse(responseCode = "500", description = "internal server error", content = @Content(mediaType = VndMediaType.ERROR_TYPE, schema = @Schema(implementation = ErrorDto.class)))
public CommentDto getComment(@PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("pullRequestId") String pullRequestId, @PathParam("commentId") String commentId, @QueryParam("sourceRevision") String expectedSourceRevision, @QueryParam("targetRevision") String expectedTargetRevision) {
checkRevision(branchRevisionResolver, namespace, name, pullRequestId, expectedSourceRevision, expectedTargetRevision);
Repository repository = repositoryResolver.resolve(new NamespaceAndName(namespace, name));
BranchRevisionResolver.RevisionResult revisions = branchRevisionResolver.getRevisions(namespace, name, pullRequestId);
Comment comment = service.get(namespace, name, pullRequestId, commentId);
Collection<CommentTransition> possibleTransitions = service.possibleTransitions(namespace, name, pullRequestId, comment.getId());
return commentMapper.map(comment, repository, pullRequestId, possibleTransitions, revisions);
}
use of com.cloudogu.scm.review.comment.service.Comment 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.cloudogu.scm.review.comment.service.Comment in project scm-review-plugin by scm-manager.
the class CommentResourceTest method shouldUpdateComment.
@Test
public void shouldUpdateComment() throws URISyntaxException {
String newComment = "haha";
byte[] pullRequestCommentJson = ("{\"comment\" : \"" + newComment + "\"}").getBytes();
MockHttpRequest request = MockHttpRequest.put("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/space/name/1/comments/1").content(pullRequestCommentJson).contentType(MediaType.APPLICATION_JSON);
dispatcher.invoke(request, response);
assertEquals(HttpServletResponse.SC_NO_CONTENT, response.getStatus());
verify(service).modifyComment(eq("space"), eq("name"), eq("1"), eq("1"), argThat((Comment t) -> t.getComment().equals(newComment)));
}
Aggregations