Search in sources :

Example 6 with EnqueueRequests

use of okhttp3.mockwebserver.EnqueueRequests in project pivotal-cla by pivotalsoftware.

the class MylynGitHubApiITests method saveObviousFixAfterPleaseSign.

@Test
@EnqueueRequests({ "getUserPivotalIssueMaster", "getIssueCommentsPleaseSignAndObviousFix", "getStatusNone", "saveStatus", "createComment" })
public void saveObviousFixAfterPleaseSign() throws Exception {
    String accessToken = "access-token-123";
    PullRequestStatus commitStatus = new PullRequestStatus();
    commitStatus.setGitHubUsername("rwinch");
    commitStatus.setPullRequestId(1);
    commitStatus.setRepoId("spring-projects/spring-security");
    commitStatus.setSha("14f7eed929c0086d5d7b87d28bc4722f618a361f");
    commitStatus.setSuccess(false);
    commitStatus.setUrl("https://status.example.com/uri");
    commitStatus.setSyncUrl("https://cla.pivotal.io/sync/pivotal");
    commitStatus.setFaqUrl("https://cla.pivotal.io/about");
    commitStatus.setAccessToken(accessToken);
    commitStatus.setPullRequestState("open");
    service.save(commitStatus);
    assertThat(server.getServer().getRequestCount()).isEqualTo(5);
    RecordedRequest request = server.getServer().takeRequest();
    assertGetUserRequest(request);
    assertIssueCommentsRequest(server.getServer().takeRequest());
    assertGetStatus(accessToken, server.getServer().takeRequest());
    request = server.getServer().takeRequest();
    assertThat(request.getMethod()).isEqualTo("POST");
    assertThat(request.getPath()).isEqualTo("/api/v3/repos/spring-projects/spring-security/statuses/14f7eed929c0086d5d7b87d28bc4722f618a361f");
    assertThat(request.getHeader("Authorization")).isEqualTo("token " + accessToken);
    assertThat(request.getBody().readUtf8()).isEqualTo("{\"context\":\"ci/pivotal-cla\",\"description\":\"This Pull Request contains an obvious fix. Signing the Contributor License Agreement is not necessary.\",\"state\":\"success\",\"target_url\":\"https://status.example.com/uri\"}");
    request = server.getServer().takeRequest();
    assertThat(request.getMethod()).isEqualTo("POST");
    assertThat(request.getPath()).isEqualTo("/api/v3/repos/spring-projects/spring-security/issues/1/comments");
    assertThat(request.getHeader("Authorization")).isEqualTo("token pivotal-cla-accessToken");
    assertThat(request.getBody().readUtf8()).isEqualTo("{\"body\":\"@rwinch This Pull Request contains an obvious fix. Signing the Contributor License Agreement is not necessary.\"}");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Test(org.junit.Test) EnqueueRequests(okhttp3.mockwebserver.EnqueueRequests)

Example 7 with EnqueueRequests

use of okhttp3.mockwebserver.EnqueueRequests in project pivotal-cla by pivotalsoftware.

the class MylynGitHubApiITests method enableInactivePullRequestHookAndSetSecret.

@Test
@EnqueueRequests({ "getPullRequestInactive", "updatePullRequestHooks" })
public void enableInactivePullRequestHookAndSetSecret() throws Exception {
    CreatePullRequestHookRequest hookRequest = new CreatePullRequestHookRequest();
    hookRequest.setAccessToken("access-token-123");
    hookRequest.setGitHubEventUrl("https://example.com/github/hooks/pull_request/my-cla");
    hookRequest.setRepositoryIds(Arrays.asList("spring-projects/spring-security"));
    hookRequest.setSecret("do not guess me");
    List<String> hooks = service.createPullRequestHooks(hookRequest);
    assertThat(hooks).containsOnly("https://github.com/spring-projects/spring-security/settings/hooks/123");
    RecordedRequest request = server.getServer().takeRequest();
    assertThat(request.getMethod()).isEqualTo("GET");
    assertThat(request.getPath()).isEqualTo("/api/v3/repos/spring-projects/spring-security/hooks?per_page=100&page=1");
    request = server.getServer().takeRequest();
    assertThat(request.getMethod()).isEqualTo("POST");
    assertThat(request.getPath()).isEqualTo("/api/v3/repos/spring-projects/spring-security/hooks/123");
    assertThat(request.getHeader("Authorization")).isEqualTo("token " + hookRequest.getAccessToken());
    assertThat(request.getBody().readUtf8()).isEqualTo("{\"events\":[\"issue_comment\",\"pull_request\",\"pull_request_review_comment\"],\"active\":true,\"created_at\":null,\"updated_at\":null,\"id\":123,\"last_response\":null,\"name\":\"web\",\"url\":null,\"config\":{\"content_type\":\"json\",\"secret\":\"do not guess me\",\"url\":\"https://example.com/github/hooks/pull_request/my-cla\"}}");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Test(org.junit.Test) EnqueueRequests(okhttp3.mockwebserver.EnqueueRequests)

Example 8 with EnqueueRequests

use of okhttp3.mockwebserver.EnqueueRequests in project pivotal-cla by pivotalsoftware.

the class MylynGitHubApiITests method saveObviousFixWithoutPleaseSignComment.

@Test
@EnqueueRequests({ "getUserPivotalIssueMaster", "getIssueCommentsNoComments", "getPullRequestReviewCommentsObviousFixComment", "getStatusNone", "saveStatus" })
public void saveObviousFixWithoutPleaseSignComment() throws Exception {
    String accessToken = "access-token-123";
    PullRequestStatus commitStatus = new PullRequestStatus();
    commitStatus.setGitHubUsername("rwinch");
    commitStatus.setPullRequestId(1);
    commitStatus.setRepoId("spring-projects/spring-security");
    commitStatus.setSha("14f7eed929c0086d5d7b87d28bc4722f618a361f");
    commitStatus.setSuccess(false);
    commitStatus.setUrl("https://status.example.com/uri");
    commitStatus.setSyncUrl("https://cla.pivotal.io/sync/pivotal");
    commitStatus.setFaqUrl("https://cla.pivotal.io/about");
    commitStatus.setAccessToken(accessToken);
    commitStatus.setPullRequestState("open");
    service.save(commitStatus);
    assertThat(server.getServer().getRequestCount()).isEqualTo(5);
    RecordedRequest request = server.getServer().takeRequest();
    assertGetUserRequest(request);
    assertIssueCommentsRequest(server.getServer().takeRequest());
    assertPullRequestCommentsRequest(server.getServer().takeRequest());
    assertGetStatus(accessToken, server.getServer().takeRequest());
    request = server.getServer().takeRequest();
    assertThat(request.getMethod()).isEqualTo("POST");
    assertThat(request.getPath()).isEqualTo("/api/v3/repos/spring-projects/spring-security/statuses/14f7eed929c0086d5d7b87d28bc4722f618a361f");
    assertThat(request.getHeader("Authorization")).isEqualTo("token " + accessToken);
    assertThat(request.getBody().readUtf8()).isEqualTo("{\"context\":\"ci/pivotal-cla\",\"description\":\"This Pull Request contains an obvious fix. Signing the Contributor License Agreement is not necessary.\",\"state\":\"success\",\"target_url\":\"https://status.example.com/uri\"}");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Test(org.junit.Test) EnqueueRequests(okhttp3.mockwebserver.EnqueueRequests)

Example 9 with EnqueueRequests

use of okhttp3.mockwebserver.EnqueueRequests in project pivotal-cla by pivotalsoftware.

the class MylynGitHubApiITests method createPullRequestHooks.

@Test
@EnqueueRequests({ "getPullRequestHooksEmpty", "createPullRequestHooks", "getPullRequestHooksEmpty", "createPullRequestHooks456" })
public void createPullRequestHooks() throws Exception {
    CreatePullRequestHookRequest hookRequest = new CreatePullRequestHookRequest();
    hookRequest.setAccessToken("access-token-123");
    hookRequest.setGitHubEventUrl("https://example.com/github/hook");
    hookRequest.setRepositoryIds(Arrays.asList("spring-projects/spring-security", "spring-projects/spring-session"));
    hookRequest.setSecret("do not guess me");
    List<String> hooks = service.createPullRequestHooks(hookRequest);
    assertThat(hooks).containsOnly("https://github.com/spring-projects/spring-security/settings/hooks/123", "https://github.com/spring-projects/spring-session/settings/hooks/456");
    RecordedRequest request = server.getServer().takeRequest();
    assertThat(request.getMethod()).isEqualTo("GET");
    assertThat(request.getPath()).isEqualTo("/api/v3/repos/spring-projects/spring-security/hooks?per_page=100&page=1");
    request = server.getServer().takeRequest();
    assertThat(request.getMethod()).isEqualTo("POST");
    assertThat(request.getPath()).isEqualTo("/api/v3/repos/spring-projects/spring-security/hooks");
    assertThat(request.getHeader("Authorization")).isEqualTo("token " + hookRequest.getAccessToken());
    assertThat(request.getBody().readUtf8()).isEqualTo("{\"events\":[\"issue_comment\",\"pull_request\",\"pull_request_review_comment\"],\"active\":true,\"created_at\":null,\"updated_at\":null,\"id\":0,\"last_response\":null,\"name\":\"web\",\"url\":null,\"config\":{\"content_type\":\"json\",\"secret\":\"do not guess me\",\"url\":\"https://example.com/github/hook\"}}");
    request = server.getServer().takeRequest();
    assertThat(request.getMethod()).isEqualTo("GET");
    assertThat(request.getPath()).isEqualTo("/api/v3/repos/spring-projects/spring-session/hooks?per_page=100&page=1");
    request = server.getServer().takeRequest();
    assertThat(request.getMethod()).isEqualTo("POST");
    assertThat(request.getPath()).isEqualTo("/api/v3/repos/spring-projects/spring-session/hooks");
    assertThat(request.getHeader("Authorization")).isEqualTo("token " + hookRequest.getAccessToken());
    assertThat(request.getBody().readUtf8()).isEqualTo("{\"events\":[\"issue_comment\",\"pull_request\",\"pull_request_review_comment\"],\"active\":true,\"created_at\":null,\"updated_at\":null,\"id\":0,\"last_response\":null,\"name\":\"web\",\"url\":null,\"config\":{\"content_type\":\"json\",\"secret\":\"do not guess me\",\"url\":\"https://example.com/github/hook\"}}");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Test(org.junit.Test) EnqueueRequests(okhttp3.mockwebserver.EnqueueRequests)

Example 10 with EnqueueRequests

use of okhttp3.mockwebserver.EnqueueRequests in project pivotal-cla by pivotalsoftware.

the class MylynGitHubApiITests method saveObviousFixAfterPleaseSignWithSignedCla.

@Test
@EnqueueRequests({ "getUserPivotalIssueMaster", "getIssueCommentsPleaseSignAndObviousFix", "getStatusNone", "saveStatus", "editComment", "createComment" })
public void saveObviousFixAfterPleaseSignWithSignedCla() throws Exception {
    String accessToken = "access-token-123";
    PullRequestStatus commitStatus = new PullRequestStatus();
    commitStatus.setGitHubUsername("rwinch");
    commitStatus.setPullRequestId(1);
    commitStatus.setRepoId("spring-projects/spring-security");
    commitStatus.setSha("14f7eed929c0086d5d7b87d28bc4722f618a361f");
    commitStatus.setSuccess(true);
    commitStatus.setUrl("https://status.example.com/uri");
    commitStatus.setSyncUrl("https://cla.pivotal.io/sync/pivotal");
    commitStatus.setFaqUrl("https://cla.pivotal.io/about");
    commitStatus.setAccessToken(accessToken);
    commitStatus.setPullRequestState("open");
    service.save(commitStatus);
    assertThat(server.getServer().getRequestCount()).isEqualTo(5);
    RecordedRequest request = server.getServer().takeRequest();
    assertGetUserRequest(request);
    assertIssueCommentsRequest(server.getServer().takeRequest());
    assertGetStatus(accessToken, server.getServer().takeRequest());
    request = server.getServer().takeRequest();
    assertThat(request.getMethod()).isEqualTo("POST");
    assertThat(request.getPath()).isEqualTo("/api/v3/repos/spring-projects/spring-security/statuses/14f7eed929c0086d5d7b87d28bc4722f618a361f");
    assertThat(request.getHeader("Authorization")).isEqualTo("token " + accessToken);
    assertThat(request.getBody().readUtf8()).isEqualTo("{\"context\":\"ci/pivotal-cla\",\"description\":\"This Pull Request contains an obvious fix. Signing the Contributor License Agreement is not necessary.\",\"state\":\"success\",\"target_url\":\"https://status.example.com/uri\"}");
    request = server.getServer().takeRequest();
    assertThat(request.getMethod()).isEqualTo("POST");
    assertThat(request.getPath()).isEqualTo("/api/v3/repos/spring-projects/spring-security/issues/1/comments");
    assertThat(request.getHeader("Authorization")).isEqualTo("token pivotal-cla-accessToken");
    assertThat(request.getBody().readUtf8()).isEqualTo("{\"body\":\"@rwinch Thank you for signing the [Contributor License Agreement](https://status.example.com/uri)!\"}");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Test(org.junit.Test) EnqueueRequests(okhttp3.mockwebserver.EnqueueRequests)

Aggregations

Test (org.junit.Test)28 EnqueueRequests (okhttp3.mockwebserver.EnqueueRequests)26 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)25 User (io.pivotal.cla.data.User)4 HttpUrl (okhttp3.HttpUrl)2 OkHttpClient (okhttp3.OkHttpClient)2 Request (okhttp3.Request)2 Response (okhttp3.Response)2 SerializingConverter (org.springframework.core.serializer.support.SerializingConverter)1