use of org.broadinstitute.consent.http.models.Consent in project consent by DataBiosphere.
the class DatasetResourceTest method testDisableDataSetSuccessChairperson.
@Test
public void testDisableDataSetSuccessChairperson() {
DataSet dataSet = new DataSet();
dataSet.setDataSetId(1);
Consent consent = new Consent();
consent.setDacId(1);
when(consentService.getConsentFromDatasetID(any())).thenReturn(consent);
when(dacUser.hasUserRole(UserRoles.ADMIN)).thenReturn(false);
UserRole role = new UserRole(UserRoles.CHAIRPERSON.getRoleId(), UserRoles.CHAIRPERSON.getRoleName());
role.setDacId(1);
when(dacUser.getRoles()).thenReturn(List.of(role));
when(userService.findUserByEmail(authUser.getEmail())).thenReturn(dacUser);
when(datasetService.findDatasetById(any())).thenReturn(dataSet);
initResource();
Response response = resource.disableDataSet(authUser, 1, true, null);
assertEquals(200, response.getStatus());
}
use of org.broadinstitute.consent.http.models.Consent in project consent by DataBiosphere.
the class DatasetResourceTest method testDisableDataSetErrorNullConsent.
@Test
public void testDisableDataSetErrorNullConsent() {
DataSet dataSet = new DataSet();
dataSet.setDataSetId(1);
Consent consent = new Consent();
when(consentService.getConsentFromDatasetID(any())).thenReturn(consent);
when(dacUser.hasUserRole(UserRoles.ADMIN)).thenReturn(false);
UserRole role = new UserRole(UserRoles.CHAIRPERSON.getRoleId(), UserRoles.CHAIRPERSON.getRoleName());
role.setDacId(1);
when(dacUser.getRoles()).thenReturn(List.of(role));
when(userService.findUserByEmail(authUser.getEmail())).thenReturn(dacUser);
when(datasetService.findDatasetById(any())).thenReturn(dataSet);
initResource();
Response response = resource.disableDataSet(authUser, 1, true, null);
assertEquals(404, response.getStatus());
}
use of org.broadinstitute.consent.http.models.Consent in project consent by DataBiosphere.
the class DatasetResourceTest method testDeleteErrorMismatch.
@Test
public void testDeleteErrorMismatch() {
DataSet dataSet = new DataSet();
dataSet.setDataSetId(1);
Consent consent = new Consent();
consent.setDacId(2);
when(consentService.getConsentFromDatasetID(any())).thenReturn(consent);
when(dacUser.hasUserRole(UserRoles.ADMIN)).thenReturn(false);
UserRole role = new UserRole(UserRoles.CHAIRPERSON.getRoleId(), UserRoles.CHAIRPERSON.getRoleName());
role.setDacId(1);
when(dacUser.getRoles()).thenReturn(List.of(role));
when(userService.findUserByEmail(authUser.getEmail())).thenReturn(dacUser);
when(datasetService.findDatasetById(any())).thenReturn(dataSet);
initResource();
Response response = resource.delete(authUser, 1, null);
assertEquals(404, response.getStatus());
}
use of org.broadinstitute.consent.http.models.Consent in project consent by DataBiosphere.
the class DatasetResourceTest method testCreateDatasetSuccess.
@Test
public void testCreateDatasetSuccess() throws Exception {
DatasetDTO result = createMockDatasetDTO();
Consent consent = new Consent();
String json = createPropertiesJson("Dataset Name", "test");
when(datasetService.getDatasetByName("test")).thenReturn(null);
when(datasetService.createDatasetWithConsent(any(), any(), anyInt())).thenReturn(result);
when(datasetService.createConsentForDataset(any())).thenReturn(consent);
when(datasetService.getDatasetDTO(any())).thenReturn(result);
when(authUser.getGoogleUser()).thenReturn(googleUser);
when(googleUser.getEmail()).thenReturn("email@email.com");
when(userService.findUserByEmail(any())).thenReturn(dacUser);
when(dacUser.getDacUserId()).thenReturn(1);
when(uriInfo.getRequestUriBuilder()).thenReturn(uriBuilder);
when(uriBuilder.replacePath(anyString())).thenReturn(uriBuilder);
when(uriBuilder.build(anyString())).thenReturn(new URI("/api/dataset/1"));
initResource();
Response response = resource.createDataset(authUser, uriInfo, json);
assertEquals(201, response.getStatus());
assertEquals(result, response.getEntity());
}
use of org.broadinstitute.consent.http.models.Consent in project consent by DataBiosphere.
the class ConsentElectionResource method createElectionURI.
private URI createElectionURI(UriInfo info, Election election, String consentId) throws Exception {
// For a consent election, any dataset associated to the consent is
// appropriate for assignment to this election.
Optional<DataSet> dataset = dacService.findDatasetsByConsentId(consentId).stream().findFirst();
dataset.ifPresent(dataSet -> election.setDataSetId(dataSet.getDataSetId()));
Election newElection = electionService.createElection(election, consentId, ElectionType.TRANSLATE_DUL);
List<Vote> votes = voteService.createVotes(newElection, ElectionType.TRANSLATE_DUL, false);
List<Vote> dulVotes = votes.stream().filter(vote -> vote.getType().equals(VoteType.DAC.getValue())).collect(Collectors.toList());
emailNotifierService.sendNewCaseMessageToList(dulVotes, newElection);
return info.getRequestUriBuilder().build();
}
Aggregations