Search in sources :

Example 6 with Study

use of org.obiba.mica.study.domain.Study in project mica2 by obiba.

the class IndividualStudyServiceTest method test_loosing_git_base_and_clone_repos.

@Test
public void test_loosing_git_base_and_clone_repos() throws IOException {
    Study study = new Study();
    Stream.of("a", "b", "c").forEach(name -> {
        study.setName(en(name + " en").forFr(name + " fr"));
        individualStudyService.save(study);
        individualStudyService.publish(study.getId(), true);
    });
    FileUtil.delete(Config.BASE_REPO);
    FileUtil.delete(Config.BASE_CLONE);
    Study draft = individualStudyService.findDraft(study.getId());
    draft.setName(en("d en").forFr("d fr"));
    individualStudyService.save(draft);
    individualStudyService.publish(draft.getId(), true);
    StudyState studyState = individualStudyService.findStateById(draft.getId());
    assertThat(studyState.isPublished()).isTrue();
    assertThat(studyState.getPublishedTag()).isEqualTo("1");
}
Also used : Study(org.obiba.mica.study.domain.Study) StudyState(org.obiba.mica.study.domain.StudyState) Test(org.junit.Test)

Example 7 with Study

use of org.obiba.mica.study.domain.Study in project mica2 by obiba.

the class IndividualStudyServiceTest method test_delete_study_conflict.

@Test
public void test_delete_study_conflict() {
    Study study = new Study();
    study.setName(en("name en").forFr("name fr"));
    individualStudyService.save(study);
    Network network = new Network();
    network.setId("test");
    network.setStudyIds(new ArrayList() {

        {
            add(study.getId());
        }
    });
    networkRepository.save(network);
    assertThat(studyStateRepository.findAll()).hasSize(1);
    exception.expect(ConstraintException.class);
    individualStudyService.delete(study.getId());
}
Also used : Study(org.obiba.mica.study.domain.Study) Network(org.obiba.mica.network.domain.Network) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 8 with Study

use of org.obiba.mica.study.domain.Study in project mica2 by obiba.

the class IndividualStudyServiceTest method test_find_all_draft_studies.

@Test
public void test_find_all_draft_studies() {
    Stream.of("cancer", "gout", "diabetes").forEach(name -> {
        Study draft = new Study();
        draft.setName(en(name + " en").forFr(name + " fr"));
        individualStudyService.save(draft);
    });
    List<Study> drafts = individualStudyService.findAllDraftStudies();
    assertThat(drafts.size()).isEqualTo(3);
    assertThat(drafts.get(2).getName().get("en")).isEqualTo("diabetes en");
}
Also used : Study(org.obiba.mica.study.domain.Study) Test(org.junit.Test)

Example 9 with Study

use of org.obiba.mica.study.domain.Study in project mica2 by obiba.

the class IndividualStudyServiceTest method testCreateStudyWithContacts.

@Test
public void testCreateStudyWithContacts() throws Exception {
    Study study = new Study();
    study.setId("test");
    Person person = new Person();
    person.setEmail("test@test.com");
    List<Person> persons = Lists.newArrayList();
    persons.add(person);
    study.getMemberships().get(Membership.CONTACT).addAll(persons.stream().map(e -> new Membership(e, "contact")).collect(Collectors.toList()));
    individualStudyService.save(study);
    Study retrievedStudy = individualStudyService.findDraft(study.getId());
    List<Person> retrievedPersons = retrievedStudy.getMemberships().get(Membership.CONTACT).stream().map(Membership::getPerson).collect(Collectors.toList());
    assertThat(retrievedPersons).contains(person);
}
Also used : Study(org.obiba.mica.study.domain.Study) Membership(org.obiba.mica.core.domain.Membership) Person(org.obiba.mica.core.domain.Person) Test(org.junit.Test)

Example 10 with Study

use of org.obiba.mica.study.domain.Study in project mica2 by obiba.

the class TestDataCollectionEventSort method test_study_population_sort_with_duplicate_event_dates.

@Test
public void test_study_population_sort_with_duplicate_event_dates() {
    Study study = new Study();
    study.setId("01234567889");
    study.addPopulation(createPopulation("Population001", createEvent("A", 2010, 1, 2020, 12), createEvent("B", 2014, 1, 2035, 12), createEvent("C", 2010, 1, 2020, 12)));
    Population population = Iterables.get(study.getPopulations(), 0);
    SortedSet<DataCollectionEvent> events = population.getDataCollectionEvents();
    assertThat(events.size()).isEqualTo(3);
    assertThat(Iterables.get(events, 0).getStart()).isEqualTo(of(2010, 1));
    assertThat(Iterables.get(events, 1).getStart()).isEqualTo(of(2010, 1));
}
Also used : Study(org.obiba.mica.study.domain.Study) DataCollectionEvent(org.obiba.mica.study.domain.DataCollectionEvent) Population(org.obiba.mica.study.domain.Population) Test(org.junit.Test)

Aggregations

Study (org.obiba.mica.study.domain.Study)33 Test (org.junit.Test)16 StudyState (org.obiba.mica.study.domain.StudyState)8 BaseStudy (org.obiba.mica.study.domain.BaseStudy)6 List (java.util.List)5 Population (org.obiba.mica.study.domain.Population)5 Timed (com.codahale.metrics.annotation.Timed)4 HashMap (java.util.HashMap)4 Collectors (java.util.stream.Collectors)4 Inject (javax.inject.Inject)4 NotNull (javax.validation.constraints.NotNull)4 Component (org.springframework.stereotype.Component)4 Strings (com.google.common.base.Strings)3 Maps (com.google.common.collect.Maps)3 Map (java.util.Map)3 Collectors.toList (java.util.stream.Collectors.toList)3 NoSuchEntityException (org.obiba.mica.NoSuchEntityException)3 Membership (org.obiba.mica.core.domain.Membership)3 DataCollectionEvent (org.obiba.mica.study.domain.DataCollectionEvent)3 HarmonizationStudy (org.obiba.mica.study.domain.HarmonizationStudy)3