Search in sources :

Example 1 with Everything

use of org.broadinstitute.consent.http.models.grammar.Everything 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 2 with Everything

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

the class DataAccessRequestServiceTest method testCreateReviewedDARDocument.

@Test
public void testCreateReviewedDARDocument() {
    Election election = generateElection(1);
    election.setFinalVote(true);
    election.setFinalVoteDate(new Date());
    when(electionDAO.findDataAccessClosedElectionsByFinalResult(true)).thenReturn(Collections.singletonList(election));
    when(electionDAO.findDataAccessClosedElectionsByFinalResult(false)).thenReturn(Collections.emptyList());
    DataAccessRequest dar = generateDataAccessRequest();
    dar.setUserId(1);
    when(dataAccessRequestDAO.findByReferenceId(any())).thenReturn(dar);
    when(dataSetDAO.getAssociatedConsentIdByDataSetId(any())).thenReturn("CONS-1");
    Consent consent = new Consent();
    consent.setConsentId("CONS-1");
    consent.setName("Consent 1");
    consent.setUseRestriction(new Everything());
    consent.setTranslatedUseRestriction(new Everything().toString());
    when(consentDAO.findConsentById("CONS-1")).thenReturn(consent);
    initService();
    try {
        File file = service.createReviewedDARDocument();
        assertNotNull(file);
    } catch (Exception e) {
        assert false;
    }
}
Also used : Everything(org.broadinstitute.consent.http.models.grammar.Everything) Consent(org.broadinstitute.consent.http.models.Consent) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) Election(org.broadinstitute.consent.http.models.Election) File(java.io.File) Date(java.util.Date) NotFoundException(javax.ws.rs.NotFoundException) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with Everything

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

the class ConsentServiceTest method getTestConsent.

private Consent getTestConsent() {
    Consent consent = new Consent(false, new Everything(), "data use", "test consent", new Timestamp(new Date().getTime()), new Timestamp(new Date().getTime()), new Timestamp(new Date().getTime()), "test consent group");
    consent.setDataUse(new 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) Timestamp(java.sql.Timestamp) Date(java.util.Date) LocalDate(java.time.LocalDate)

Example 4 with Everything

use of org.broadinstitute.consent.http.models.grammar.Everything 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());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MockitoAnnotations.openMocks(org.mockito.MockitoAnnotations.openMocks) IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) Mock(org.mockito.Mock) DatasetDTO(org.broadinstitute.consent.http.models.dto.DatasetDTO) UserRoles(org.broadinstitute.consent.http.enumeration.UserRoles) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) ArrayList(java.util.ArrayList) DatasetDAO(org.broadinstitute.consent.http.db.DatasetDAO) Gson(com.google.gson.Gson) ElectionType(org.broadinstitute.consent.http.enumeration.ElectionType) AuthUser(org.broadinstitute.consent.http.models.AuthUser) BadRequestException(javax.ws.rs.BadRequestException) Role(org.broadinstitute.consent.http.models.Role) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) UserDAO(org.broadinstitute.consent.http.db.UserDAO) Before(org.junit.Before) DataAccessRequestData(org.broadinstitute.consent.http.models.DataAccessRequestData) DataSet(org.broadinstitute.consent.http.models.DataSet) DacDAO(org.broadinstitute.consent.http.db.DacDAO) DataAccessRequestDAO(org.broadinstitute.consent.http.db.DataAccessRequestDAO) ConsentManage(org.broadinstitute.consent.http.models.ConsentManage) Collection(java.util.Collection) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) Set(java.util.Set) UserRole(org.broadinstitute.consent.http.models.UserRole) Mockito.times(org.mockito.Mockito.times) User(org.broadinstitute.consent.http.models.User) Test(org.junit.Test) Mockito.doNothing(org.mockito.Mockito.doNothing) Mockito.when(org.mockito.Mockito.when) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Dac(org.broadinstitute.consent.http.models.Dac) Mockito.verify(org.mockito.Mockito.verify) ElectionDAO(org.broadinstitute.consent.http.db.ElectionDAO) List(java.util.List) Stream(java.util.stream.Stream) Election(org.broadinstitute.consent.http.models.Election) Everything(org.broadinstitute.consent.http.models.grammar.Everything) Assert(org.junit.Assert) Collections(java.util.Collections) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Consent(org.broadinstitute.consent.http.models.Consent) DataAccessRequestData(org.broadinstitute.consent.http.models.DataAccessRequestData) Role(org.broadinstitute.consent.http.models.Role) UserRole(org.broadinstitute.consent.http.models.UserRole) Everything(org.broadinstitute.consent.http.models.grammar.Everything) AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) Dac(org.broadinstitute.consent.http.models.Dac) Gson(com.google.gson.Gson) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) Election(org.broadinstitute.consent.http.models.Election) Test(org.junit.Test)

Example 5 with Everything

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

the class JsonTest method testEverything.

@Test
public void testEverything() {
    UseRestriction r = new Everything();
    String json = r.toString();
    Assert.assertTrue(json.equals("{\"type\":\"everything\"}"));
}
Also used : Everything(org.broadinstitute.consent.http.models.grammar.Everything) UseRestriction(org.broadinstitute.consent.http.models.grammar.UseRestriction) Test(org.junit.Test)

Aggregations

Everything (org.broadinstitute.consent.http.models.grammar.Everything)8 Consent (org.broadinstitute.consent.http.models.Consent)5 Test (org.junit.Test)5 Date (java.util.Date)3 DataUse (org.broadinstitute.consent.http.models.DataUse)3 Timestamp (java.sql.Timestamp)2 DataAccessRequest (org.broadinstitute.consent.http.models.DataAccessRequest)2 DataUseBuilder (org.broadinstitute.consent.http.models.DataUseBuilder)2 Election (org.broadinstitute.consent.http.models.Election)2 UseRestriction (org.broadinstitute.consent.http.models.grammar.UseRestriction)2 Gson (com.google.gson.Gson)1 File (java.io.File)1 IOException (java.io.IOException)1 LocalDate (java.time.LocalDate)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Set (java.util.Set)1