Search in sources :

Example 16 with Vote

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

the class VoteServiceTest method testMemberCreateVotesDataAccessManualReview.

@Test
public void testMemberCreateVotesDataAccessManualReview() {
    setUpUserAndElectionVotes(UserRoles.MEMBER);
    initService();
    List<Vote> votes = service.createVotes(new Election(), ElectionType.DATA_ACCESS, false);
    assertFalse(votes.isEmpty());
    // Should create 1 member vote
    assertEquals(1, votes.size());
}
Also used : Vote(org.broadinstitute.consent.http.models.Vote) Election(org.broadinstitute.consent.http.models.Election) Test(org.junit.Test)

Example 17 with Vote

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

the class VoteServiceTest method testUpdateVote_ByReferenceId.

@Test
public void testUpdateVote_ByReferenceId() {
    Vote v = setUpTestVote(false, false);
    when(voteDAO.checkVoteById("test", v.getVoteId())).thenReturn(v.getVoteId());
    when(electionDAO.getOpenElectionIdByReferenceId("test")).thenReturn(1);
    initService();
    Vote vote = service.updateVote(v, v.getVoteId(), "test");
    assertNotNull(vote);
}
Also used : Vote(org.broadinstitute.consent.http.models.Vote) Test(org.junit.Test)

Example 18 with Vote

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

the class VoteServiceTest method testMemberCreateVotesDataAccess.

@Test
public void testMemberCreateVotesDataAccess() {
    setUpUserAndElectionVotes(UserRoles.MEMBER);
    initService();
    List<Vote> votes = service.createVotes(new Election(), ElectionType.DATA_ACCESS, false);
    assertFalse(votes.isEmpty());
    // Should create 1 member vote
    assertEquals(1, votes.size());
}
Also used : Vote(org.broadinstitute.consent.http.models.Vote) Election(org.broadinstitute.consent.http.models.Election) Test(org.junit.Test)

Example 19 with Vote

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

the class VoteServiceTest method testNotifyResearchersOfDarApproval_2Dars_2Collections.

@Test
public void testNotifyResearchersOfDarApproval_2Dars_2Collections() throws Exception {
    String referenceId1 = UUID.randomUUID().toString();
    String referenceId2 = UUID.randomUUID().toString();
    Vote v1 = new Vote();
    v1.setVote(true);
    v1.setType(VoteType.FINAL.getValue());
    v1.setElectionId(1);
    v1.setDacUserId(1);
    Vote v2 = new Vote();
    v2.setVote(true);
    v2.setType(VoteType.FINAL.getValue());
    v2.setElectionId(2);
    v2.setDacUserId(1);
    Dataset d1 = new Dataset();
    d1.setDataSetId(1);
    d1.setName(RandomStringUtils.random(50, true, false));
    d1.setAlias(1);
    d1.setDataUse(new DataUseBuilder().setGeneralUse(false).setCommercialUse(true).build());
    Dataset d2 = new Dataset();
    d2.setDataSetId(2);
    d2.setName(RandomStringUtils.random(50, true, false));
    d2.setAlias(2);
    d2.setDataUse(new DataUseBuilder().setGeneralUse(false).setHmbResearch(true).build());
    Election e1 = new Election();
    e1.setElectionId(1);
    e1.setReferenceId(referenceId1);
    e1.setElectionType(ElectionType.DATA_ACCESS.getValue());
    e1.setDataSetId(1);
    Election e2 = new Election();
    e2.setElectionId(2);
    e2.setReferenceId(referenceId2);
    e2.setElectionType(ElectionType.DATA_ACCESS.getValue());
    e2.setDataSetId(2);
    DataAccessRequest dar1 = new DataAccessRequest();
    DataAccessRequestData data1 = new DataAccessRequestData();
    data1.setDatasetIds(List.of(d1.getDataSetId()));
    dar1.setCollectionId(1);
    dar1.setData(data1);
    dar1.setReferenceId(referenceId1);
    DataAccessRequest dar2 = new DataAccessRequest();
    DataAccessRequestData data2 = new DataAccessRequestData();
    data2.setDatasetIds(List.of(d2.getDataSetId()));
    dar2.setCollectionId(2);
    dar2.setData(data2);
    dar2.setReferenceId(referenceId2);
    DarCollection c1 = new DarCollection();
    c1.setDarCollectionId(1);
    c1.addDar(dar1);
    c1.setDarCode("DAR-CODE-1");
    DarCollection c2 = new DarCollection();
    c2.setDarCollectionId(2);
    c2.addDar(dar2);
    c2.setDarCode("DAR-CODE-2");
    when(electionDAO.findElectionsByIds(any())).thenReturn(List.of(e1, e2));
    when(dataAccessRequestDAO.findByReferenceIds(any())).thenReturn(List.of(dar1, dar2));
    when(darCollectionDAO.findDARCollectionByCollectionIds(any())).thenReturn(List.of(c1, c2));
    when(datasetDAO.findDatasetsByIdList(any())).thenReturn(List.of(d1, d2));
    spy(emailNotifierService);
    initService();
    service.notifyResearchersOfDarApproval(List.of(v1, v2));
    // Since we have 2 collections with different DAR/Datasets, we should be sending 2 emails
    verify(emailNotifierService, times(2)).sendResearcherDarApproved(any(), any(), anyList(), any());
}
Also used : DataAccessRequestData(org.broadinstitute.consent.http.models.DataAccessRequestData) Vote(org.broadinstitute.consent.http.models.Vote) Dataset(org.broadinstitute.consent.http.models.Dataset) DataUseBuilder(org.broadinstitute.consent.http.models.DataUseBuilder) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Election(org.broadinstitute.consent.http.models.Election) DarCollection(org.broadinstitute.consent.http.models.DarCollection) Test(org.junit.Test)

