Search in sources :

Example 1 with REJECTED

use of com.cloudogu.scm.review.pullrequest.service.PullRequestStatus.REJECTED in project scm-review-plugin by scm-manager.

the class PullRequestRootResourceTest method shouldSetPullRequestToStatusRejected.

@Test
public void shouldSetPullRequestToStatusRejected() throws URISyntaxException {
    Subject subject = mock(Subject.class, RETURNS_DEEP_STUBS);
    shiroRule.setSubject(subject);
    User currentUser = new User("currentUser");
    when(subject.getPrincipals().oneByType(User.class)).thenReturn(currentUser);
    when(store.get("1")).thenReturn(createPullRequest("opened_1", PullRequestStatus.OPEN));
    when(branchResolver.resolve(any(), any())).thenReturn(Branch.normalBranch("master", "123"));
    MockHttpRequest request = MockHttpRequest.post("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo/1/reject");
    dispatcher.invoke(request, response);
    assertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_NO_CONTENT);
    verify(store).update(argThat(pullRequest -> {
        assertThat(pullRequest.getStatus()).isEqualTo(REJECTED);
        return true;
    }));
}
Also used : PullRequestMediaType(com.cloudogu.scm.review.PullRequestMediaType) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ShiroRule(com.github.sdorra.shiro.ShiroRule) URL(java.net.URL) RestDispatcher(sonia.scm.web.RestDispatcher) URISyntaxException(java.net.URISyntaxException) ScmEventBus(sonia.scm.event.ScmEventBus) DefaultPullRequestService(com.cloudogu.scm.review.pullrequest.service.DefaultPullRequestService) Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) PullRequestMapperImpl(com.cloudogu.scm.review.pullrequest.dto.PullRequestMapperImpl) Collections.singleton(java.util.Collections.singleton) Comment(com.cloudogu.scm.review.comment.service.Comment) Arrays.asList(java.util.Arrays.asList) After(org.junit.After) Duration(java.time.Duration) JsonNode(com.fasterxml.jackson.databind.JsonNode) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) RepositoryService(sonia.scm.repository.api.RepositoryService) PullRequestStore(com.cloudogu.scm.review.pullrequest.service.PullRequestStore) AssertionsForClassTypes.assertThat(org.assertj.core.api.AssertionsForClassTypes.assertThat) NotFoundException(sonia.scm.NotFoundException) RepositoryResolver(com.cloudogu.scm.review.RepositoryResolver) ImmutableSet(com.google.common.collect.ImmutableSet) Collections.emptyList(java.util.Collections.emptyList) Changeset(sonia.scm.repository.Changeset) ChannelRegistry(sonia.scm.sse.ChannelRegistry) Instant(java.time.Instant) MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) List(java.util.List) CommentService(com.cloudogu.scm.review.comment.service.CommentService) CommentType(com.cloudogu.scm.review.comment.service.CommentType) Lists(org.assertj.core.util.Lists) UserDisplayManager(sonia.scm.user.UserDisplayManager) REJECTED(com.cloudogu.scm.review.pullrequest.service.PullRequestStatus.REJECTED) Optional(java.util.Optional) Providers(com.google.inject.util.Providers) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) NamespaceAndName(sonia.scm.repository.NamespaceAndName) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PullRequestStatus(com.cloudogu.scm.review.pullrequest.service.PullRequestStatus) Mockito.mock(org.mockito.Mockito.mock) BranchResolver(com.cloudogu.scm.review.BranchResolver) Branch(sonia.scm.repository.Branch) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MockHttpResponse(org.jboss.resteasy.mock.MockHttpResponse) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Mockito.lenient(org.mockito.Mockito.lenient) DisplayUser(sonia.scm.user.DisplayUser) ArrayList(java.util.ArrayList) ChangesetPagingResult(sonia.scm.repository.ChangesetPagingResult) LogCommandBuilder(sonia.scm.repository.api.LogCommandBuilder) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) Subject(org.apache.shiro.subject.Subject) RepositoryServiceFactory(sonia.scm.repository.api.RepositoryServiceFactory) Collections.singletonMap(java.util.Collections.singletonMap) RETURNS_DEEP_STUBS(org.mockito.Mockito.RETURNS_DEEP_STUBS) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) Answers(org.mockito.Answers) BranchLinkProvider(sonia.scm.api.v2.resources.BranchLinkProvider) Resources(com.google.common.io.Resources) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpServletResponse(javax.servlet.http.HttpServletResponse) PullRequestStoreFactory(com.cloudogu.scm.review.pullrequest.service.PullRequestStoreFactory) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) User(sonia.scm.user.User) Mockito.verify(org.mockito.Mockito.verify) TestData.createPullRequest(com.cloudogu.scm.review.TestData.createPullRequest) Mockito.never(org.mockito.Mockito.never) SubjectAware(com.github.sdorra.shiro.SubjectAware) Rule(org.junit.Rule) ThreadContext(org.apache.shiro.util.ThreadContext) ReviewMark(com.cloudogu.scm.review.pullrequest.service.ReviewMark) Location(com.cloudogu.scm.review.comment.service.Location) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) DisplayUser(sonia.scm.user.DisplayUser) User(sonia.scm.user.User) Subject(org.apache.shiro.subject.Subject) Test(org.junit.Test)

Aggregations

BranchResolver (com.cloudogu.scm.review.BranchResolver)1 PullRequestMediaType (com.cloudogu.scm.review.PullRequestMediaType)1 RepositoryResolver (com.cloudogu.scm.review.RepositoryResolver)1 TestData.createPullRequest (com.cloudogu.scm.review.TestData.createPullRequest)1 Comment (com.cloudogu.scm.review.comment.service.Comment)1 CommentService (com.cloudogu.scm.review.comment.service.CommentService)1 CommentType (com.cloudogu.scm.review.comment.service.CommentType)1 Location (com.cloudogu.scm.review.comment.service.Location)1 PullRequestMapperImpl (com.cloudogu.scm.review.pullrequest.dto.PullRequestMapperImpl)1 DefaultPullRequestService (com.cloudogu.scm.review.pullrequest.service.DefaultPullRequestService)1 PullRequest (com.cloudogu.scm.review.pullrequest.service.PullRequest)1 PullRequestStatus (com.cloudogu.scm.review.pullrequest.service.PullRequestStatus)1 REJECTED (com.cloudogu.scm.review.pullrequest.service.PullRequestStatus.REJECTED)1 PullRequestStore (com.cloudogu.scm.review.pullrequest.service.PullRequestStore)1 PullRequestStoreFactory (com.cloudogu.scm.review.pullrequest.service.PullRequestStoreFactory)1 ReviewMark (com.cloudogu.scm.review.pullrequest.service.ReviewMark)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ShiroRule (com.github.sdorra.shiro.ShiroRule)1 SubjectAware (com.github.sdorra.shiro.SubjectAware)1