Search in sources :

Example 1 with JsonMockHttpResponse

use of sonia.scm.web.JsonMockHttpResponse 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 2 with JsonMockHttpResponse

use of sonia.scm.web.JsonMockHttpResponse 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 3 with JsonMockHttpResponse

use of sonia.scm.web.JsonMockHttpResponse in project scm-review-plugin by scm-manager.

the class MergeResourceTest method shouldNotSetCommitAuthorForNonSquash.

@Test
void shouldNotSetCommitAuthorForNonSquash() throws URISyntaxException {
    when(mergeService.createCommitDefaults(any(), any(), eq(MERGE_COMMIT))).thenReturn(new CommitDefaults("happy days", null));
    MockHttpRequest request = createHttpGetRequest(MERGE_URL + "/merge-strategy-info/?strategy=MERGE_COMMIT");
    JsonMockHttpResponse response = new JsonMockHttpResponse();
    dispatcher.invoke(request, response);
    JsonNode jsonResponse = response.getContentAsJson();
    assertThat(jsonResponse.get("commitAuthor")).isNull();
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) 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)

Aggregations

CommitDefaults (com.cloudogu.scm.review.pullrequest.service.MergeService.CommitDefaults)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 MockHttpRequest (org.jboss.resteasy.mock.MockHttpRequest)3 Test (org.junit.jupiter.api.Test)3 JsonMockHttpResponse (sonia.scm.web.JsonMockHttpResponse)3 DisplayUser (sonia.scm.user.DisplayUser)2 User (sonia.scm.user.User)2