Search in sources :

Example 16 with NamespaceAndName

use of sonia.scm.repository.NamespaceAndName 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 + "\"");
}
Also used : 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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 17 with NamespaceAndName

use of sonia.scm.repository.NamespaceAndName 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.*");
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) NamespaceAndName(sonia.scm.repository.NamespaceAndName) NotFoundException(sonia.scm.NotFoundException) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 18 with NamespaceAndName

use of sonia.scm.repository.NamespaceAndName in project scm-review-plugin by scm-manager.

the class MergeServiceTest method shouldNotMergeWithObstaclesIfNotEmergency.

@Test
void shouldNotMergeWithObstaclesIfNotEmergency() {
    PullRequest pullRequest = mockPullRequest("squash", "master", "1");
    mockMergeGuard(pullRequest, true);
    MergeCommitDto mergeCommit = createMergeCommit(false);
    NamespaceAndName namespaceAndName = REPOSITORY.getNamespaceAndName();
    assertThrows(MergeNotAllowedException.class, () -> service.merge(namespaceAndName, "1", mergeCommit, MergeStrategy.SQUASH, false));
}
Also used : MergeCommitDto(com.cloudogu.scm.review.pullrequest.dto.MergeCommitDto) NamespaceAndName(sonia.scm.repository.NamespaceAndName) Test(org.junit.jupiter.api.Test)

Example 19 with NamespaceAndName

use of sonia.scm.repository.NamespaceAndName in project scm-review-plugin by scm-manager.

the class MergeServiceTest method shouldThrowExceptionIfStrategyNotSupported.

@Test
void shouldThrowExceptionIfStrategyNotSupported() {
    when(mergeCommandBuilder.isSupported(MergeStrategy.SQUASH)).thenReturn(false);
    mockPullRequest("squash", "master", "1");
    MergeCommitDto mergeCommit = createMergeCommit(false);
    NamespaceAndName namespaceAndName = REPOSITORY.getNamespaceAndName();
    assertThrows(MergeStrategyNotSupportedException.class, () -> service.merge(namespaceAndName, "1", mergeCommit, MergeStrategy.SQUASH, false));
}
Also used : MergeCommitDto(com.cloudogu.scm.review.pullrequest.dto.MergeCommitDto) NamespaceAndName(sonia.scm.repository.NamespaceAndName) Test(org.junit.jupiter.api.Test)

Example 20 with NamespaceAndName

use of sonia.scm.repository.NamespaceAndName 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)

Aggregations

NamespaceAndName (sonia.scm.repository.NamespaceAndName)35 Repository (sonia.scm.repository.Repository)15 PullRequest (com.cloudogu.scm.review.pullrequest.service.PullRequest)11 Operation (io.swagger.v3.oas.annotations.Operation)10 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)10 Path (javax.ws.rs.Path)10 MockHttpRequest (org.jboss.resteasy.mock.MockHttpRequest)8 Test (org.junit.jupiter.api.Test)8 Produces (javax.ws.rs.Produces)7 MergeCommitDto (com.cloudogu.scm.review.pullrequest.dto.MergeCommitDto)6 SubjectAware (com.github.sdorra.shiro.SubjectAware)6 GET (javax.ws.rs.GET)6 Comment (com.cloudogu.scm.review.comment.service.Comment)5 Consumes (javax.ws.rs.Consumes)5 Test (org.junit.Test)5 TestData.createPullRequest (com.cloudogu.scm.review.TestData.createPullRequest)4 BranchRevisionResolver (com.cloudogu.scm.review.pullrequest.dto.BranchRevisionResolver)3 POST (javax.ws.rs.POST)3 NotFoundException (sonia.scm.NotFoundException)3 PermissionCheck (com.cloudogu.scm.review.PermissionCheck)2