use of okhttp3.mockwebserver.EnqueueRequests in project pivotal-cla by pivotalsoftware.
the class MylynGitHubApiITests method saveObviousFixInBodyWithoutComments.
@Test
@EnqueueRequests({ "getUserPivotalIssueMaster", "getIssueCommentsNoComments", "getStatusNone", "saveStatus", "createComment" })
public void saveObviousFixInBodyWithoutComments() 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");
commitStatus.setPullRequestBody("That's an obvious fix");
service.save(commitStatus);
assertThat(server.getServer().getRequestCount()).isEqualTo(4);
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\"}");
}
use of okhttp3.mockwebserver.EnqueueRequests in project pivotal-cla by pivotalsoftware.
the class MylynGitHubApiITests method saveSuccessDoNotAddCommentIfNoPleaseSign.
@Test
@EnqueueRequests({ "getUserPivotalIssueMaster", "getIssueCommentsNoComments", "getPullRequestReviewCommentsNoComments", "getStatusSuccess" })
public void saveSuccessDoNotAddCommentIfNoPleaseSign() 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());
}
use of okhttp3.mockwebserver.EnqueueRequests in project pivotal-cla by pivotalsoftware.
the class MylynGitHubApiITests method createPullRequestHooksExistingEmptyUrl.
@Test
@EnqueueRequests({ "getPullRequestHooksEmptyUrl", "createPullRequestHooks" })
public void createPullRequestHooksExistingEmptyUrl() 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"));
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");
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\"}}");
}
use of okhttp3.mockwebserver.EnqueueRequests in project pivotal-cla by pivotalsoftware.
the class MylynGitHubApiITests method saveFailureEditComment.
@Test
@EnqueueRequests({ "getUserPivotalIssueMaster", "getIssueCommentsOldFailureComment", "getPullRequestReviewCommentsNoComments", "getStatusNone", "saveStatus", "editComment" })
public void saveFailureEditComment() 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/comments/1");
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 getCurrentUserAdminAndNotClaAuthor.
@Test
@EnqueueRequests({ "getAccessToken", "getEmailsPivotal", "getUserRwinch", "getTeamMembersNotFound" })
public void getCurrentUserAdminAndNotClaAuthor() 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()).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());
}
Aggregations