Search in sources :

Example 71 with PullRequest

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

the class PullRequestRootResourceTest method shouldGetTheUnsubscribeLink.

@Test
public void shouldGetTheUnsubscribeLink() throws URISyntaxException, IOException {
    PullRequest pullRequest = createPullRequest();
    pullRequest.setSubscriber(singleton("user1"));
    when(store.get("1")).thenReturn(pullRequest);
    mockLoggedInUser(new User("user1", "User 1", "email@d.de"));
    MockHttpRequest request = MockHttpRequest.get("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo/1/subscription");
    dispatcher.invoke(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonNode = mapper.readValue(response.getContentAsString(), JsonNode.class);
    assertThat(jsonNode.path("_links").get("subscribe")).isNull();
    assertThat(jsonNode.path("_links").get("unsubscribe")).isNotNull();
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) DisplayUser(sonia.scm.user.DisplayUser) User(sonia.scm.user.User) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) TestData.createPullRequest(com.cloudogu.scm.review.TestData.createPullRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 72 with PullRequest

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

the class PullRequestRootResourceTest method shouldGetTheApproveButNoSubscriptionLinkWithoutMail.

@Test
public void shouldGetTheApproveButNoSubscriptionLinkWithoutMail() throws URISyntaxException, IOException {
    PullRequest pullRequest = createPullRequest();
    when(store.get("1")).thenReturn(pullRequest);
    mockLoggedInUser(new User("user1", "User 1", null));
    MockHttpRequest request = MockHttpRequest.get("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo/1");
    dispatcher.invoke(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonNode = mapper.readValue(response.getContentAsString(), JsonNode.class);
    assertThat(jsonNode.path("_links").get("approve")).isNotNull();
    assertThat(jsonNode.path("_links").get("subscription")).isNull();
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) DisplayUser(sonia.scm.user.DisplayUser) User(sonia.scm.user.User) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) TestData.createPullRequest(com.cloudogu.scm.review.TestData.createPullRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 73 with PullRequest

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

the class PullRequestRootResourceTest method shouldGetMarkAsReviewedLink.

@Test
@SubjectAware(username = "dent")
public void shouldGetMarkAsReviewedLink() throws URISyntaxException, IOException {
    PullRequest pullRequest = createPullRequest();
    when(store.get("1")).thenReturn(pullRequest);
    MockHttpRequest request = MockHttpRequest.get("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo/1");
    dispatcher.invoke(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonNode = mapper.readValue(response.getContentAsString(), JsonNode.class);
    assertThat(jsonNode.path("_links").get("reviewMark")).isNotNull();
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) TestData.createPullRequest(com.cloudogu.scm.review.TestData.createPullRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 74 with PullRequest

use of com.cloudogu.scm.review.pullrequest.service.PullRequest 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)

Example 75 with PullRequest

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

the class PullRequestMapperTest method shouldAppendSourceAndTargetBranchLinks.

@Test
void shouldAppendSourceAndTargetBranchLinks() {
    String sourceLink = "/api/v2/source";
    String targetLink = "/api/v2/target";
    when(branchLinkProvider.get(REPOSITORY.getNamespaceAndName(), "develop")).thenReturn(sourceLink);
    when(branchLinkProvider.get(REPOSITORY.getNamespaceAndName(), "master")).thenReturn(targetLink);
    PullRequest pullRequest = TestData.createPullRequest();
    PullRequestDto dto = mapper.map(pullRequest, REPOSITORY);
    assertThat(dto.getLinks().isEmpty()).isFalse();
    Optional<Link> sourceBranch = dto.getLinks().getLinkBy("sourceBranch");
    assertThat(sourceBranch).isPresent();
    assertThat(sourceBranch.get().getHref()).isEqualTo(sourceLink);
    Optional<Link> targetBranch = dto.getLinks().getLinkBy("targetBranch");
    assertThat(targetBranch).isPresent();
    assertThat(targetBranch.get().getHref()).isEqualTo(targetLink);
}
Also used : PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Link(de.otto.edison.hal.Link) Test(org.junit.jupiter.api.Test)

Aggregations

PullRequest (com.cloudogu.scm.review.pullrequest.service.PullRequest)82 Repository (sonia.scm.repository.Repository)27 Test (org.junit.jupiter.api.Test)20 Test (org.junit.Test)18 TestData.createPullRequest (com.cloudogu.scm.review.TestData.createPullRequest)17 MockHttpRequest (org.jboss.resteasy.mock.MockHttpRequest)16 Subscribe (com.github.legman.Subscribe)13 SubjectAware (com.github.sdorra.shiro.SubjectAware)13 NamespaceAndName (sonia.scm.repository.NamespaceAndName)13 User (sonia.scm.user.User)11 DisplayUser (sonia.scm.user.DisplayUser)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 Optional (java.util.Optional)7 Comment (com.cloudogu.scm.review.comment.service.Comment)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 PermissionCheck (com.cloudogu.scm.review.PermissionCheck)5 PullRequestService (com.cloudogu.scm.review.pullrequest.service.PullRequestService)5 Operation (io.swagger.v3.oas.annotations.Operation)5 List (java.util.List)5