Search in sources :

Example 1 with Study

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

the class IndividualStudyServiceTest method test_update_study.

@Test
public void test_update_study() throws Exception {
    Study study = new Study();
    study.setName(en("name en to update").forFr("name fr to update"));
    individualStudyService.save(study);
    study.setName(en("new name en").forFr("new name fr"));
    individualStudyService.save(study);
    List<StudyState> studyStates = studyStateRepository.findAll();
    assertThat(studyStates).hasSize(1);
    StudyState studyState = studyStates.get(0);
    // 
    assertThat(studyState.getId()).isNotEmpty().isEqualTo(study.getId());
    verify(eventBus, times(2)).post(any(DraftStudyUpdatedEvent.class));
    Study retrievedStudy = individualStudyService.findDraft(study.getId());
    assertThat(retrievedStudy).areFieldsEqualToEachOther(study);
}
Also used : Study(org.obiba.mica.study.domain.Study) DraftStudyUpdatedEvent(org.obiba.mica.study.event.DraftStudyUpdatedEvent) StudyState(org.obiba.mica.study.domain.StudyState) Test(org.junit.Test)

Example 2 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 3 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 4 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 5 with Study

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

the class IndividualStudyServiceTest method test_loosing_git_clone_repo.

@Test
public void test_loosing_git_clone_repo() 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_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("4");
}
Also used : Study(org.obiba.mica.study.domain.Study) StudyState(org.obiba.mica.study.domain.StudyState) Test(org.junit.Test)

Aggregations

Study (org.obiba.mica.study.domain.Study)46 BaseStudy (org.obiba.mica.study.domain.BaseStudy)17 Test (org.junit.Test)16 Collectors (java.util.stream.Collectors)10 Inject (javax.inject.Inject)10 List (java.util.List)9 HarmonizationStudy (org.obiba.mica.study.domain.HarmonizationStudy)9 Strings (com.google.common.base.Strings)8 Population (org.obiba.mica.study.domain.Population)8 NotNull (javax.validation.constraints.NotNull)7 DataCollectionEvent (org.obiba.mica.study.domain.DataCollectionEvent)7 Timed (com.codahale.metrics.annotation.Timed)6 Lists (com.google.common.collect.Lists)6 Map (java.util.Map)6 Collectors.toList (java.util.stream.Collectors.toList)6 PublishedStudyService (org.obiba.mica.study.service.PublishedStudyService)6 Sets (com.google.common.collect.Sets)5 HashMap (java.util.HashMap)5 NoSuchEntityException (org.obiba.mica.NoSuchEntityException)5 StudyService (org.obiba.mica.study.service.StudyService)5