use of org.broadinstitute.consent.http.models.Consent in project consent by DataBiosphere.
the class DataAccessRequestResourceTest method testDescribeConsentForDarCase5.
/**
* Negative case where user does not have access
*/
@Test(expected = ForbiddenException.class)
public void testDescribeConsentForDarCase5() {
DataAccessRequest dar = generateDataAccessRequest();
when(dataAccessRequestService.findByReferenceId(any())).thenReturn(dar);
DataSet dataSet = new DataSet();
dataSet.setDataSetId(1);
when(consentService.getConsentFromDatasetID(any())).thenReturn(new Consent());
when(user.getDacUserId()).thenReturn(dar.getUserId() + 1);
when(userService.findUserByEmail(any())).thenReturn(user);
resource = new DataAccessRequestResource(dataAccessRequestService, userService, consentService, electionService);
resource.describeConsentForDAR(authUser, dar.getReferenceId());
}
use of org.broadinstitute.consent.http.models.Consent in project consent by DataBiosphere.
the class DataAccessRequestResourceTest method testDescribeConsentForDarCase2.
/**
* Positive case where a DAR references a string dataset id
*/
@Test
public void testDescribeConsentForDarCase2() {
DataAccessRequest dar = generateDataAccessRequest();
when(dataAccessRequestService.findByReferenceId(any())).thenReturn(dar);
DataSet dataSet = new DataSet();
dataSet.setDataSetId(1);
when(consentService.getConsentFromDatasetID(any())).thenReturn(new Consent());
when(user.getDacUserId()).thenReturn(dar.getUserId());
when(userService.findUserByEmail(any())).thenReturn(user);
resource = new DataAccessRequestResource(dataAccessRequestService, userService, consentService, electionService);
Consent consent = resource.describeConsentForDAR(authUser, dar.getReferenceId());
assertNotNull(consent);
}
use of org.broadinstitute.consent.http.models.Consent in project consent by DataBiosphere.
the class DataUseLetterResourceTest method setupConsent.
private Consent setupConsent(String dul) {
DataUse dataUse = new DataUseBuilder().setGeneralUse(true).build();
Consent consent = new Consent();
consent.setDulName(dul);
consent.setUseRestriction(new Everything());
consent.setConsentId(UUID.randomUUID().toString());
consent.setDataUse(dataUse);
return consent;
}
use of org.broadinstitute.consent.http.models.Consent in project consent by DataBiosphere.
the class DataUseLetterResourceTest method testCreateDUL.
@Test
public void testCreateDUL() throws Exception {
Consent consent = setupConsent(null);
File fileToUpload = File.createTempFile("temp", "pdf");
fileToUpload.deleteOnExit();
when(store.postStorageDocument(any(InputStream.class), eq("application/pdf"), anyString())).thenReturn(consentDulPath(consent.getConsentId()));
when(ct.getFileName()).thenReturn("temp.pdf");
// noinspection ResultOfMethodCallIgnored
fileToUpload.createNewFile();
FormDataBodyPart bodyPart = new FormDataBodyPart();
bodyPart.setContentDisposition(ct);
bodyPart.setMediaType(MediaType.valueOf("application/pdf"));
when(consentService.updateConsentDul(any(), any(), any())).thenReturn(consent);
initResource();
Consent c = resource.createDUL(new FileInputStream(fileToUpload), bodyPart, consent.getConsentId(), "temp.pdf", user);
assertNotNull(c);
}
use of org.broadinstitute.consent.http.models.Consent in project consent by DataBiosphere.
the class DatasetResourceTest method testDisableDataSetErrorMismatch.
@Test
public void testDisableDataSetErrorMismatch() {
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.disableDataSet(authUser, 1, true, null);
assertEquals(404, response.getStatus());
}
Aggregations