use of okhttp3.mockwebserver.EnqueueRequests in project pivotal-cla by pivotalsoftware.
the class MylynGitHubApiITests method saveSuccessHasPleaseSign.
@Test
@EnqueueRequests({ "getUserPivotalIssueMaster", "getIssueCommentsFailureComment", "getPullRequestReviewCommentsNoComments", "getStatusNone", "saveStatus", "createComment" })
public void saveSuccessHasPleaseSign() 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(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\":\"Thank you for signing the Contributor License Agreement!\",\"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)!\"}");
}
use of okhttp3.mockwebserver.EnqueueRequests in project pivotal-cla by pivotalsoftware.
the class MylynGitHubApiITests method saveNoLongerObvious.
@Test
@EnqueueRequests({ "getUserPivotalIssueMaster", "getIssueCommentsNoComments", "getPullRequestReviewCommentsNoComments", "getStatusObvious", "saveStatus", "createComment" })
public void saveNoLongerObvious() 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()).contains("\"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.\"");
}
use of okhttp3.mockwebserver.EnqueueRequests in project pivotal-cla by pivotalsoftware.
the class MylynGitHubApiITests method saveFailureAlreadyCommented.
@Test
@EnqueueRequests({ "getUserPivotalIssueMaster", "getIssueCommentsFailureComment", "getPullRequestReviewCommentsNoComments", "getStatusNone", "saveStatus" })
public void saveFailureAlreadyCommented() 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\"}");
}
use of okhttp3.mockwebserver.EnqueueRequests in project pivotal-cla by pivotalsoftware.
the class MylynGitHubApiITests method getCurrentUserAdminAndClaAuthor.
@Test
@EnqueueRequests({ "getAccessToken", "getEmailsPivotal", "getUserRwinch", "getTeamMembers" })
public void getCurrentUserAdminAndClaAuthor() 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", "rob@pivotal.io");
assertThat(user.getGitHubLogin()).isEqualTo("rwinch");
assertThat(user.getName()).isEqualTo("Rob Winch");
assertThat(user.isAdminAccessRequested()).isTrue();
assertThat(user.isAdmin()).isTrue();
assertThat(user.isClaAuthor()).isTrue();
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());
}
use of okhttp3.mockwebserver.EnqueueRequests in project pivotal-cla by pivotalsoftware.
the class MylynGitHubApiITests method findRepositoryNames.
@Test
@EnqueueRequests("findRepositoryNames")
public void findRepositoryNames() throws Exception {
String accessToken = "accessToken";
List<String> respositoryNames = service.findRepositoryNamesWithAdminPermission(accessToken);
assertThat(respositoryNames).containsOnly("spring-projects/spring-security", "spring-projects/spring-framework");
RecordedRequest request = server.getServer().takeRequest();
assertThat(request.getMethod()).isEqualTo("GET");
assertThat(request.getPath()).isEqualTo("/api/v3/user/repos?per_page=100&page=1");
assertThat(request.getHeader("Authorization")).isEqualTo("token " + accessToken);
}
Aggregations