Search in sources :

Example 1 with EnqueueRequests

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

the class EnqueueResourcesMockWebServerITest method enqueueRequestsRelative.

@Test
@EnqueueRequests("body-relative")
public void enqueueRequestsRelative() throws Exception {
    OkHttpClient client = new OkHttpClient.Builder().build();
    HttpUrl url = server.getServer().url("/");
    Request request = new Request.Builder().get().url(url).build();
    Response response = client.newCall(request).execute();
    assertEquals(200, response.code());
    assertEquals("body-relative", response.body().string());
}
Also used : Response(okhttp3.Response) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) HttpUrl(okhttp3.HttpUrl) Test(org.junit.Test)

Example 2 with EnqueueRequests

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

the class EnqueueResourcesMockWebServerITest method enqueueRequestsAbsolute.

@Test
@EnqueueRequests("/okhttp3/mockwebserver/EnqueueResourcesMockWebServerITest_resource/body-absolute")
public void enqueueRequestsAbsolute() throws Exception {
    OkHttpClient client = new OkHttpClient.Builder().build();
    HttpUrl url = server.getServer().url("/");
    Request request = new Request.Builder().get().url(url).build();
    Response response = client.newCall(request).execute();
    assertEquals(200, response.code());
    assertEquals("body-absolute", response.body().string());
}
Also used : Response(okhttp3.Response) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) HttpUrl(okhttp3.HttpUrl) Test(org.junit.Test)

Example 3 with EnqueueRequests

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

the class MylynGitHubApiITests method saveSuccessAlreadyCommented.

@Test
@EnqueueRequests({ "getUserPivotalIssueMaster", "getIssueCommentsSignedByPivotalIssueMsaer", "getPullRequestReviewCommentsNoComments", "getStatusNone", "saveStatus" })
public void saveSuccessAlreadyCommented() 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(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\":\"Thank you for signing the Contributor License Agreement!\",\"state\":\"success\",\"target_url\":\"https://status.example.com/uri\"}");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Test(org.junit.Test) EnqueueRequests(okhttp3.mockwebserver.EnqueueRequests)

Example 4 with EnqueueRequests

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

the class MylynGitHubApiITests method saveFailureNoComments.

@Test
@EnqueueRequests({ "getUserPivotalIssueMaster", "getIssueCommentsNone", "getPullRequestReviewCommentsNoComments", "getStatusNone", "saveStatus", "createComment" })
public void saveFailureNoComments() 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(6);
    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\":\"Please sign the Contributor License Agreement!\",\"state\":\"failure\",\"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 Please sign the [Contributor License Agreement](https://status.example.com/uri)!\\n\\n[Click here](https://cla.pivotal.io/sync/pivotal) to manually synchronize the status of this Pull Request.\\n\\nSee the [FAQ](https://cla.pivotal.io/about) for frequently asked questions.\"}");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Test(org.junit.Test) EnqueueRequests(okhttp3.mockwebserver.EnqueueRequests)

Example 5 with EnqueueRequests

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

the class MylynGitHubApiITests method saveSuccessChangeStatusNoAddComment.

@Test
@EnqueueRequests({ "getUserPivotalIssueMaster", "getIssueCommentsSignedByPivotalIssueMsaer", "getPullRequestReviewCommentsNoComments", "getStatusFailure", "saveStatus" })
public void saveSuccessChangeStatusNoAddComment() 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(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\":\"Thank you for signing the Contributor License Agreement!\",\"state\":\"success\",\"target_url\":\"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