Search in sources :

Example 96 with MockHttpRequest

use of org.jboss.resteasy.mock.MockHttpRequest 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 97 with MockHttpRequest

use of org.jboss.resteasy.mock.MockHttpRequest 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 98 with MockHttpRequest

use of org.jboss.resteasy.mock.MockHttpRequest in project scm-review-plugin by scm-manager.

the class EngineResultResourceTest method shouldGetEmptyResultWithoutRules.

@Test
void shouldGetEmptyResultWithoutRules() throws URISyntaxException, UnsupportedEncodingException, JsonProcessingException {
    when(engine.validate(REPOSITORY, PULL_REQUEST)).thenReturn(new Results(emptyList()));
    MockHttpRequest request = MockHttpRequest.get("/v2/pull-requests/space/X/42/workflow");
    dispatcher.invoke(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    JsonNode jsonNode = getJsonNode();
    JsonNode results = jsonNode.get("results");
    assertThat(results).isNotNull();
    assertThat(results.size()).isEqualTo(0);
    JsonNode links = jsonNode.get("_links");
    assertThat(links).isNotNull();
    assertThat(links.get("self")).isNotNull();
    assertThat(links.get("self").get("href")).isNotNull();
    assertThat(links.get("self").get("href").asText()).isEqualTo("/v2/pull-requests/space/X/42/workflow/");
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.jupiter.api.Test)

Example 99 with MockHttpRequest

use of org.jboss.resteasy.mock.MockHttpRequest in project scm-review-plugin by scm-manager.

the class GlobalEngineConfigResourceTest method shouldReturnConfigurationWithUpdateLink.

@Test
void shouldReturnConfigurationWithUpdateLink() throws URISyntaxException, UnsupportedEncodingException {
    when(configurator.getEngineConfiguration()).thenReturn(new GlobalEngineConfiguration(ImmutableList.of(AppliedRule.of(SuccessRule.class)), true, false));
    when(subject.isPermitted("configuration:write:workflowConfig")).thenReturn(true);
    MockHttpRequest request = MockHttpRequest.get("/v2/workflow/config");
    dispatcher.invoke(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getContentAsString()).contains("\"update\":{\"href\":\"/v2/workflow/config\"}").contains("\"availableRules\":{\"href\":\"/v2/workflow/rules\"}");
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) Test(org.junit.jupiter.api.Test)

Example 100 with MockHttpRequest

use of org.jboss.resteasy.mock.MockHttpRequest in project scm-review-plugin by scm-manager.

the class GlobalEngineConfigResourceTest method shouldReturnConfiguration.

@Test
void shouldReturnConfiguration() throws URISyntaxException, UnsupportedEncodingException {
    when(configurator.getEngineConfiguration()).thenReturn(new GlobalEngineConfiguration(ImmutableList.of(AppliedRule.of(SuccessRule.class)), true, false));
    when(subject.isPermitted("configuration:write:workflowConfig")).thenReturn(true);
    MockHttpRequest request = MockHttpRequest.get("/v2/workflow/config");
    dispatcher.invoke(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getContentAsString()).contains("\"rules\":[{\"rule\":\"SuccessRule\"}]").contains("\"enabled\":true").contains("\"self\":{\"href\":\"/v2/workflow/config\"}");
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) Test(org.junit.jupiter.api.Test)

Aggregations

MockHttpRequest (org.jboss.resteasy.mock.MockHttpRequest)108 Test (org.junit.Test)64 SubjectAware (com.github.sdorra.shiro.SubjectAware)46 Test (org.junit.jupiter.api.Test)41 JsonNode (com.fasterxml.jackson.databind.JsonNode)29 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)24 PullRequest (com.cloudogu.scm.review.pullrequest.service.PullRequest)17 TestData.createPullRequest (com.cloudogu.scm.review.TestData.createPullRequest)16 DisplayUser (sonia.scm.user.DisplayUser)16 User (sonia.scm.user.User)16 MockHttpResponse (org.jboss.resteasy.mock.MockHttpResponse)14 NamespaceAndName (sonia.scm.repository.NamespaceAndName)13 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 Repository (sonia.scm.repository.Repository)9 Comment (com.cloudogu.scm.review.comment.service.Comment)8 BranchRevisionResolver (com.cloudogu.scm.review.pullrequest.dto.BranchRevisionResolver)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)8 URISyntaxException (java.net.URISyntaxException)8 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)8 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)8