Search in sources :

Example 21 with Vote

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");
}
Also used : Vote(org.broadinstitute.consent.http.models.Vote) Election(org.broadinstitute.consent.http.models.Election) Test(org.junit.Test)

Example 22 with Vote

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");
}
Also used : Vote(org.broadinstitute.consent.http.models.Vote) Election(org.broadinstitute.consent.http.models.Election) Test(org.junit.Test)

Example 23 with Vote

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());
}
Also used : Vote(org.broadinstitute.consent.http.models.Vote) Election(org.broadinstitute.consent.http.models.Election) Test(org.junit.Test)

Example 24 with Vote

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());
}
Also used : Vote(org.broadinstitute.consent.http.models.Vote) Election(org.broadinstitute.consent.http.models.Election) Test(org.junit.Test)

Example 25 with Vote

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())));
}
Also used : ElectionStatus(org.broadinstitute.consent.http.enumeration.ElectionStatus) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) Dataset(org.broadinstitute.consent.http.models.Dataset) Date(java.util.Date) Assert.assertNotNull(org.junit.Assert.assertNotNull) UserRole(org.broadinstitute.consent.http.models.UserRole) Vote(org.broadinstitute.consent.http.models.Vote) Assert.assertTrue(org.junit.Assert.assertTrue) User(org.broadinstitute.consent.http.models.User) Test(org.junit.Test) UserRoles(org.broadinstitute.consent.http.enumeration.UserRoles) DarCollection(org.broadinstitute.consent.http.models.DarCollection) Collectors(java.util.stream.Collectors) Dac(org.broadinstitute.consent.http.models.Dac) DAOTestHelper(org.broadinstitute.consent.http.db.DAOTestHelper) List(java.util.List) VoteType(org.broadinstitute.consent.http.enumeration.VoteType) Election(org.broadinstitute.consent.http.models.Election) Assert.assertFalse(org.junit.Assert.assertFalse) ElectionType(org.broadinstitute.consent.http.enumeration.ElectionType) Optional(java.util.Optional) Assert.assertEquals(org.junit.Assert.assertEquals) Consent(org.broadinstitute.consent.http.models.Consent) Vote(org.broadinstitute.consent.http.models.Vote) User(org.broadinstitute.consent.http.models.User) UserRole(org.broadinstitute.consent.http.models.UserRole) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) Election(org.broadinstitute.consent.http.models.Election) DarCollection(org.broadinstitute.consent.http.models.DarCollection) Test(org.junit.Test)

Aggregations

Vote (org.broadinstitute.consent.http.models.Vote)167 Test (org.junit.Test)124 Election (org.broadinstitute.consent.http.models.Election)105 User (org.broadinstitute.consent.http.models.User)90 Dataset (org.broadinstitute.consent.http.models.Dataset)59 Consent (org.broadinstitute.consent.http.models.Consent)57 Dac (org.broadinstitute.consent.http.models.Dac)45 DataAccessRequest (org.broadinstitute.consent.http.models.DataAccessRequest)45 Response (javax.ws.rs.core.Response)37 AuthUser (org.broadinstitute.consent.http.models.AuthUser)30 ElectionReviewVote (org.broadinstitute.consent.http.models.ElectionReviewVote)30 UserRole (org.broadinstitute.consent.http.models.UserRole)25 Date (java.util.Date)21 NotFoundException (javax.ws.rs.NotFoundException)18 List (java.util.List)16 ArrayList (java.util.ArrayList)14 Collectors (java.util.stream.Collectors)14 ElectionType (org.broadinstitute.consent.http.enumeration.ElectionType)14 DarCollection (org.broadinstitute.consent.http.models.DarCollection)14 DataAccessRequestData (org.broadinstitute.consent.http.models.DataAccessRequestData)14