Search in sources :

Example 1 with DacDAO

use of org.broadinstitute.consent.http.db.DacDAO in project consent by DataBiosphere.

the class DacServiceTest method testAddDacMember.

@Test
public void testAddDacMember() {
    Gson gson = new Gson();
    User user = getDacUsers().get(0);
    Dac dac = getDacs().get(0);
    when(userDAO.findUserById(any())).thenReturn(user);
    when(userDAO.findUserById(any())).thenReturn(user);
    when(dacDAO.findUserRolesForUser(any())).thenReturn(getDacUsers().get(0).getRoles());
    List<Election> elections = getElections().stream().map(e -> {
        Election newE = gson.fromJson(gson.toJson(e), Election.class);
        newE.setElectionType(ElectionType.DATA_ACCESS.getValue());
        newE.setReferenceId(UUID.randomUUID().toString());
        return newE;
    }).collect(Collectors.toList());
    DataAccessRequest dar = new DataAccessRequest();
    dar.setData(new DataAccessRequestData());
    dar.getData().setRestriction(new Everything());
    when(dataAccessRequestDAO.findByReferenceId(any())).thenReturn(dar);
    when(electionDAO.findOpenElectionsByDacId(any())).thenReturn(elections);
    when(voteService.createVotes(any(), any(), anyBoolean())).thenReturn(Collections.emptyList());
    doNothing().when(dacDAO).addDacMember(anyInt(), anyInt(), anyInt());
    initService();
    Role role = new Role(UserRoles.CHAIRPERSON.getRoleId(), UserRoles.CHAIRPERSON.getRoleName());
    User user1 = service.addDacMember(role, user, dac);
    Assert.assertNotNull(user1);
    Assert.assertFalse(user1.getRoles().isEmpty());
    verify(voteService, times(elections.size())).createVotesForUser(any(), any(), any(), anyBoolean());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MockitoAnnotations.openMocks(org.mockito.MockitoAnnotations.openMocks) IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) Mock(org.mockito.Mock) DatasetDTO(org.broadinstitute.consent.http.models.dto.DatasetDTO) UserRoles(org.broadinstitute.consent.http.enumeration.UserRoles) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) ArrayList(java.util.ArrayList) DatasetDAO(org.broadinstitute.consent.http.db.DatasetDAO) Gson(com.google.gson.Gson) ElectionType(org.broadinstitute.consent.http.enumeration.ElectionType) AuthUser(org.broadinstitute.consent.http.models.AuthUser) BadRequestException(javax.ws.rs.BadRequestException) Role(org.broadinstitute.consent.http.models.Role) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) UserDAO(org.broadinstitute.consent.http.db.UserDAO) Before(org.junit.Before) DataAccessRequestData(org.broadinstitute.consent.http.models.DataAccessRequestData) DataSet(org.broadinstitute.consent.http.models.DataSet) DacDAO(org.broadinstitute.consent.http.db.DacDAO) DataAccessRequestDAO(org.broadinstitute.consent.http.db.DataAccessRequestDAO) ConsentManage(org.broadinstitute.consent.http.models.ConsentManage) Collection(java.util.Collection) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) Set(java.util.Set) UserRole(org.broadinstitute.consent.http.models.UserRole) Mockito.times(org.mockito.Mockito.times) User(org.broadinstitute.consent.http.models.User) Test(org.junit.Test) Mockito.doNothing(org.mockito.Mockito.doNothing) Mockito.when(org.mockito.Mockito.when) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Dac(org.broadinstitute.consent.http.models.Dac) Mockito.verify(org.mockito.Mockito.verify) ElectionDAO(org.broadinstitute.consent.http.db.ElectionDAO) List(java.util.List) Stream(java.util.stream.Stream) Election(org.broadinstitute.consent.http.models.Election) Everything(org.broadinstitute.consent.http.models.grammar.Everything) Assert(org.junit.Assert) Collections(java.util.Collections) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Consent(org.broadinstitute.consent.http.models.Consent) DataAccessRequestData(org.broadinstitute.consent.http.models.DataAccessRequestData) Role(org.broadinstitute.consent.http.models.Role) UserRole(org.broadinstitute.consent.http.models.UserRole) Everything(org.broadinstitute.consent.http.models.grammar.Everything) AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) Dac(org.broadinstitute.consent.http.models.Dac) Gson(com.google.gson.Gson) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) Election(org.broadinstitute.consent.http.models.Election) Test(org.junit.Test)

Aggregations

Gson (com.google.gson.Gson)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Set (java.util.Set)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 Stream (java.util.stream.Stream)1 BadRequestException (javax.ws.rs.BadRequestException)1 DacDAO (org.broadinstitute.consent.http.db.DacDAO)1 DataAccessRequestDAO (org.broadinstitute.consent.http.db.DataAccessRequestDAO)1 DatasetDAO (org.broadinstitute.consent.http.db.DatasetDAO)1 ElectionDAO (org.broadinstitute.consent.http.db.ElectionDAO)1 UserDAO (org.broadinstitute.consent.http.db.UserDAO)1 ElectionType (org.broadinstitute.consent.http.enumeration.ElectionType)1 UserRoles (org.broadinstitute.consent.http.enumeration.UserRoles)1 AuthUser (org.broadinstitute.consent.http.models.AuthUser)1