Search in sources :

Example 11 with SubjectAware

use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.

the class RepositoryLinkEnricherTest method shouldNotEnrichRepositoriesWithoutBranchSupport.

@Test
@SubjectAware(username = "dent", password = "secret")
public void shouldNotEnrichRepositoriesWithoutBranchSupport() {
    enricher = new RepositoryLinkEnricher(scmPathInfoStoreProvider, pullRequestService, configService, globalEngineConfigurator);
    when(pullRequestService.supportsPullRequests(any())).thenReturn(false);
    Repository repo = new Repository("id", "type", "space", "name");
    HalEnricherContext context = HalEnricherContext.of(repo);
    enricher.enrich(context, appender);
    verify(appender, never()).appendLink(any(), any());
}
Also used : Repository(sonia.scm.repository.Repository) HalEnricherContext(sonia.scm.api.v2.resources.HalEnricherContext) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 12 with SubjectAware

use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.

the class RepositoryLinkEnricherTest method shouldEnrichRepositoriesWithBranchSupport.

@Test
@SubjectAware(username = "dent", password = "secret")
public void shouldEnrichRepositoriesWithBranchSupport() {
    enricher = new RepositoryLinkEnricher(scmPathInfoStoreProvider, pullRequestService, configService, globalEngineConfigurator);
    when(pullRequestService.supportsPullRequests(any())).thenReturn(true);
    mockGlobalConfig(false);
    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).appendLink("pullRequestConfig", "https://scm-manager.org/scm/api/v2/pull-requests/space/name/config");
}
Also used : Repository(sonia.scm.repository.Repository) HalEnricherContext(sonia.scm.api.v2.resources.HalEnricherContext) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 13 with SubjectAware

use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.

the class CommentServiceTest method shouldNotMarkAlreadyOutdatedComments.

@Test
@SubjectAware(username = "dent")
public void shouldNotMarkAlreadyOutdatedComments() {
    Comment comment = EXISTING_COMMENT.clone();
    comment.setOutdated(true);
    when(store.getAll(PULL_REQUEST_ID)).thenReturn(singletonList(comment));
    commentService.markAsOutdated(NAMESPACE, NAME, PULL_REQUEST_ID, comment.getId());
    verify(store, never()).update(any(), any());
}
Also used : Comment.createComment(com.cloudogu.scm.review.comment.service.Comment.createComment) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 14 with SubjectAware

use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.

the class CommentServiceTest method shouldFailIfUserHasNoPermissionTocreateReply.

@Test(expected = UnauthorizedException.class)
@SubjectAware(username = "trillian")
public void shouldFailIfUserHasNoPermissionTocreateReply() {
    Reply reply = createReply("1", "1. comment", author);
    commentService.reply(NAMESPACE, NAME, PULL_REQUEST_ID, "1", reply);
}
Also used : Reply.createReply(com.cloudogu.scm.review.comment.service.Reply.createReply) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 15 with SubjectAware

use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.

the class CommentServiceTest method shouldFailModifyingRootCommentWhenUserHasNoPermission.

@Test(expected = UnauthorizedException.class)
@SubjectAware(username = "createCommentUser")
public void shouldFailModifyingRootCommentWhenUserHasNoPermission() {
    Comment changedRootComment = EXISTING_COMMENT.clone();
    commentService.modifyComment(NAMESPACE, NAME, PULL_REQUEST_ID, EXISTING_COMMENT.getId(), changedRootComment);
}
Also used : Comment.createComment(com.cloudogu.scm.review.comment.service.Comment.createComment) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Aggregations

SubjectAware (com.github.sdorra.shiro.SubjectAware)91 Test (org.junit.Test)91 MockHttpRequest (org.jboss.resteasy.mock.MockHttpRequest)45 Comment.createComment (com.cloudogu.scm.review.comment.service.Comment.createComment)27 JsonNode (com.fasterxml.jackson.databind.JsonNode)18 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)16 PullRequest (com.cloudogu.scm.review.pullrequest.service.PullRequest)14 Reply.createReply (com.cloudogu.scm.review.comment.service.Reply.createReply)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 TestData.createPullRequest (com.cloudogu.scm.review.TestData.createPullRequest)11 Repository (sonia.scm.repository.Repository)9 BasicComment (com.cloudogu.scm.review.comment.service.BasicComment)6 BranchRevisionResolver (com.cloudogu.scm.review.pullrequest.dto.BranchRevisionResolver)6 HalEnricherContext (sonia.scm.api.v2.resources.HalEnricherContext)6 NamespaceAndName (sonia.scm.repository.NamespaceAndName)6 DisplayUser (sonia.scm.user.DisplayUser)6 User (sonia.scm.user.User)6 Changeset (sonia.scm.repository.Changeset)5 Comment (com.cloudogu.scm.review.comment.service.Comment)4 ShiroRule (com.github.sdorra.shiro.ShiroRule)3