Search in sources :

Example 11 with Comment

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;
}
Also used : Comment(com.cloudogu.scm.review.comment.service.Comment) Location(com.cloudogu.scm.review.comment.service.Location)

Example 12 with 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");
}
Also used : Comment(com.cloudogu.scm.review.comment.service.Comment) MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) NamespaceAndName(sonia.scm.repository.NamespaceAndName) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) TestData.createPullRequest(com.cloudogu.scm.review.TestData.createPullRequest) ArrayList(java.util.ArrayList) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 13 with Comment

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);
}
Also used : CommentTransition(com.cloudogu.scm.review.comment.service.CommentTransition) Comment(com.cloudogu.scm.review.comment.service.Comment) Repository(sonia.scm.repository.Repository) NamespaceAndName(sonia.scm.repository.NamespaceAndName) BranchRevisionResolver(com.cloudogu.scm.review.pullrequest.dto.BranchRevisionResolver) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse)

Example 14 with Comment

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");
}
Also used : Comment(com.cloudogu.scm.review.comment.service.Comment) Comment.createComment(com.cloudogu.scm.review.comment.service.Comment.createComment) MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 15 with Comment

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)));
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) Comment(com.cloudogu.scm.review.comment.service.Comment) Comment.createComment(com.cloudogu.scm.review.comment.service.Comment.createComment) Test(org.junit.Test)

Aggregations

Comment (com.cloudogu.scm.review.comment.service.Comment)18 Repository (sonia.scm.repository.Repository)7 Comment.createComment (com.cloudogu.scm.review.comment.service.Comment.createComment)6 BranchRevisionResolver (com.cloudogu.scm.review.pullrequest.dto.BranchRevisionResolver)6 MockHttpRequest (org.jboss.resteasy.mock.MockHttpRequest)6 Test (org.junit.Test)6 Location (com.cloudogu.scm.review.comment.service.Location)5 Reply (com.cloudogu.scm.review.comment.service.Reply)5 PullRequest (com.cloudogu.scm.review.pullrequest.service.PullRequest)5 Operation (io.swagger.v3.oas.annotations.Operation)5 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)5 Path (javax.ws.rs.Path)5 NamespaceAndName (sonia.scm.repository.NamespaceAndName)5 RepositoryResolver (com.cloudogu.scm.review.RepositoryResolver)4 CommentService (com.cloudogu.scm.review.comment.service.CommentService)4 PullRequestService (com.cloudogu.scm.review.pullrequest.service.PullRequestService)4 GET (javax.ws.rs.GET)4 Produces (javax.ws.rs.Produces)4 MediaType (javax.ws.rs.core.MediaType)4 UriBuilder (javax.ws.rs.core.UriBuilder)4