Search in sources :

Example 1 with CommitDefaults

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

the class MergeResourceTest method shouldGetRebaseMergeStrategyInfo.

@Test
void shouldGetRebaseMergeStrategyInfo() throws URISyntaxException, UnsupportedEncodingException {
    CommitDefaults commitDefaults = new CommitDefaults("happy days", DisplayUser.from(new User("Arthur Dent")));
    when(mergeService.createCommitDefaults(any(), any(), eq(REBASE))).thenReturn(commitDefaults);
    when(mergeService.isCommitMessageDisabled(REBASE)).thenReturn(true);
    when(mergeService.createMergeCommitMessageHint(REBASE)).thenReturn(null);
    MockHttpRequest request = createHttpGetRequest(MERGE_URL + "/merge-strategy-info/?strategy=REBASE");
    MockHttpResponse response = new MockHttpResponse();
    dispatcher.invoke(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getContentAsString()).contains("happy days").contains("true").doesNotContain("commitMessageHint");
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) DisplayUser(sonia.scm.user.DisplayUser) User(sonia.scm.user.User) CommitDefaults(com.cloudogu.scm.review.pullrequest.service.MergeService.CommitDefaults) MockHttpResponse(org.jboss.resteasy.mock.MockHttpResponse) JsonMockHttpResponse(sonia.scm.web.JsonMockHttpResponse) Test(org.junit.jupiter.api.Test)

Example 2 with CommitDefaults

use of com.cloudogu.scm.review.pullrequest.service.MergeService.CommitDefaults 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 3 with CommitDefaults

use of com.cloudogu.scm.review.pullrequest.service.MergeService.CommitDefaults 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 4 with CommitDefaults

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

the class MergeServiceTest method shouldOmitAuthorForNonSquash.

@Test
void shouldOmitAuthorForNonSquash() {
    PullRequest pullRequest = createPullRequest();
    when(pullRequestService.get(REPOSITORY.getNamespace(), REPOSITORY.getName(), "1")).thenReturn(pullRequest);
    CommitDefaults commitDefaults = service.createCommitDefaults(REPOSITORY.getNamespaceAndName(), "1", MergeStrategy.MERGE_COMMIT);
    assertThat(commitDefaults.getCommitAuthor()).isNull();
}
Also used : CommitDefaults(com.cloudogu.scm.review.pullrequest.service.MergeService.CommitDefaults) Test(org.junit.jupiter.api.Test)

Example 5 with CommitDefaults

use of com.cloudogu.scm.review.pullrequest.service.MergeService.CommitDefaults 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)8 Test (org.junit.jupiter.api.Test)8 DisplayUser (sonia.scm.user.DisplayUser)6 User (sonia.scm.user.User)6 MockHttpRequest (org.jboss.resteasy.mock.MockHttpRequest)5 JsonMockHttpResponse (sonia.scm.web.JsonMockHttpResponse)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 MockHttpResponse (org.jboss.resteasy.mock.MockHttpResponse)2 Changeset (sonia.scm.repository.Changeset)2 ChangesetPagingResult (sonia.scm.repository.ChangesetPagingResult)2 Person (sonia.scm.repository.Person)2