use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class CommentRootResourceTest method shouldGetOnlyTheSelfLinkÍfTheAuthorIsNotTheCurrentUser.
@Test
@SubjectAware(username = "createCommentUser", password = "secret")
public void shouldGetOnlyTheSelfLinkÍfTheAuthorIsNotTheCurrentUser() 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")).isNull();
assertThat(comment_2.get("_links").get("update")).isNull();
assertThat(comment_1.get("_links").get("delete")).isNull();
assertThat(comment_2.get("_links").get("delete")).isNull();
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")).isNull();
assertThat(reply_2.get("_links").get("update")).isNull();
assertThat(reply_1.get("_links").get("delete")).isNull();
assertThat(reply_2.get("_links").get("delete")).isNull();
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 RepositoryLinkEnricherTest method shouldNotEnrichRepositoriesForConfigWhenRepositoryConfigIsDisabled.
@Test
@SubjectAware(username = "dent", password = "secret")
public void shouldNotEnrichRepositoriesForConfigWhenRepositoryConfigIsDisabled() {
enricher = new RepositoryLinkEnricher(scmPathInfoStoreProvider, pullRequestService, configService, globalEngineConfigurator);
when(pullRequestService.supportsPullRequests(any())).thenReturn(true);
mockGlobalConfig(true);
Repository repo = new Repository("id", "type", "space", "name");
HalEnricherContext context = HalEnricherContext.of(repo);
enricher.enrich(context, appender);
verify(appender).appendLink("pullRequest", "https://scm-manager.org/scm/api/v2/pull-requests/space/name");
verify(appender, never()).appendLink(eq("pullRequestConfig"), any());
}
use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class RepositoryLinkEnricherTest method shouldEnrichPullRequestCheckLink.
@Test
@SubjectAware(username = "dent", password = "secret")
public void shouldEnrichPullRequestCheckLink() {
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("pullRequestCheck", "https://scm-manager.org/scm/api/v2/pull-requests/space/name/check");
}
use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class CommentServiceTest method shouldMarkCommentAsOutdated.
@Test
@SubjectAware(username = "trillian")
public void shouldMarkCommentAsOutdated() {
doNothing().when(store).update(eq(PULL_REQUEST_ID), rootCommentCaptor.capture());
Comment comment = EXISTING_COMMENT.clone();
commentService.markAsOutdated(NAMESPACE, NAME, PULL_REQUEST_ID, comment.getId());
assertThat(rootCommentCaptor.getAllValues()).hasSize(1);
Comment storedComment = rootCommentCaptor.getValue();
assertThat(storedComment.isOutdated()).isTrue();
}
use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.
the class CommentServiceTest method shouldAddCommentOnRejectEventByDeletedBranch.
@Test
@SubjectAware(username = "dent")
public void shouldAddCommentOnRejectEventByDeletedBranch() {
PullRequest pullRequest = mockPullRequest();
when(store.add(eq(PULL_REQUEST_ID), rootCommentCaptor.capture())).thenReturn("newId");
commentService.addCommentOnReject(new PullRequestRejectedEvent(REPOSITORY, pullRequest, PullRequestRejectedEvent.RejectionCause.BRANCH_DELETED));
assertThat(rootCommentCaptor.getAllValues()).hasSize(1);
Comment storedComment = rootCommentCaptor.getValue();
assertThat(storedComment.getComment()).isEqualTo("sourceDeleted");
}
Aggregations