use of org.broadinstitute.consent.http.models.Vote in project consent by DataBiosphere.
the class VoteServiceTest method testUpdateRationaleByVoteIds_NonOpenDataAccessElection.
@Test(expected = IllegalArgumentException.class)
public void testUpdateRationaleByVoteIds_NonOpenDataAccessElection() {
doNothing().when(voteDAO).updateRationaleByVoteIds(any(), any());
Vote v = setUpTestVote(true, true);
when(voteDAO.findVoteById(anyInt())).thenReturn(v);
Election election = new Election();
election.setElectionType(ElectionType.DATA_ACCESS.getValue());
election.setStatus(ElectionStatus.CLOSED.getValue());
when(electionDAO.findElectionsByIds(any())).thenReturn(List.of(election));
initService();
service.updateRationaleByVoteIds(List.of(1), "rationale");
}
use of org.broadinstitute.consent.http.models.Vote in project consent by DataBiosphere.
the class VoteServiceTest method testUpdateRationaleByVoteIds_NonDataAccessElection.
@Test(expected = IllegalArgumentException.class)
public void testUpdateRationaleByVoteIds_NonDataAccessElection() {
doNothing().when(voteDAO).updateRationaleByVoteIds(any(), any());
Vote v = setUpTestVote(true, true);
when(voteDAO.findVoteById(anyInt())).thenReturn(v);
Election election = new Election();
election.setElectionType(ElectionType.TRANSLATE_DUL.getValue());
election.setStatus(ElectionStatus.OPEN.getValue());
when(electionDAO.findElectionsByIds(any())).thenReturn(List.of(election));
initService();
service.updateRationaleByVoteIds(List.of(1), "rationale");
}
use of org.broadinstitute.consent.http.models.Vote in project consent by DataBiosphere.
the class VoteServiceTest method testChairCreateVotesRP.
@Test
public void testChairCreateVotesRP() {
setUpUserAndElectionVotes(UserRoles.CHAIRPERSON);
initService();
List<Vote> votes = service.createVotes(new Election(), ElectionType.RP, false);
assertFalse(votes.isEmpty());
// Should create 2 votes:
// Chairperson as a chair
// Chairperson as a dac member
assertEquals(2, votes.size());
}
use of org.broadinstitute.consent.http.models.Vote in project consent by DataBiosphere.
the class VoteServiceTest method testChairCreateVotesDataAccess.
@Test
public void testChairCreateVotesDataAccess() {
setUpUserAndElectionVotes(UserRoles.CHAIRPERSON);
initService();
List<Vote> votes = service.createVotes(new Election(), ElectionType.DATA_ACCESS, false);
assertFalse(votes.isEmpty());
// Should create 4 votes:
// Chairperson as a chair
// Chairperson as a dac member
// Final vote
// Manual review Agreement vote
assertEquals(4, votes.size());
}
use of org.broadinstitute.consent.http.models.Vote in project consent by DataBiosphere.
the class DarCollectionServiceDAOTest method testCreateElectionsForDarCollectionAdmin.
/**
* This test covers the case where:
* - User is an admin
* - Collection has 1 DAR/Dataset combinations
* - Elections created should be for the DAR/Dataset for the user
*/
@Test
public void testCreateElectionsForDarCollectionAdmin() throws Exception {
initService();
User user = new User();
user.addRole(new UserRole(UserRoles.ADMIN.getRoleId(), UserRoles.ADMIN.getRoleName()));
DarCollection collection = setUpDarCollectionWithDacDataset();
DataAccessRequest dar = collection.getDars().values().stream().findFirst().orElse(null);
assertNotNull(dar);
List<String> referenceIds = serviceDAO.createElectionsForDarCollection(user, collection);
List<Election> createdElections = electionDAO.findLastElectionsByReferenceIds(List.of(dar.getReferenceId()));
List<Vote> createdVotes = voteDAO.findVotesByElectionIds(createdElections.stream().map(Election::getElectionId).collect(Collectors.toList()));
assertTrue(referenceIds.contains(dar.getReferenceId()));
assertFalse(createdElections.isEmpty());
assertFalse(createdVotes.isEmpty());
// Ensure that we have all primary vote types for each election type
// Data Access Elections have Chair, Dac, Final, and Agreement votes
Optional<Election> daElectionOption = createdElections.stream().filter(e -> ElectionType.DATA_ACCESS.getValue().equals(e.getElectionType())).findFirst();
assertTrue(daElectionOption.isPresent());
assertTrue(createdVotes.stream().filter(v -> v.getElectionId().equals(daElectionOption.get().getElectionId())).anyMatch(v -> v.getType().equals(VoteType.CHAIRPERSON.getValue())));
assertTrue(createdVotes.stream().filter(v -> v.getElectionId().equals(daElectionOption.get().getElectionId())).anyMatch(v -> v.getType().equals(VoteType.DAC.getValue())));
assertTrue(createdVotes.stream().filter(v -> v.getElectionId().equals(daElectionOption.get().getElectionId())).anyMatch(v -> v.getType().equals(VoteType.FINAL.getValue())));
assertTrue(createdVotes.stream().filter(v -> v.getElectionId().equals(daElectionOption.get().getElectionId())).anyMatch(v -> v.getType().equals(VoteType.AGREEMENT.getValue())));
// RP Elections have Chair and Dac votes
Optional<Election> rpElectionOption = createdElections.stream().filter(e -> ElectionType.RP.getValue().equals(e.getElectionType())).findFirst();
assertTrue(rpElectionOption.isPresent());
assertTrue(createdVotes.stream().filter(v -> v.getElectionId().equals(rpElectionOption.get().getElectionId())).anyMatch(v -> v.getType().equals(VoteType.CHAIRPERSON.getValue())));
assertTrue(createdVotes.stream().filter(v -> v.getElectionId().equals(rpElectionOption.get().getElectionId())).anyMatch(v -> v.getType().equals(VoteType.DAC.getValue())));
}
Aggregations