Search in sources :

Example 1 with Donor

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

the class DonorServiceTest method testUpdateDonor.

@Test
public void testUpdateDonor() {
    val studyId = DEFAULT_STUDY_ID;
    val info = JsonUtils.fromSingleQuoted("{'test': 'new json'}");
    val d = new DonorWithSpecimens();
    d.setDonorId("");
    d.setDonorSubmitterId("Triangle-Arrow-S");
    d.setStudyId(studyId);
    d.setDonorGender("male");
    val id = service.create(d);
    assertThat(id).isEqualTo(d.getDonorId());
    val d2 = new Donor();
    d2.setDonorId(id);
    d2.setDonorSubmitterId("X21-Beta-17");
    d2.setStudyId(studyId);
    d2.setDonorGender("female");
    d2.setInfo(info);
    val response = service.update(d2);
    assertThat(response).isEqualTo("OK");
    val d3 = service.read(id);
    assertThat(d3).isEqualToComparingFieldByField(d2);
}
Also used : lombok.val(lombok.val) Donor(org.icgc.dcc.song.server.model.entity.Donor) DonorWithSpecimens(org.icgc.dcc.song.server.model.entity.composites.DonorWithSpecimens) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with Donor

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

the class SerializationTest method testDonorToJson.

@Test
public void testDonorToJson() {
    val donor = new Donor();
    val json = JsonUtils.toJson(donor);
    val expected = "{'donorId':'','donorSubmitterId':'','studyId':'','donorGender':''," + "'info':{}}";
    val expectedJson = JsonUtils.fromSingleQuoted(expected);
    assertThat(json).isEqualTo(expectedJson);
}
Also used : lombok.val(lombok.val) Donor(org.icgc.dcc.song.server.model.entity.Donor) Test(org.junit.Test)

Example 3 with Donor

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

the class StudyWithDonorsServiceTest method testReadWithChildren.

@Test
public void testReadWithChildren() {
    // Create random isolated study
    val studyId = studyGenerator.createRandomStudy();
    // Generate Random SequencingRead analyses
    val analysisGenerator = createAnalysisGenerator(studyId, analysisService, randomGenerator);
    val numAnalysis = 11;
    val analysisMap = Maps.<String, SequencingReadAnalysis>newHashMap();
    for (int i = 0; i < numAnalysis; i++) {
        val sequencingReadAnalysis = analysisGenerator.createDefaultRandomSequencingReadAnalysis();
        analysisMap.put(sequencingReadAnalysis.getAnalysisId(), sequencingReadAnalysis);
    }
    // Extract expected donors and verify
    val expectedDonors = analysisMap.values().stream().flatMap(x -> x.getSample().stream()).map(CompositeEntity::getDonor).collect(toSet());
    assertThat(expectedDonors).hasSize(numAnalysis);
    assertThat(expectedDonors.stream().map(Donor::getDonorSubmitterId).distinct().count()).isEqualTo(numAnalysis);
    assertThat(expectedDonors.stream().filter(x -> x.getStudyId().equals(studyId)).count()).isEqualTo(numAnalysis);
    // Extract expected specimens and verify
    val expectedSpecimens = analysisMap.values().stream().flatMap(x -> x.getSample().stream()).map(CompositeEntity::getSpecimen).collect(toSet());
    assertThat(expectedSpecimens).hasSize(numAnalysis);
    assertThat(expectedSpecimens.stream().map(Specimen::getSpecimenSubmitterId).distinct().count()).isEqualTo(numAnalysis);
    // Extract expected samples and verify
    val expectedSamples = analysisMap.values().stream().flatMap(x -> x.getSample().stream()).collect(toSet());
    val expectedSampleSubmitterIds = expectedSamples.stream().map(Sample::getSampleSubmitterId).collect(toSet());
    assertThat(expectedSamples).hasSize(numAnalysis);
    assertThat(expectedSampleSubmitterIds).hasSize(numAnalysis);
    // Run the target method to test, readWithChildren
    val studyWithDonors = studyWithDonorsService.readWithChildren(studyId);
    // Extract actual donors
    val actualDonors = studyWithDonors.getDonors().stream().map(DonorWithSpecimens::createDonor).collect(toSet());
    // Extract actual specimens
    val actualSpecimens = studyWithDonors.getDonors().stream().map(DonorWithSpecimens::getSpecimens).flatMap(Collection::stream).map(SpecimenWithSamples::getSpecimen).collect(toSet());
    // Extract actual samples
    val actualSamples = studyWithDonors.getDonors().stream().map(DonorWithSpecimens::getSpecimens).flatMap(Collection::stream).map(SpecimenWithSamples::getSamples).flatMap(Collection::stream).collect(toSet());
    val actualSampleSubmitterIds = actualSamples.stream().map(Sample::getSampleSubmitterId).collect(toSet());
    // Verify expected donors and actual donors match
    assertSetsMatch(expectedDonors, actualDonors);
    // Verify expected specimens and actual specimens match
    assertSetsMatch(expectedSpecimens, actualSpecimens);
    // Verify expected sampleSubmitterIds and actual sampleSubmitterIds match
    assertSetsMatch(expectedSampleSubmitterIds, actualSampleSubmitterIds);
}
Also used : lombok.val(lombok.val) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) SequencingReadAnalysis(org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis) ActiveProfiles(org.springframework.test.context.ActiveProfiles) TestFiles.assertSetsMatch(org.icgc.dcc.song.server.utils.TestFiles.assertSetsMatch) StudyGenerator(org.icgc.dcc.song.server.utils.StudyGenerator) TestExecutionListeners(org.springframework.test.context.TestExecutionListeners) AnalysisGenerator.createAnalysisGenerator(org.icgc.dcc.song.server.utils.AnalysisGenerator.createAnalysisGenerator) SpringRunner(org.springframework.test.context.junit4.SpringRunner) DonorWithSpecimens(org.icgc.dcc.song.server.model.entity.composites.DonorWithSpecimens) DependencyInjectionTestExecutionListener(org.springframework.test.context.support.DependencyInjectionTestExecutionListener) Collectors.toSet(java.util.stream.Collectors.toSet) Before(org.junit.Before) RandomGenerator.createRandomGenerator(org.icgc.dcc.song.core.utils.RandomGenerator.createRandomGenerator) Donor(org.icgc.dcc.song.server.model.entity.Donor) Specimen(org.icgc.dcc.song.server.model.entity.Specimen) Collection(java.util.Collection) lombok.val(lombok.val) Test(org.junit.Test) Maps(com.google.common.collect.Maps) CompositeEntity(org.icgc.dcc.song.server.model.entity.composites.CompositeEntity) Slf4j(lombok.extern.slf4j.Slf4j) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SpecimenWithSamples(org.icgc.dcc.song.server.model.entity.composites.SpecimenWithSamples) RandomGenerator(org.icgc.dcc.song.core.utils.RandomGenerator) StudyGenerator.createStudyGenerator(org.icgc.dcc.song.server.utils.StudyGenerator.createStudyGenerator) Sample(org.icgc.dcc.song.server.model.entity.Sample) Specimen(org.icgc.dcc.song.server.model.entity.Specimen) Donor(org.icgc.dcc.song.server.model.entity.Donor) SequencingReadAnalysis(org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis) DonorWithSpecimens(org.icgc.dcc.song.server.model.entity.composites.DonorWithSpecimens) Collection(java.util.Collection) SpecimenWithSamples(org.icgc.dcc.song.server.model.entity.composites.SpecimenWithSamples) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with Donor

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

