Search in sources :

Example 1 with DataUseBuilder

use of org.broadinstitute.consent.http.models.DataUseBuilder in project consent by DataBiosphere.

the class UseRestrictionConverterTest method testTranslateDataUsePurpose.

/*
     * Test that the UseRestrictionConverter makes a call to the ontology service and gets back a valid translation
     */
@Test
public void testTranslateDataUsePurpose() {
    mockDataUseTranslateSuccess();
    Client client = ClientBuilder.newClient();
    UseRestrictionConverter converter = new UseRestrictionConverter(client, config());
    DataUse dataUse = new DataUseBuilder().setHmbResearch(true).build();
    String translation = converter.translateDataUse(dataUse, DataUseTranslationType.PURPOSE);
    assertNotNull(translation);
}
Also used : DataUse(org.broadinstitute.consent.http.models.DataUse) DataUseBuilder(org.broadinstitute.consent.http.models.DataUseBuilder) Client(javax.ws.rs.client.Client) MockServerClient(org.mockserver.client.MockServerClient) Test(org.junit.Test)

Example 2 with DataUseBuilder

use of org.broadinstitute.consent.http.models.DataUseBuilder 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 3 with DataUseBuilder

use of org.broadinstitute.consent.http.models.DataUseBuilder in project consent by DataBiosphere.

the class ConsentResourceTest method testCreateConsent.

@Test
public void testCreateConsent() throws Exception {
    User dacUser = new User();
    dacUser.setEmail("test@email.com");
    AuthUser user = new AuthUser(dacUser.getEmail());
    Consent consent = new Consent();
    consent.setConsentId(UUID.randomUUID().toString());
    consent.setDataUse(new DataUseBuilder().setGeneralUse(true).build());
    when(userService.findUserByEmail(any())).thenReturn(dacUser);
    doNothing().when(useRestrictionValidator).validateUseRestriction(any());
    when(consentService.create(any())).thenReturn(consent);
    doNothing().when(auditService).saveConsentAudit(any(), any(), any(), any());
    doNothing().when(matchService).reprocessMatchesForConsent(any());
    initResource();
    Response response = resource.createConsent(info, consent, user);
    assertEquals(201, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) User(org.broadinstitute.consent.http.models.User) AuthUser(org.broadinstitute.consent.http.models.AuthUser) Consent(org.broadinstitute.consent.http.models.Consent) DataUseBuilder(org.broadinstitute.consent.http.models.DataUseBuilder) AuthUser(org.broadinstitute.consent.http.models.AuthUser) Test(org.junit.Test)

Example 4 with DataUseBuilder

use of org.broadinstitute.consent.http.models.DataUseBuilder in project consent by DataBiosphere.

the class ConsentResourceTest method testUpdateConsent.

@Test
public void testUpdateConsent() throws Exception {
    User dacUser = new User();
    dacUser.setEmail("test@email.com");
    AuthUser user = new AuthUser(dacUser.getEmail());
    Consent consent = new Consent();
    // Unarchived consents cannot be updated.
    consent.setLastElectionArchived(true);
    consent.setConsentId(UUID.randomUUID().toString());
    consent.setDataUse(new DataUseBuilder().setGeneralUse(true).build());
    when(userService.findUserByEmail(any())).thenReturn(dacUser);
    doNothing().when(useRestrictionValidator).validateUseRestriction(any());
    when(consentService.retrieve(any())).thenReturn(consent);
    when(consentService.update(any(), any())).thenReturn(consent);
    doNothing().when(auditService).saveConsentAudit(any(), any(), any(), any());
    doNothing().when(matchService).reprocessMatchesForConsent(any());
    initResource();
    Response response = resource.update(consent.getConsentId(), consent, user);
    assertEquals(200, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) User(org.broadinstitute.consent.http.models.User) AuthUser(org.broadinstitute.consent.http.models.AuthUser) Consent(org.broadinstitute.consent.http.models.Consent) DataUseBuilder(org.broadinstitute.consent.http.models.DataUseBuilder) AuthUser(org.broadinstitute.consent.http.models.AuthUser) Test(org.junit.Test)

Example 5 with DataUseBuilder

use of org.broadinstitute.consent.http.models.DataUseBuilder in project consent by DataBiosphere.

the class ConsentResourceTest method testInvalidDULCreate.

@Test
public void testInvalidDULCreate() throws Exception {
    User dacUser = new User();
    dacUser.setEmail("test@email.com");
    AuthUser user = new AuthUser(dacUser.getEmail());
    Consent consent = new Consent();
    consent.setDataUse(new DataUseBuilder().setGeneralUse(true).build());
    consent.setConsentId(UUID.randomUUID().toString());
    consent.setDataUseLetter(UUID.randomUUID().toString());
    when(consentService.retrieve(any())).thenReturn(consent);
    when(userService.findUserByEmail(any())).thenReturn(dacUser);
    doNothing().when(useRestrictionValidator).validateUseRestriction(any());
    initResource();
    Response response = resource.createConsent(info, consent, user);
    assertEquals(400, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) User(org.broadinstitute.consent.http.models.User) AuthUser(org.broadinstitute.consent.http.models.AuthUser) Consent(org.broadinstitute.consent.http.models.Consent) DataUseBuilder(org.broadinstitute.consent.http.models.DataUseBuilder) AuthUser(org.broadinstitute.consent.http.models.AuthUser) Test(org.junit.Test)

Aggregations

DataUseBuilder (org.broadinstitute.consent.http.models.DataUseBuilder)9 Test (org.junit.Test)7 Consent (org.broadinstitute.consent.http.models.Consent)6 DataUse (org.broadinstitute.consent.http.models.DataUse)5 Client (javax.ws.rs.client.Client)3 Response (javax.ws.rs.core.Response)3 AuthUser (org.broadinstitute.consent.http.models.AuthUser)3 User (org.broadinstitute.consent.http.models.User)3 MockServerClient (org.mockserver.client.MockServerClient)3 Everything (org.broadinstitute.consent.http.models.grammar.Everything)2 Timestamp (java.sql.Timestamp)1 Date (java.util.Date)1 DatasetDTO (org.broadinstitute.consent.http.models.dto.DatasetDTO)1 UseRestriction (org.broadinstitute.consent.http.models.grammar.UseRestriction)1