use of org.broadinstitute.consent.http.models.Vote in project consent by DataBiosphere.
the class DarCollectionServiceDAOTest method testCreateElectionsForDarCollectionChair.
/**
* This test covers the case where:
* - User is a chairperson
* - Collection has 1 DAR/Dataset combinations
* - Elections created should be for the DAR/Dataset for the user
*/
@Test
public void testCreateElectionsForDarCollectionChair() throws Exception {
initService();
DarCollection collection = setUpDarCollectionWithDacDataset();
Optional<DataAccessRequest> dar = collection.getDars().values().stream().findFirst();
assertTrue(dar.isPresent());
Integer datasetId = dar.get().getData().getDatasetIds().get(0);
assertNotNull(datasetId);
Optional<Dac> dac = dacDAO.findDacsForDatasetIds(List.of(datasetId)).stream().findFirst();
assertTrue(dac.isPresent());
List<User> dacUsers = dacDAO.findMembersByDacId(dac.get().getDacId());
Optional<User> chair = dacUsers.stream().filter(u -> u.hasUserRole(UserRoles.CHAIRPERSON)).findFirst();
assertTrue(chair.isPresent());
List<String> referenceIds = serviceDAO.createElectionsForDarCollection(chair.get(), collection);
List<Election> createdElections = electionDAO.findLastElectionsByReferenceIds(List.of(dar.get().getReferenceId()));
List<Vote> createdVotes = voteDAO.findVotesByElectionIds(createdElections.stream().map(Election::getElectionId).collect(Collectors.toList()));
assertTrue(referenceIds.contains(dar.get().getReferenceId()));
// Ensure that we have an access and rp election
assertFalse(createdElections.isEmpty());
assertTrue(createdElections.stream().anyMatch(e -> e.getElectionType().equals(ElectionType.DATA_ACCESS.getValue())));
assertTrue(createdElections.stream().anyMatch(e -> e.getElectionType().equals(ElectionType.RP.getValue())));
// Ensure that we have primary vote types
assertFalse(createdVotes.isEmpty());
assertTrue(createdVotes.stream().anyMatch(v -> v.getType().equals(VoteType.CHAIRPERSON.getValue())));
assertTrue(createdVotes.stream().anyMatch(v -> v.getType().equals(VoteType.FINAL.getValue())));
assertTrue(createdVotes.stream().anyMatch(v -> v.getType().equals(VoteType.DAC.getValue())));
assertTrue(createdVotes.stream().anyMatch(v -> v.getType().equals(VoteType.AGREEMENT.getValue())));
}
use of org.broadinstitute.consent.http.models.Vote in project consent by DataBiosphere.
the class DarCollectionServiceDAOTest method testCreateElectionsForDarCollectionWithMultipleDatasetsForAdmin.
/**
* This test covers the case where:
* - User is an admin
* - Collection has 2 DAR/Dataset combinations
* - User is an Admin
* - Elections created should only be for ALL the DAR/Dataset combinations
*/
@Test
public void testCreateElectionsForDarCollectionWithMultipleDatasetsForAdmin() 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);
// Add another DAR with Dataset in a separate DAC to the collection
DataAccessRequest dar2 = addDARWithDacAndDatasetToCollection(collection);
// refresh the collection
collection = darCollectionDAO.findDARCollectionByCollectionId(collection.getDarCollectionId());
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()));
assertTrue(referenceIds.contains(dar2.getReferenceId()));
// Ensure that we have an access and rp election
assertFalse(createdElections.isEmpty());
assertTrue(createdElections.stream().anyMatch(e -> e.getElectionType().equals(ElectionType.DATA_ACCESS.getValue())));
assertTrue(createdElections.stream().anyMatch(e -> e.getElectionType().equals(ElectionType.RP.getValue())));
// Ensure that we have primary vote types
assertFalse(createdVotes.isEmpty());
assertTrue(createdVotes.stream().anyMatch(v -> v.getType().equals(VoteType.CHAIRPERSON.getValue())));
assertTrue(createdVotes.stream().anyMatch(v -> v.getType().equals(VoteType.FINAL.getValue())));
assertTrue(createdVotes.stream().anyMatch(v -> v.getType().equals(VoteType.DAC.getValue())));
assertTrue(createdVotes.stream().anyMatch(v -> v.getType().equals(VoteType.AGREEMENT.getValue())));
// Make sure that we DID create elections for the additional DAR/Dataset combination
List<Election> additionalCreatedElections = electionDAO.findLastElectionsByReferenceIds(List.of(dar2.getReferenceId()));
assertFalse(additionalCreatedElections.isEmpty());
}
use of org.broadinstitute.consent.http.models.Vote in project consent by DataBiosphere.
the class VoteServiceDAOTest method testUpdateVotesWithValue_NoRationale.
@Test
public void testUpdateVotesWithValue_NoRationale() throws Exception {
User user = createUser();
DataAccessRequest dar = createDataAccessRequestV3();
Dataset dataset = createDataset();
Election election = createAccessElection(dar.getReferenceId(), dataset.getDataSetId());
Vote vote = createFinalVote(user.getDacUserId(), election.getElectionId());
initService();
List<Vote> votes = serviceDAO.updateVotesWithValue(List.of(vote), true, null);
assertNotNull(votes);
assertFalse(votes.isEmpty());
assertTrue(votes.get(0).getVote());
assertNull(votes.get(0).getRationale());
assertEquals(vote.getVoteId(), votes.get(0).getVoteId());
}
use of org.broadinstitute.consent.http.models.Vote in project consent by DataBiosphere.
the class VoteServiceDAOTest method testUpdateVotesWithValue_MultipleElectionTypes.
@Test
public void testUpdateVotesWithValue_MultipleElectionTypes() throws Exception {
User user = createUser();
DataAccessRequest dar = createDataAccessRequestV3();
Dataset dataset = createDataset();
Election rpElection1 = createRPElection(dar.getReferenceId(), dataset.getDataSetId());
Election rpElection2 = createRPElection(dar.getReferenceId(), dataset.getDataSetId());
Election accessElection = createAccessElection(dar.getReferenceId(), dataset.getDataSetId());
changeElectionStatus(rpElection1, ElectionStatus.CLOSED);
Vote vote1 = createDacVote(user.getDacUserId(), rpElection1.getElectionId());
Vote vote2 = createDacVote(user.getDacUserId(), rpElection2.getElectionId());
Vote vote3 = createDacVote(user.getDacUserId(), accessElection.getElectionId());
String rationale = "rationale";
initService();
List<Vote> votes = serviceDAO.updateVotesWithValue(List.of(vote1, vote2, vote3), true, rationale);
assertNotNull(votes);
assertFalse(votes.isEmpty());
List<Integer> requestVoteIds = Stream.of(vote1, vote2, vote3).map(Vote::getVoteId).collect(Collectors.toList());
votes.forEach(v -> {
assertTrue(v.getVote());
assertEquals(rationale, v.getRationale());
assertTrue(requestVoteIds.contains(v.getVoteId()));
});
}
use of org.broadinstitute.consent.http.models.Vote in project consent by DataBiosphere.
the class VoteServiceDAOTest method testUpdateVotesWithValue_MultipleVotes.
@Test
public void testUpdateVotesWithValue_MultipleVotes() throws Exception {
User user = createUser();
DataAccessRequest dar = createDataAccessRequestV3();
Dataset dataset = createDataset();
Election election = createAccessElection(dar.getReferenceId(), dataset.getDataSetId());
Vote vote1 = createDacVote(user.getDacUserId(), election.getElectionId());
Vote vote2 = createDacVote(user.getDacUserId(), election.getElectionId());
Vote vote3 = createDacVote(user.getDacUserId(), election.getElectionId());
String rationale = "rationale";
initService();
List<Vote> votes = serviceDAO.updateVotesWithValue(List.of(vote1, vote2, vote3), true, rationale);
assertNotNull(votes);
assertFalse(votes.isEmpty());
List<Integer> requestVoteIds = Stream.of(vote1, vote2, vote3).map(Vote::getVoteId).collect(Collectors.toList());
votes.forEach(v -> {
assertTrue(v.getVote());
assertEquals(rationale, v.getRationale());
assertTrue(requestVoteIds.contains(v.getVoteId()));
});
}
Aggregations