the class EntityTest method testDonor.

@Test
public void testDonor() {
    val donor1 = new Donor();
    donor1.setDonorGender("male");
    donor1.setDonorSubmitterId("donorSubmitter1");
    donor1.setDonorId("donor1");
    donor1.setStudyId("study1");
    val donor1_same = Donor.create("donor1", "donorSubmitter1", "study1", "male");
    assertEntitiesEqual(donor1, donor1_same, true);
    val donor2 = Donor.create("donor2", "donorSubmitter2", "study2", "female");
    assertEntitiesNotEqual(donor1, donor2);
    donor1.setInfo("key1", "f5c9381090a53c54358feb2ba5b7a3d7");
    donor1_same.setInfo("key2", "6329334b-dcd5-53c8-98fd-9812ac386d30");
    assertEntitiesNotEqual(donor1, donor1_same);
    // Test getters
    assertThat(donor1.getStudyId()).isEqualTo("study1");
    assertThat(donor1.getDonorGender()).isEqualTo("male");
    assertThat(donor1.getDonorSubmitterId()).isEqualTo("donorSubmitter1");
    assertThat(donor1.getDonorId()).isEqualTo("donor1");
    assertInfoKVPair(donor1, "key1", "f5c9381090a53c54358feb2ba5b7a3d7");
}
Also used : lombok.val(lombok.val) Donor(org.icgc.dcc.song.server.model.entity.Donor) Test(org.junit.Test)

Example 5 with Donor

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

the class SerializationTest method testDonorSettings.

@Test
public void testDonorSettings() {
    val donor = new Donor();
    donor.setDonorId(null);
    val json = JsonUtils.toJson(donor);
    System.err.printf("json='%s'\n", json);
    val expected = "{'donorId':null,'donorSubmitterId':'','studyId':'','donorGender':''," + "'info':{}}";
    val expectedJson = JsonUtils.fromSingleQuoted(expected);
    assertThat(json).isEqualTo(expectedJson);
}
Also used : lombok.val(lombok.val) Donor(org.icgc.dcc.song.server.model.entity.Donor) Test(org.junit.Test)

Aggregations

lombok.val (lombok.val)5 Donor (org.icgc.dcc.song.server.model.entity.Donor)5 Test (org.junit.Test)5 DonorWithSpecimens (org.icgc.dcc.song.server.model.entity.composites.DonorWithSpecimens)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 Maps (com.google.common.collect.Maps)1 Collection (java.util.Collection)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 Slf4j (lombok.extern.slf4j.Slf4j)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 RandomGenerator (org.icgc.dcc.song.core.utils.RandomGenerator)1 RandomGenerator.createRandomGenerator (org.icgc.dcc.song.core.utils.RandomGenerator.createRandomGenerator)1 SequencingReadAnalysis (org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis)1 Sample (org.icgc.dcc.song.server.model.entity.Sample)1 Specimen (org.icgc.dcc.song.server.model.entity.Specimen)1 CompositeEntity (org.icgc.dcc.song.server.model.entity.composites.CompositeEntity)1 SpecimenWithSamples (org.icgc.dcc.song.server.model.entity.composites.SpecimenWithSamples)1 AnalysisGenerator.createAnalysisGenerator (org.icgc.dcc.song.server.utils.AnalysisGenerator.createAnalysisGenerator)1 StudyGenerator (org.icgc.dcc.song.server.utils.StudyGenerator)1 StudyGenerator.createStudyGenerator (org.icgc.dcc.song.server.utils.StudyGenerator.createStudyGenerator)1