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());
}
Aggregations