use of io.pivotal.cla.data.User in project pivotal-cla by pivotalsoftware.
the class GitHubHooksControllerTests method markCommitStatusSuccessIndividual.
@Test
public void markCommitStatusSuccessIndividual() throws Exception {
User user = WithSigningUserFactory.create();
when(mockUserRepo.findOne(anyString())).thenReturn(user);
when(mockTokenRepo.findOne("rwinch/176_test")).thenReturn(new AccessToken("rwinch/176_test", "mock_access_token_value"));
when(mockIndividualSignatureRepository.findSignaturesFor(any(), any(), anyString())).thenReturn(Arrays.asList(individualSignature));
mockMvc.perform(hookRequest().header("X-GitHub-Event", GithubEvents.PULL_REQUEST).content(getPayload("pull_request.json"))).andExpect(status().isOk());
ArgumentCaptor<PullRequestStatus> statusCaptor = ArgumentCaptor.forClass(PullRequestStatus.class);
verify(mockGitHub).save(statusCaptor.capture());
PullRequestStatus status = statusCaptor.getValue();
assertThat(status.getRepoId()).isEqualTo("rwinch/176_test");
assertThat(status.getAccessToken()).isEqualTo("mock_access_token_value");
assertThat(status.getPullRequestId()).isEqualTo(2);
assertThat(status.getSha()).isEqualTo("a6befb598a35c1c206e1bf7bbb3018f4403b9610");
assertThat(status.getUrl()).isEqualTo("http://localhost/sign/pivotal?repositoryId=rwinch/176_test&pullRequestId=2");
assertThat(status.isSuccess()).isTrue();
assertThat(status.getGitHubUsername()).isEqualTo(user.getGitHubLogin());
assertThat(status.getPullRequestBody()).isNotEmpty();
}
use of io.pivotal.cla.data.User in project pivotal-cla by pivotalsoftware.
the class GitHubHooksControllerTests method rejectUnknownEventPayload.
@Test
public void rejectUnknownEventPayload() throws Exception {
User user = WithSigningUserFactory.create();
when(mockUserRepo.findOne(anyString())).thenReturn(user);
when(mockTokenRepo.findOne("rwinch/176_test")).thenReturn(new AccessToken("rwinch/176_test", "mock_access_token_value"));
when(mockIndividualSignatureRepository.findSignaturesFor(any(), any(), anyString())).thenReturn(Arrays.asList(individualSignature));
mockMvc.perform(hookRequest().header("X-GitHub-Event", "unknown").content(getPayload("pull_request.json"))).andExpect(status().isBadRequest());
}
use of io.pivotal.cla.data.User in project pivotal-cla by pivotalsoftware.
the class GitHubHooksControllerTests method markCommitStatusSuccessIndividualAcceptingReviewComments.
@Test
public void markCommitStatusSuccessIndividualAcceptingReviewComments() throws Exception {
User user = WithSigningUserFactory.create();
when(mockUserRepo.findOne(anyString())).thenReturn(user);
when(mockTokenRepo.findOne("rwinch/176_test")).thenReturn(new AccessToken("rwinch/176_test", "mock_access_token_value"));
when(mockIndividualSignatureRepository.findSignaturesFor(any(), any(), anyString())).thenReturn(Arrays.asList(individualSignature));
mockMvc.perform(hookRequest().header("X-GitHub-Event", GithubEvents.PULL_REQUEST_REVIEW_COMMENT).content(getPayload("pull_request_review_comment.json"))).andExpect(status().isOk());
ArgumentCaptor<PullRequestStatus> statusCaptor = ArgumentCaptor.forClass(PullRequestStatus.class);
verify(mockGitHub).save(statusCaptor.capture());
PullRequestStatus status = statusCaptor.getValue();
assertThat(status.getRepoId()).isEqualTo("rwinch/176_test");
assertThat(status.getAccessToken()).isEqualTo("mock_access_token_value");
assertThat(status.getPullRequestId()).isEqualTo(2);
assertThat(status.getSha()).isEqualTo("a6befb598a35c1c206e1bf7bbb3018f4403b9610");
assertThat(status.getUrl()).isEqualTo("http://localhost/sign/pivotal?repositoryId=rwinch/176_test&pullRequestId=2");
assertThat(status.isSuccess()).isTrue();
assertThat(status.getGitHubUsername()).isEqualTo(user.getGitHubLogin());
assertThat(status.getPullRequestBody()).isNotEmpty();
}
use of io.pivotal.cla.data.User in project pivotal-cla by pivotalsoftware.
the class WithAdminUserFactory method create.
public static User create() {
User user = new User();
user.setAccessToken("mocked_access_token");
user.setAvatarUrl("https://avatars.githubusercontent.com/u/362503?v=3");
user.setEmails(Collections.singleton("rob@pivotal.io"));
user.setGitHubLogin("rwinch");
user.setAdmin(true);
return user;
}
use of io.pivotal.cla.data.User in project pivotal-cla by pivotalsoftware.
the class WithAdminUserFactory method createSecurityContext.
@Override
public SecurityContext createSecurityContext(WithAdminUser user) {
User adminUser = create();
UserAuthentication auth = new UserAuthentication(adminUser);
SecurityContext context = SecurityContextHolder.createEmptyContext();
context.setAuthentication(auth);
return context;
}
Aggregations