Search in sources :

Example 21 with MockHttpRequest

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

the class MergeResourceTest method shouldGetSquashMergeStrategyInfoWithoutMail.

@Test
void shouldGetSquashMergeStrategyInfoWithoutMail() throws URISyntaxException {
    when(mergeService.createCommitDefaults(any(), any(), eq(SQUASH))).thenReturn(new CommitDefaults("happy days", DisplayUser.from(new User("Arthur Dent"))));
    when(mergeService.isCommitMessageDisabled(SQUASH)).thenReturn(true);
    when(mergeService.createMergeCommitMessageHint(SQUASH)).thenReturn(null);
    MockHttpRequest request = createHttpGetRequest(MERGE_URL + "/merge-strategy-info/?strategy=SQUASH");
    JsonMockHttpResponse response = new JsonMockHttpResponse();
    dispatcher.invoke(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    JsonNode jsonResponse = response.getContentAsJson();
    assertThat(jsonResponse.get("commitMessageDisabled").asBoolean()).isTrue();
    assertThat(jsonResponse.get("defaultCommitMessage").asText()).isEqualTo("happy days");
    assertThat(jsonResponse.get("commitAuthor").asText()).isEqualTo("Arthur Dent");
    assertThat(jsonResponse.get("commitMessageHint")).isNull();
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) DisplayUser(sonia.scm.user.DisplayUser) User(sonia.scm.user.User) JsonMockHttpResponse(sonia.scm.web.JsonMockHttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) CommitDefaults(com.cloudogu.scm.review.pullrequest.service.MergeService.CommitDefaults) Test(org.junit.jupiter.api.Test)

Example 22 with MockHttpRequest

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

the class MergeResourceTest method shouldGetSquashMergeStrategyInfoWithMail.

@Test
void shouldGetSquashMergeStrategyInfoWithMail() throws URISyntaxException {
    when(mergeService.createCommitDefaults(any(), any(), eq(SQUASH))).thenReturn(new CommitDefaults("happy days", DisplayUser.from(new User("dent", "Arthur Dent", "arthur@hitchhiker.com"))));
    MockHttpRequest request = createHttpGetRequest(MERGE_URL + "/merge-strategy-info/?strategy=SQUASH");
    JsonMockHttpResponse response = new JsonMockHttpResponse();
    dispatcher.invoke(request, response);
    JsonNode jsonResponse = response.getContentAsJson();
    assertThat(jsonResponse.get("commitAuthor").asText()).isEqualTo("Arthur Dent <arthur@hitchhiker.com>");
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) DisplayUser(sonia.scm.user.DisplayUser) User(sonia.scm.user.User) JsonMockHttpResponse(sonia.scm.web.JsonMockHttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) CommitDefaults(com.cloudogu.scm.review.pullrequest.service.MergeService.CommitDefaults) Test(org.junit.jupiter.api.Test)

Example 23 with MockHttpRequest

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

the class MergeResourceTest method shouldHandleFailedDryRun.

@Test
void shouldHandleFailedDryRun() throws IOException, URISyntaxException {
    when(mergeService.checkMerge(any(), any())).thenReturn(new MergeCheckResult(true, emptyList()));
    byte[] mergeCommandJson = loadJson("com/cloudogu/scm/review/mergeCommand.json");
    MockHttpRequest request = createHttpPostRequest(MERGE_URL + "/merge-check", mergeCommandJson);
    MockHttpResponse response = new MockHttpResponse();
    dispatcher.invoke(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getContentAsString()).contains("\"hasConflicts\":true");
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) MergeCheckResult(com.cloudogu.scm.review.pullrequest.service.MergeCheckResult) MockHttpResponse(org.jboss.resteasy.mock.MockHttpResponse) JsonMockHttpResponse(sonia.scm.web.JsonMockHttpResponse) Test(org.junit.jupiter.api.Test)

Example 24 with MockHttpRequest

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

the class PullRequestRootResourceTest method shouldGetUnauthorizedExceptionWhenMissingPermissionOnGetAllPR.

@Test
@SubjectAware(username = "trillian")
public void shouldGetUnauthorizedExceptionWhenMissingPermissionOnGetAllPR() throws URISyntaxException {
    MockHttpRequest request = MockHttpRequest.get("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/" + REPOSITORY_NAMESPACE + "/" + REPOSITORY_NAME + "");
    dispatcher.invoke(request, response);
    assertEquals(HttpServletResponse.SC_FORBIDDEN, response.getStatus());
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 25 with MockHttpRequest

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

the class PullRequestRootResourceTest method shouldGetUnauthorizedExceptionWhenMissingPermissionOnGetPR.

@Test
@SubjectAware(username = "trillian")
public void shouldGetUnauthorizedExceptionWhenMissingPermissionOnGetPR() throws URISyntaxException {
    MockHttpRequest request = MockHttpRequest.get("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/" + REPOSITORY_NAMESPACE + "/" + REPOSITORY_NAME + "/123");
    dispatcher.invoke(request, response);
    assertEquals(HttpServletResponse.SC_FORBIDDEN, response.getStatus());
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

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