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 + "\"");
}
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.*");
}
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));
}
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));
}
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);
}
Aggregations