use of org.broadinstitute.consent.http.models.DataAccessRequest in project consent by DataBiosphere.
the class DarCollectionServiceDAOTest method testCreateElectionsForDarCollectionAfterCancelingEarlierElections.
@Test
public void testCreateElectionsForDarCollectionAfterCancelingEarlierElections() throws Exception {
initService();
DarCollection collection = setUpDarCollectionWithDacDataset();
DataAccessRequest dar = collection.getDars().values().stream().findFirst().orElse(null);
assertNotNull(dar);
// create elections & votes:
serviceDAO.createElectionsForDarCollection(collection);
// cancel those elections:
electionDAO.findLastElectionsByReferenceIds(List.of(dar.getReferenceId())).forEach(e -> electionDAO.updateElectionById(e.getElectionId(), ElectionStatus.CANCELED.getValue(), new Date()));
// re-create elections & new votes:
serviceDAO.createElectionsForDarCollection(collection);
List<Election> createdElections = electionDAO.findLastElectionsByReferenceIds(List.of(dar.getReferenceId()));
// Ensure that we have the right number of access and rp elections, i.e. 1 each
assertFalse(createdElections.isEmpty());
assertEquals(2, createdElections.size());
assertEquals(1, createdElections.stream().filter(e -> e.getElectionType().equals(ElectionType.DATA_ACCESS.getValue())).count());
assertEquals(1, createdElections.stream().filter(e -> e.getElectionType().equals(ElectionType.RP.getValue())).count());
}
use of org.broadinstitute.consent.http.models.DataAccessRequest in project consent by DataBiosphere.
the class DarCollectionServiceDAOTest method testCreateElectionsForDarCollection.
@Test
public void testCreateElectionsForDarCollection() throws Exception {
initService();
DarCollection collection = setUpDarCollectionWithDacDataset();
DataAccessRequest dar = collection.getDars().values().stream().findFirst().orElse(null);
assertNotNull(dar);
serviceDAO.createElectionsForDarCollection(collection);
List<Election> createdElections = electionDAO.findLastElectionsByReferenceIds(List.of(dar.getReferenceId()));
List<Vote> createdVotes = voteDAO.findVotesByElectionIds(createdElections.stream().map(Election::getElectionId).collect(Collectors.toList()));
// 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.DataAccessRequest 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()));
});
}
use of org.broadinstitute.consent.http.models.DataAccessRequest in project consent by DataBiosphere.
the class VoteServiceDAOTest method testUpdateVotesWithValue_RPElectionWithStatus.
private void testUpdateVotesWithValue_RPElectionWithStatus(ElectionStatus status) throws Exception {
User user = createUser();
DataAccessRequest dar = createDataAccessRequestV3();
DataSet dataset = createDataset();
Election election = createRPElection(dar.getReferenceId(), dataset.getDataSetId());
changeElectionStatus(election, status);
Vote vote = createDacVote(user.getDacUserId(), election.getElectionId());
String rationale = "rationale";
initService();
List<Vote> votes = serviceDAO.updateVotesWithValue(List.of(vote), true, rationale);
assertNotNull(votes);
assertFalse(votes.isEmpty());
assertTrue(votes.get(0).getVote());
assertEquals(rationale, votes.get(0).getRationale());
assertEquals(vote.getVoteId(), votes.get(0).getVoteId());
}
use of org.broadinstitute.consent.http.models.DataAccessRequest 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());
}
Aggregations