Search in sources :

Example 1 with StudyWithDonors

use of org.icgc.dcc.song.server.model.entity.composites.StudyWithDonors in project SONG by overture-stack.

the class EntityTest method testStudyWithDonors.

@Test
public void testStudyWithDonors() {
    val study1 = Study.create("d1", "b1", "c1", "a1");
    val study2 = Study.create("d2", "b2", "c2", "a2");
    val s1 = new StudyWithDonors();
    s1.setStudy(study1);
    val s1_same = new StudyWithDonors();
    s1_same.setName(study1.getName());
    s1_same.setOrganization(study1.getOrganization());
    s1_same.setStudyId(study1.getStudyId());
    s1_same.setDescription(study1.getDescription());
    assertEntitiesEqual(s1, s1_same, true);
    val s2 = new StudyWithDonors();
    s2.setStudy(study2);
    assertEntitiesNotEqual(s1, s2);
    // ---------------
    val specimen1 = Specimen.create("mySpecimen1", "mySpecimenSubmitter1", "myDonor1", SPECIMEN_CLASSES.get(2), SPECIMEN_TYPES.get(2));
    val specimen2 = Specimen.create("mySpecimen2", "mySpecimenSubmitter2", "myDonor2", SPECIMEN_CLASSES.get(1), SPECIMEN_TYPES.get(1));
    val sample11 = Sample.create("mySample11", "mySubmitterSample11", "mySpecimen11", SAMPLE_TYPES.get(2));
    val sample12 = Sample.create("mySample12", "mySubmitterSample12", "mySpecimen12", SAMPLE_TYPES.get(2));
    val sampleGroup1 = newArrayList(sample11, sample12);
    val sample21 = Sample.create("mySample21", "mySubmitterSample21", "mySpecimen21", SAMPLE_TYPES.get(3));
    val sample22 = Sample.create("mySample22", "mySubmitterSample22", "mySpecimen22", SAMPLE_TYPES.get(3));
    val sampleGroup2 = newArrayList(sample21, sample22);
    val specimenWithSample1 = new SpecimenWithSamples();
    specimenWithSample1.setSpecimen(specimen1);
    specimenWithSample1.setSamples(sampleGroup1);
    val specimenWithSample2 = new SpecimenWithSamples();
    specimenWithSample2.setSpecimen(specimen2);
    specimenWithSample2.setSamples(sampleGroup2);
    val specimenWSampleGroup1 = newArrayList(specimenWithSample1, specimenWithSample2);
    val specimenWSampleGroup2 = newArrayList(specimenWithSample1);
    val donor1 = Donor.create("myDonor1", "myDonorSubmitter1", DEFAULT_STUDY_ID, "male");
    val donor2 = Donor.create("myDonor2", "myDonorSubmitter2", DEFAULT_STUDY_ID, "female");
    val d1 = new DonorWithSpecimens();
    d1.setDonor(donor1);
    d1.setSpecimens(specimenWSampleGroup1);
    val d2 = new DonorWithSpecimens();
    d2.setDonor(donor2);
    d2.setSpecimens(specimenWSampleGroup2);
    // 00 -- matchingDonorGroup=0    matchingStudy=0
    s1.setStudy(study1);
    s1.setDonors(newArrayList(d1));
    s2.setStudy(study2);
    s2.setDonors(newArrayList(d2));
    assertEntitiesNotEqual(s1, s2);
    // 01 -- matchingDonorGroup=0    matchingStudy=1
    s1.setStudy(study1);
    s1.setDonors(newArrayList(d1));
    s2.setStudy(study1);
    s2.setDonors(newArrayList(d2));
    assertEntitiesNotEqual(s1, s2);
    // 10 -- matchingDonorGroup=1    matchingStudy=0
    s1.setStudy(study1);
    s1.setDonors(newArrayList(d1));
    s2.setStudy(study2);
    s2.setDonors(newArrayList(d1));
    assertEntitiesNotEqual(s1, s2);
    // 11 -- matchingDonorGroup=1    matchingStudy=1
    s1.setStudy(study1);
    s1.setDonors(newArrayList(d1));
    s2.setStudy(study1);
    s2.setDonors(newArrayList(d1));
    assertEntitiesEqual(s1, s2, true);
    s1.setInfo("key1", "f5c9381090a53c54358feb2ba5b7a3d7");
    s2.setInfo("key2", "6329334b-dcd5-53c8-98fd-9812ac386d30");
    assertInfoKVPair(s1, "key1", "f5c9381090a53c54358feb2ba5b7a3d7");
    assertEntitiesNotEqual(s1, s2);
    s1.setInfo("key1", "f5c9381090a53c54358feb2ba5b7a3d7");
    s2.setInfo("key1", "6329334b-dcd5-53c8-98fd-9812ac386d30");
    assertEntitiesNotEqual(s1, s2);
    // Test getters
    assertThat(s1.getDescription()).isEqualTo(study1.getDescription());
    assertThat(s1.getName()).isEqualTo(study1.getName());
    assertThat(s1.getOrganization()).isEqualTo(study1.getOrganization());
    assertThat(s1.getStudyId()).isEqualTo(study1.getStudyId());
    assertThat(s1.getStudy()).isNotSameAs(study1);
    assertThat(s1.getDonors()).containsExactlyInAnyOrder(d1);
    assertInfoKVPair(s1, "key1", "f5c9381090a53c54358feb2ba5b7a3d7");
    // Assert addDonor
    val sLeft = new StudyWithDonors();
    sLeft.setStudy(study1);
    sLeft.setDonors(newArrayList(d1, d2));
    val sRight = new StudyWithDonors();
    sRight.setStudy(study1);
    sRight.addDonor(d1);
    sRight.addDonor(d2);
    assertThat(sLeft).isEqualTo(sRight);
}
Also used : lombok.val(lombok.val) DonorWithSpecimens(org.icgc.dcc.song.server.model.entity.composites.DonorWithSpecimens) SpecimenWithSamples(org.icgc.dcc.song.server.model.entity.composites.SpecimenWithSamples) StudyWithDonors(org.icgc.dcc.song.server.model.entity.composites.StudyWithDonors) Test(org.junit.Test)

Example 2 with StudyWithDonors

use of org.icgc.dcc.song.server.model.entity.composites.StudyWithDonors in project SONG by overture-stack.

the class StudyWithDonorsService method readWithChildren.

@SneakyThrows
public StudyWithDonors readWithChildren(String studyId) {
    val study = new StudyWithDonors();
    val s = studyService.read(studyId);
    study.setStudy(s);
    study.setDonors(donorService.readByParentId(studyId));
    return study;
}
Also used : lombok.val(lombok.val) StudyWithDonors(org.icgc.dcc.song.server.model.entity.composites.StudyWithDonors) SneakyThrows(lombok.SneakyThrows)

Aggregations

lombok.val (lombok.val)2 StudyWithDonors (org.icgc.dcc.song.server.model.entity.composites.StudyWithDonors)2 SneakyThrows (lombok.SneakyThrows)1 DonorWithSpecimens (org.icgc.dcc.song.server.model.entity.composites.DonorWithSpecimens)1 SpecimenWithSamples (org.icgc.dcc.song.server.model.entity.composites.SpecimenWithSamples)1 Test (org.junit.Test)1