use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class CommentRootResourceTest method shouldGetAllLinks.
@Test
@SubjectAware(username = "slarti", password = "secret")
public void shouldGetAllLinks() 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("_links").get("self").get("href").asText()).isEqualTo("/v2/pull-requests/space/name/1/comments/1");
assertThat(comment_2.get("_links").get("self").get("href").asText()).isEqualTo("/v2/pull-requests/space/name/1/comments/2");
assertThat(comment_1.get("_links").get("update").get("href").asText()).isEqualTo("/v2/pull-requests/space/name/1/comments/1");
assertThat(comment_2.get("_links").get("update").get("href").asText()).isEqualTo("/v2/pull-requests/space/name/1/comments/2");
assertThat(comment_1.get("_links").get("delete").get("href").asText()).isEqualTo("/v2/pull-requests/space/name/1/comments/1");
// must not delete comment with responses
assertThat(comment_2.get("_links").get("delete")).isNull();
// root comments have reply links
assertThat(comment_1.get("_links").get("reply").get("href").asText()).isEqualTo("/v2/pull-requests/space/name/1/comments/1/reply");
assertThat(comment_2.get("_links").get("reply").get("href").asText()).isEqualTo("/v2/pull-requests/space/name/1/comments/2/reply");
JsonNode replies = comment_2.get("_embedded").get("replies");
JsonNode reply_1 = replies.path(0);
JsonNode reply_2 = replies.path(1);
assertThat(reply_1.get("_links").get("self").get("href").asText()).isEqualTo("/v2/pull-requests/space/name/1/comments/2/replies/2_1");
assertThat(reply_2.get("_links").get("self").get("href").asText()).isEqualTo("/v2/pull-requests/space/name/1/comments/2/replies/2_2");
assertThat(reply_1.get("_links").get("update").get("href").asText()).isEqualTo("/v2/pull-requests/space/name/1/comments/2/replies/2_1");
assertThat(reply_2.get("_links").get("update").get("href").asText()).isEqualTo("/v2/pull-requests/space/name/1/comments/2/replies/2_2");
assertThat(reply_1.get("_links").get("delete").get("href").asText()).isEqualTo("/v2/pull-requests/space/name/1/comments/2/replies/2_1");
assertThat(reply_2.get("_links").get("delete").get("href").asText()).isEqualTo("/v2/pull-requests/space/name/1/comments/2/replies/2_2");
// replies no longer have a reply link
assertThat(reply_1.get("_links").get("reply")).isNull();
assertThat(reply_2.get("_links").get("reply")).isNull();
}
use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class CommentRootResourceTest method shouldThrowConflictExceptionIfTargetRevisionNotEqualPullRequestTargetRevision.
@Test
@SubjectAware(username = "slarti", password = "secret")
public void shouldThrowConflictExceptionIfTargetRevisionNotEqualPullRequestTargetRevision() 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=source&targetRevision=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 shouldCreateNewComment.
@Test
@SubjectAware(username = "slarti", password = "secret")
public void shouldCreateNewComment() throws URISyntaxException {
when(pullRequestService.get(any(), any(), any())).thenReturn(PULL_REQUEST);
when(service.add(eq(REPOSITORY_NAMESPACE), eq(REPOSITORY_NAME), eq("1"), argThat(t -> t.getComment().equals("this is my comment")))).thenReturn("1");
byte[] commentJson = "{\"comment\" : \"this is my comment\"}".getBytes();
MockHttpRequest request = MockHttpRequest.post("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/space/name/1/comments?sourceRevision=source&targetRevision=target").content(commentJson).contentType(MediaType.APPLICATION_JSON);
dispatcher.invoke(request, response);
assertEquals(HttpServletResponse.SC_CREATED, response.getStatus());
assertThat(response.getOutputHeaders().getFirst("Location")).hasToString("/v2/pull-requests/space/name/1/comments/1");
}
use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class RepositoryLinkEnricherTest method shouldNotEnrichBecauseOfMissingPermission.
@Test
@SubjectAware(username = "trillian", password = "secret")
public void shouldNotEnrichBecauseOfMissingPermission() {
enricher = new RepositoryLinkEnricher(scmPathInfoStoreProvider, pullRequestService, configService, globalEngineConfigurator);
Repository repo = new Repository("id", "type", "space", "name");
HalEnricherContext context = HalEnricherContext.of(repo);
enricher.enrich(context, appender);
verify(appender, never()).appendLink(any(), any());
}
use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class RepositoryLinkEnricherTest method shouldEnrichWorkflowConfigLink.
@Test
@SubjectAware(username = "dent", password = "secret")
public void shouldEnrichWorkflowConfigLink() {
when(pullRequestService.supportsPullRequests(any())).thenReturn(true);
mockGlobalConfig(true);
enricher = new RepositoryLinkEnricher(scmPathInfoStoreProvider, pullRequestService, configService, globalEngineConfigurator);
Repository repo = new Repository("id", "type", "space", "name");
HalEnricherContext context = HalEnricherContext.of(repo);
enricher.enrich(context, appender);
verify(appender).appendLink("workflowConfig", "https://scm-manager.org/scm/api/v2/workflow/space/name/config");
}
Aggregations