use of com.faforever.api.data.domain.Player in project faf-java-api by FAForever.
the class VotingServiceTest method saveVoteInvalidChoiceId.
@Test
public void saveVoteInvalidChoiceId() {
VotingSubject votingSubject = new VotingSubject();
votingSubject.setId(1);
votingSubject.setBeginOfVoteTime(OffsetDateTime.now());
votingSubject.setEndOfVoteTime(OffsetDateTime.MAX);
VotingQuestion votingQuestion = new VotingQuestion();
votingQuestion.setAlternativeQuestion(true);
votingSubject.setVotingQuestions(Collections.singleton(votingQuestion));
votingQuestion.setMaxAnswers(2);
Vote vote = new Vote();
VotingAnswer votingAnswer = new VotingAnswer();
VotingChoice votingChoice = new VotingChoice();
votingChoice.setId(1);
votingChoice.setVotingQuestion(votingQuestion);
votingAnswer.setVotingChoice(votingChoice);
votingAnswer.setAlternativeOrdinal(0);
vote.setVotingAnswers(new HashSet<>(Collections.singletonList(votingAnswer)));
vote.setVotingSubject(votingSubject);
Player player = new Player();
when(voteRepository.findByPlayerAndVotingSubjectId(player, votingSubject.getId())).thenReturn(Optional.empty());
when(votingSubjectRepository.findById(votingSubject.getId())).thenReturn(Optional.of(votingSubject));
expectedException.expect(ApiExceptionWithCode.apiExceptionWithCode(ErrorCode.VOTING_CHOICE_DOES_NOT_EXIST));
instance.saveVote(vote, player);
verify(voteRepository, never()).save(vote);
}
use of com.faforever.api.data.domain.Player in project faf-java-api by FAForever.
the class VotingServiceTest method notSaveVoteIfUserVotedAlready.
@Test
public void notSaveVoteIfUserVotedAlready() {
Vote vote = new Vote();
VotingSubject votingSubject = new VotingSubject();
votingSubject.setId(1);
votingSubject.setBeginOfVoteTime(OffsetDateTime.now());
votingSubject.setEndOfVoteTime(OffsetDateTime.MAX);
VotingQuestion votingQuestion = new VotingQuestion();
votingQuestion.setAlternativeQuestion(false);
votingQuestion.setMaxAnswers(1);
votingSubject.setVotingQuestions(Collections.singleton(votingQuestion));
vote.setVotingSubject(votingSubject);
Player player = new Player();
when(voteRepository.findByPlayerAndVotingSubjectId(player, votingSubject.getId())).thenReturn(Optional.of(new Vote()));
when(votingSubjectRepository.findById(votingSubject.getId())).thenReturn(Optional.of(votingSubject));
try {
instance.saveVote(vote, player);
} catch (ApiException e) {
assertTrue(Arrays.stream(e.getErrors()).anyMatch(error -> error.getErrorCode().equals(ErrorCode.VOTED_TWICE)));
}
verify(voteRepository, never()).save(vote);
}
use of com.faforever.api.data.domain.Player in project faf-java-api by FAForever.
the class VotingServiceTest method saveVoteInvalidVoteId.
@Test
public void saveVoteInvalidVoteId() {
Vote vote = new Vote();
VotingSubject votingSubject = new VotingSubject();
votingSubject.setId(1);
vote.setVotingSubject(votingSubject);
expectedException.expect(ApiExceptionWithCode.apiExceptionWithCode(ErrorCode.VOTING_SUBJECT_DOES_NOT_EXIST));
instance.saveVote(vote, new Player());
verify(voteRepository, never()).save(vote);
}
use of com.faforever.api.data.domain.Player in project faf-java-api by FAForever.
the class VotingServiceTest method saveVoteIfAlternativeOrdinalCorrect.
@Test
public void saveVoteIfAlternativeOrdinalCorrect() {
VotingSubject votingSubject = new VotingSubject();
votingSubject.setId(1);
votingSubject.setBeginOfVoteTime(OffsetDateTime.now());
votingSubject.setEndOfVoteTime(OffsetDateTime.MAX);
VotingQuestion votingQuestion = new VotingQuestion();
votingQuestion.setAlternativeQuestion(true);
votingSubject.setVotingQuestions(Collections.singleton(votingQuestion));
votingQuestion.setMaxAnswers(2);
Vote vote = new Vote();
VotingAnswer votingAnswer = new VotingAnswer();
VotingChoice votingChoice = new VotingChoice();
votingChoice.setId(1);
votingChoice.setVotingQuestion(votingQuestion);
votingAnswer.setVotingChoice(votingChoice);
votingAnswer.setAlternativeOrdinal(0);
VotingAnswer votingAnswer2 = new VotingAnswer();
VotingChoice votingChoice2 = new VotingChoice();
votingChoice2.setId(2);
votingChoice2.setVotingQuestion(votingQuestion);
votingAnswer2.setVotingChoice(votingChoice2);
votingAnswer2.setAlternativeOrdinal(1);
vote.setVotingAnswers(new HashSet<>(Arrays.asList(votingAnswer, votingAnswer2)));
vote.setVotingSubject(votingSubject);
Player player = new Player();
when(voteRepository.findByPlayerAndVotingSubjectId(player, votingSubject.getId())).thenReturn(Optional.empty());
when(votingSubjectRepository.findById(votingSubject.getId())).thenReturn(Optional.of(votingSubject));
when(votingChoiceRepository.findById(votingChoice.getId())).thenReturn(Optional.of(votingChoice));
when(votingChoiceRepository.findById(votingChoice2.getId())).thenReturn(Optional.of(votingChoice2));
instance.saveVote(vote, player);
verify(voteRepository).save(vote);
}
use of com.faforever.api.data.domain.Player in project faf-java-api by FAForever.
the class ClanServiceTest method generatePlayerInvitationTokenFromNonLeader.
@Test
public void generatePlayerInvitationTokenFromNonLeader() throws IOException {
Player requester = new Player();
requester.setId(1);
Player newMember = new Player();
newMember.setId(2);
Player leader = new Player();
leader.setId(3);
Clan clan = ClanFactory.builder().leader(leader).build();
when(clanRepository.findById(clan.getId())).thenReturn(Optional.of(clan));
try {
instance.generatePlayerInvitationToken(requester, newMember.getId(), clan.getId());
fail();
} catch (ApiException e) {
assertThat(e, apiExceptionWithCode(ErrorCode.CLAN_NOT_LEADER));
}
verify(jwtService, Mockito.never()).sign(any());
}
Aggregations