Example 20 with Vote

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

the class VoteServiceTest method testNotifyResearchersOfDarApproval_2Dars_1Collection.

@Test
public void testNotifyResearchersOfDarApproval_2Dars_1Collection() throws Exception {
    String referenceId1 = UUID.randomUUID().toString();
    String referenceId2 = UUID.randomUUID().toString();
    Vote v1 = new Vote();
    v1.setVote(true);
    v1.setType(VoteType.FINAL.getValue());
    v1.setElectionId(1);
    v1.setDacUserId(1);
    Vote v2 = new Vote();
    v2.setVote(true);
    v2.setType(VoteType.FINAL.getValue());
    v2.setElectionId(2);
    v2.setDacUserId(1);
    Dataset d1 = new Dataset();
    d1.setDataSetId(1);
    d1.setName(RandomStringUtils.random(50, true, false));
    d1.setAlias(1);
    d1.setDataUse(new DataUseBuilder().setGeneralUse(false).setCommercialUse(true).build());
    Dataset d2 = new Dataset();
    d2.setDataSetId(2);
    d2.setName(RandomStringUtils.random(50, true, false));
    d2.setAlias(2);
    d2.setDataUse(new DataUseBuilder().setGeneralUse(false).setHmbResearch(true).build());
    Election e1 = new Election();
    e1.setElectionId(1);
    e1.setReferenceId(referenceId1);
    e1.setElectionType(ElectionType.DATA_ACCESS.getValue());
    e1.setDataSetId(1);
    Election e2 = new Election();
    e2.setElectionId(2);
    e2.setReferenceId(referenceId2);
    e2.setElectionType(ElectionType.DATA_ACCESS.getValue());
    e2.setDataSetId(2);
    DataAccessRequest dar1 = new DataAccessRequest();
    DataAccessRequestData data1 = new DataAccessRequestData();
    data1.setDatasetIds(List.of(d1.getDataSetId()));
    dar1.setCollectionId(1);
    dar1.setData(data1);
    dar1.setReferenceId(referenceId1);
    DataAccessRequest dar2 = new DataAccessRequest();
    DataAccessRequestData data2 = new DataAccessRequestData();
    data2.setDatasetIds(List.of(d2.getDataSetId()));
    dar2.setCollectionId(1);
    dar2.setData(data2);
    dar2.setReferenceId(referenceId2);
    DarCollection c = new DarCollection();
    c.setDarCollectionId(1);
    c.addDar(dar1);
    c.addDar(dar2);
    c.setDarCode("DAR-CODE");
    when(electionDAO.findElectionsByIds(any())).thenReturn(List.of(e1, e2));
    when(dataAccessRequestDAO.findByReferenceIds(any())).thenReturn(List.of(dar1, dar2));
    when(darCollectionDAO.findDARCollectionByCollectionIds(any())).thenReturn(List.of(c));
    when(datasetDAO.findDatasetsByIdList(any())).thenReturn(List.of(d1, d2));
    spy(emailNotifierService);
    initService();
    service.notifyResearchersOfDarApproval(List.of(v1, v2));
    // Since we have 1 collection with different DAR/Datasets, we should be sending 1 email
    verify(emailNotifierService, times(1)).sendResearcherDarApproved(any(), any(), anyList(), any());
}
Also used : DataAccessRequestData(org.broadinstitute.consent.http.models.DataAccessRequestData) Vote(org.broadinstitute.consent.http.models.Vote) Dataset(org.broadinstitute.consent.http.models.Dataset) DataUseBuilder(org.broadinstitute.consent.http.models.DataUseBuilder) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) 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