Search in sources :

Example 21 with EnqueueRequests

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

the class MylynGitHubApiITests method saveFailureChangeStatusNoAddComment.

@Test
@EnqueueRequests({ "getUserPivotalIssueMaster", "getIssueCommentsFailureComment", "getPullRequestReviewCommentsNoComments", "getStatusSuccess", "saveStatus" })
public void saveFailureChangeStatusNoAddComment() 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\":\"Please sign the Contributor License Agreement!\",\"state\":\"failure\",\"target_url\":\"https://status.example.com/uri\"}");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Test(org.junit.Test) EnqueueRequests(okhttp3.mockwebserver.EnqueueRequests)

Example 22 with EnqueueRequests

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

the class MylynGitHubApiITests method getCurrentUserSigning.

@Test
@EnqueueRequests({ "getAccessToken", "getEmailsNotPivotal", "getUserRwinch" })
public void getCurrentUserSigning() throws Exception {
    OAuthAccessTokenParams oauthParams = new OAuthAccessTokenParams();
    oauthParams.setCallbackUrl("https://example.com/oauth/callback");
    oauthParams.setCode("code-123");
    oauthParams.setState("state-456");
    CurrentUserRequest userRequest = new CurrentUserRequest();
    userRequest.setOauthParams(oauthParams);
    userRequest.setRequestAdminAccess(false);
    User user = service.getCurrentUser(userRequest);
    assertThat(user.getAccessToken()).isEqualTo("access-token-123");
    assertThat(user.getAvatarUrl()).isEqualTo("https://avatars.githubusercontent.com/u/362503?v=3");
    assertThat(user.getEmails()).containsOnly("rob@example.com");
    assertThat(user.getGitHubLogin()).isEqualTo("rwinch");
    assertThat(user.getName()).isEqualTo("Rob Winch");
    assertThat(user.isAdminAccessRequested()).isFalse();
    assertThat(user.isAdmin()).isFalse();
    RecordedRequest request = server.getServer().takeRequest();
    assertThat(request.getMethod()).isEqualTo("POST");
    assertThat(request.getPath()).isEqualTo("/login/oauth/access_token");
    assertThat(request.getBody().readUtf8()).isEqualTo("{\"code\":\"code-123\",\"client_secret\":\"client-secret\",\"state\":\"state-456\",\"client_id\":\"client-id\",\"redirect_url\":\"https://example.com/oauth/callback\"}");
    request = server.getServer().takeRequest();
    assertThat(request.getMethod()).isEqualTo("GET");
    assertThat(request.getPath()).isEqualTo("/api/v3/user/emails?per_page=100&page=1");
    assertThat(request.getHeader("Authorization")).isEqualTo("token " + user.getAccessToken());
    request = server.getServer().takeRequest();
    assertThat(request.getMethod()).isEqualTo("GET");
    assertThat(request.getPath()).isEqualTo("/api/v3/user");
    assertThat(request.getHeader("Authorization")).isEqualTo("token " + user.getAccessToken());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) User(io.pivotal.cla.data.User) Test(org.junit.Test) EnqueueRequests(okhttp3.mockwebserver.EnqueueRequests)

Example 23 with EnqueueRequests

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

the class MylynGitHubApiITests method saveSuccessNoComments.

@Test
@EnqueueRequests({ "getUserPivotalIssueMaster", "getIssueCommentsNone", "getPullRequestReviewCommentsNoComments", "getStatusNone", "saveStatus", "createComment" })
public void saveSuccessNoComments() 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 24 with EnqueueRequests

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

the class MylynGitHubApiITests method getVerifiedEmails.

@Test
@EnqueueRequests("getEmailsPivotal")
public void getVerifiedEmails() throws Exception {
    String token = "access-token-123";
    assertThat(service.getVerifiedEmails(token)).containsOnly("rob@example.com", "rob@pivotal.io");
    RecordedRequest request = server.getServer().takeRequest();
    assertThat(request.getMethod()).isEqualTo("GET");
    assertThat(request.getPath()).isEqualTo("/api/v3/user/emails?per_page=100&page=1");
    assertThat(request.getHeader("Authorization")).isEqualTo("token access-token-123");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Test(org.junit.Test) EnqueueRequests(okhttp3.mockwebserver.EnqueueRequests)

Example 25 with EnqueueRequests

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

the class MylynGitHubApiITests method getCurrentUserAdminRequestedButNotAdmin.

@Test
@EnqueueRequests({ "getAccessToken", "getEmailsNotPivotal", "getUserRwinch" })
public void getCurrentUserAdminRequestedButNotAdmin() throws Exception {
    OAuthAccessTokenParams oauthParams = new OAuthAccessTokenParams();
    oauthParams.setCallbackUrl("https://example.com/oauth/callback");
    oauthParams.setCode("code-123");
    oauthParams.setState("state-456");
    CurrentUserRequest userRequest = new CurrentUserRequest();
    userRequest.setOauthParams(oauthParams);
    userRequest.setRequestAdminAccess(true);
    User user = service.getCurrentUser(userRequest);
    assertThat(user.getAccessToken()).isEqualTo("access-token-123");
    assertThat(user.getAvatarUrl()).isEqualTo("https://avatars.githubusercontent.com/u/362503?v=3");
    assertThat(user.getEmails()).containsOnly("rob@example.com");
    assertThat(user.getGitHubLogin()).isEqualTo("rwinch");
    assertThat(user.getName()).isEqualTo("Rob Winch");
    assertThat(user.isAdminAccessRequested()).isTrue();
    assertThat(user.isAdmin()).isFalse();
    RecordedRequest request = server.getServer().takeRequest();
    assertThat(request.getMethod()).isEqualTo("POST");
    assertThat(request.getPath()).isEqualTo("/login/oauth/access_token");
    assertThat(request.getBody().readUtf8()).isEqualTo("{\"code\":\"code-123\",\"client_secret\":\"client-secret\",\"state\":\"state-456\",\"client_id\":\"client-id\",\"redirect_url\":\"https://example.com/oauth/callback\"}");
    request = server.getServer().takeRequest();
    assertThat(request.getMethod()).isEqualTo("GET");
    assertThat(request.getPath()).isEqualTo("/api/v3/user/emails?per_page=100&page=1");
    assertThat(request.getHeader("Authorization")).isEqualTo("token " + user.getAccessToken());
    request = server.getServer().takeRequest();
    assertThat(request.getMethod()).isEqualTo("GET");
    assertThat(request.getPath()).isEqualTo("/api/v3/user");
    assertThat(request.getHeader("Authorization")).isEqualTo("token " + user.getAccessToken());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) User(io.pivotal.cla.data.User) 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