Search in sources :

Example 26 with EnqueueRequests

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

the class MylynGitHubApiITests method saveObviousFixAfterPleaseSignAndClaNotRequiredComment.

@Test
@EnqueueRequests({ "getUserPivotalIssueMaster", "getIssueCommentsPleaseSignObviousFixAndObviousFixByIssueMaster", "getStatusNone", "saveStatus" })
public void saveObviousFixAfterPleaseSignAndClaNotRequiredComment() 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(4);
    RecordedRequest request = server.getServer().takeRequest();
    assertGetUserRequest(request);
    assertIssueCommentsRequest(server.getServer().takeRequest());
    request = server.getServer().takeRequest();
    assertThat(request.getMethod()).isEqualTo("GET");
    assertThat(request.getPath()).isEqualTo("/api/v3/repos/spring-projects/spring-security/statuses/14f7eed929c0086d5d7b87d28bc4722f618a361f?per_page=100&page=1");
    assertThat(request.getHeader("Authorization")).isEqualTo("token " + accessToken);
    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 27 with EnqueueRequests

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

the class MylynGitHubApiITests method saveSuccessNoChangeStatusNoAddComment.

@Test
@EnqueueRequests({ "getUserPivotalIssueMaster", "getIssueCommentsSignedByPivotalIssueMsaer", "getPullRequestReviewCommentsNoComments", "getStatusSuccess" })
public void saveSuccessNoChangeStatusNoAddComment() 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.setAccessToken(accessToken);
    commitStatus.setPullRequestState("open");
    service.save(commitStatus);
    assertThat(server.getServer().getRequestCount()).isEqualTo(4);
    RecordedRequest request = server.getServer().takeRequest();
    assertGetUserRequest(request);
    assertIssueCommentsRequest(server.getServer().takeRequest());
    assertPullRequestCommentsRequest(server.getServer().takeRequest());
    assertGetStatus(accessToken, server.getServer().takeRequest());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Test(org.junit.Test) EnqueueRequests(okhttp3.mockwebserver.EnqueueRequests)

Example 28 with EnqueueRequests

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

the class MylynGitHubApiITests method getContributingUrls.

@Test
@EnqueueRequests({ "getContributingUrls302", "getContributingUrls200", "getContributingUrls404", "getContributingUrls404", "getContributingUrls302", "getContributingUrls200", "getContributingUrls404" })
public void getContributingUrls() {
    // make sure we use GitHubHost and not the GitHubApiHost
    oauthConfig.setGitHubApiHost("donotuse");
    oauthConfig.setGitHubHost(server.getServer().getHostName());
    service = new MylynGitHubApi(oauthConfig);
    List<String> repositoryIds = Arrays.asList("spring-projects/has-md", "spring-projects/has-adoc", "spring-projects/no-contributor");
    ContributingUrlsResponse urls = service.getContributingUrls(repositoryIds);
    assertThat(urls.getAsciidoc()).containsExactly(server.getServerUrl() + "/spring-projects/has-adoc/edit/master/CONTRIBUTING.adoc", server.getServerUrl() + "/spring-projects/no-contributor/new/master?filename=CONTRIBUTING.adoc");
    assertThat(urls.getMarkdown()).containsOnly(server.getServerUrl() + "/spring-projects/has-md/edit/master/CONTRIBUTING.md");
    SerializingConverter converter = new SerializingConverter();
    // ensure we can serialize the result as it is placed in FlashMap
    assertThat(converter.convert(urls.getMarkdown())).isNotNull();
    assertThat(converter.convert(urls.getAsciidoc())).isNotNull();
}
Also used : SerializingConverter(org.springframework.core.serializer.support.SerializingConverter) 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