Search in sources :

Example 1 with Dataset

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

Example 2 with Dataset

use of org.broadinstitute.consent.http.models.Dataset 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());
}
Also used : Vote(org.broadinstitute.consent.http.models.Vote) User(org.broadinstitute.consent.http.models.User) DataSet(org.broadinstitute.consent.http.models.DataSet) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) Election(org.broadinstitute.consent.http.models.Election)

Example 3 with Dataset

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

Example 4 with Dataset

use of org.broadinstitute.consent.http.models.Dataset in project consent by DataBiosphere.

the class VoteServiceDAOTest method testUpdateVotesWithValue_MultipleElectionsDifferentStatuses.

@Test(expected = IllegalArgumentException.class)
public void testUpdateVotesWithValue_MultipleElectionsDifferentStatuses() throws Exception {
    User user = createUser();
    DataAccessRequest dar = createDataAccessRequestV3();
    DataSet dataset = createDataset();
    Election openElection = createAccessElection(dar.getReferenceId(), dataset.getDataSetId());
    Election canceledElection = createCancelledAccessElection(dar.getReferenceId(), dataset.getDataSetId());
    Vote vote1 = createDacVote(user.getDacUserId(), openElection.getElectionId());
    Vote vote2 = createDacVote(user.getDacUserId(), canceledElection.getElectionId());
    String rationale = "rationale";
    initService();
    serviceDAO.updateVotesWithValue(List.of(vote1, vote2), true, rationale);
}
Also used : Vote(org.broadinstitute.consent.http.models.Vote) User(org.broadinstitute.consent.http.models.User) DataSet(org.broadinstitute.consent.http.models.DataSet) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) Election(org.broadinstitute.consent.http.models.Election) Test(org.junit.Test)

Example 5 with Dataset

use of org.broadinstitute.consent.http.models.Dataset in project consent by DataBiosphere.

the class VoteServiceDAOTest method testUpdateVotesWithValue_DacVote.

@Test
public void testUpdateVotesWithValue_DacVote() throws Exception {
    User user = createUser();
    DataAccessRequest dar = createDataAccessRequestV3();
    DataSet dataset = createDataset();
    Election election = createAccessElection(dar.getReferenceId(), dataset.getDataSetId());
    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());
    Election foundElection = electionDAO.findElectionById(vote.getElectionId());
    assertNotEquals(ElectionStatus.CLOSED.getValue(), foundElection.getStatus());
    assertEquals(vote.getVoteId(), votes.get(0).getVoteId());
}
Also used : Vote(org.broadinstitute.consent.http.models.Vote) User(org.broadinstitute.consent.http.models.User) DataSet(org.broadinstitute.consent.http.models.DataSet) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) Election(org.broadinstitute.consent.http.models.Election) Test(org.junit.Test)

Aggregations

DataSet (org.broadinstitute.consent.http.models.DataSet)164 Test (org.junit.Test)128 Consent (org.broadinstitute.consent.http.models.Consent)88 Election (org.broadinstitute.consent.http.models.Election)82 User (org.broadinstitute.consent.http.models.User)76 Dac (org.broadinstitute.consent.http.models.Dac)58 Vote (org.broadinstitute.consent.http.models.Vote)53 DataAccessRequest (org.broadinstitute.consent.http.models.DataAccessRequest)36 ElectionReviewVote (org.broadinstitute.consent.http.models.ElectionReviewVote)30 Date (java.util.Date)25 Response (javax.ws.rs.core.Response)22 ArrayList (java.util.ArrayList)17 NotFoundException (javax.ws.rs.NotFoundException)16 AuthUser (org.broadinstitute.consent.http.models.AuthUser)16 DarCollection (org.broadinstitute.consent.http.models.DarCollection)16 UserRole (org.broadinstitute.consent.http.models.UserRole)14 DatasetDTO (org.broadinstitute.consent.http.models.dto.DatasetDTO)13 List (java.util.List)11 DataAccessRequestData (org.broadinstitute.consent.http.models.DataAccessRequestData)10 Collectors (java.util.stream.Collectors)9