Search in sources :

Example 1 with Consent

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());
}
Also used : DataSet(org.broadinstitute.consent.http.models.DataSet) Consent(org.broadinstitute.consent.http.models.Consent) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) Test(org.junit.Test)

Example 2 with Consent

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);
}
Also used : DataSet(org.broadinstitute.consent.http.models.DataSet) Consent(org.broadinstitute.consent.http.models.Consent) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) Test(org.junit.Test)

Example 3 with 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;
}
Also used : DataUse(org.broadinstitute.consent.http.models.DataUse) Everything(org.broadinstitute.consent.http.models.grammar.Everything) Consent(org.broadinstitute.consent.http.models.Consent) DataUseBuilder(org.broadinstitute.consent.http.models.DataUseBuilder)

Example 4 with 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);
}
Also used : Consent(org.broadinstitute.consent.http.models.Consent) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FormDataBodyPart(org.glassfish.jersey.media.multipart.FormDataBodyPart) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 5 with Consent

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());
}
Also used : Response(javax.ws.rs.core.Response) DataSet(org.broadinstitute.consent.http.models.DataSet) Consent(org.broadinstitute.consent.http.models.Consent) UserRole(org.broadinstitute.consent.http.models.UserRole) Test(org.junit.Test)

Aggregations

Consent (org.broadinstitute.consent.http.models.Consent)163 Test (org.junit.Test)127 DataSet (org.broadinstitute.consent.http.models.DataSet)86 Election (org.broadinstitute.consent.http.models.Election)72 Dac (org.broadinstitute.consent.http.models.Dac)61 User (org.broadinstitute.consent.http.models.User)56 Vote (org.broadinstitute.consent.http.models.Vote)48 ElectionReviewVote (org.broadinstitute.consent.http.models.ElectionReviewVote)32 Response (javax.ws.rs.core.Response)31 Date (java.util.Date)25 DataAccessRequest (org.broadinstitute.consent.http.models.DataAccessRequest)23 UnknownIdentifierException (org.broadinstitute.consent.http.exceptions.UnknownIdentifierException)13 NotFoundException (javax.ws.rs.NotFoundException)12 AuthUser (org.broadinstitute.consent.http.models.AuthUser)12 IOException (java.io.IOException)8 DatasetDTO (org.broadinstitute.consent.http.models.dto.DatasetDTO)8 ArrayList (java.util.ArrayList)7 File (java.io.File)6 Timestamp (java.sql.Timestamp)6 List (java.util.List)6