Search in sources :

Example 6 with DonorWithSpecimens

use of org.icgc.dcc.song.server.model.entity.composites.DonorWithSpecimens 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 7 with DonorWithSpecimens

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

the class DonorService method save.

public String save(@NonNull String studyId, @NonNull Donor donor) {
    donor.setStudyId(studyId);
    String donorId = donorRepository.findByBusinessKey(studyId, donor.getDonorSubmitterId());
    val donorWithSpecimens = new DonorWithSpecimens();
    donorWithSpecimens.setDonor(donor);
    donorWithSpecimens.setDonorId(donorId);
    if (isNull(donorId)) {
        donorId = create(donorWithSpecimens);
    } else {
        val updateDonor = donorWithSpecimens.createDonor();
        update(updateDonor);
    }
    return donorId;
}
Also used : lombok.val(lombok.val) DonorWithSpecimens(org.icgc.dcc.song.server.model.entity.composites.DonorWithSpecimens)

Example 8 with DonorWithSpecimens

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

the class DonorServiceTest method testSave.

@Test
public void testSave() {
    val studyId = DEFAULT_STUDY_ID;
    val donorSubmitterId = randomGenerator.generateRandomUUIDAsString();
    val d = new DonorWithSpecimens();
    d.setDonorId("");
    d.setDonorSubmitterId(donorSubmitterId);
    d.setStudyId(studyId);
    d.setDonorGender("male");
    val donorId = service.save(studyId, d);
    val initialDonor = service.read(donorId);
    assertThat(initialDonor.getDonorGender()).isEqualTo("male");
    assertThat(service.isDonorExist(donorId)).isTrue();
    val dUpdate = new DonorWithSpecimens();
    dUpdate.setDonorSubmitterId(donorSubmitterId);
    dUpdate.setStudyId(studyId);
    dUpdate.setDonorGender("female");
    val donorId2 = service.save(studyId, dUpdate);
    assertThat(service.isDonorExist(donorId2)).isTrue();
    assertThat(donorId2).isEqualTo(donorId);
    val updateDonor = service.read(donorId2);
    assertThat(updateDonor.getDonorGender()).isEqualTo("female");
}
Also used : lombok.val(lombok.val) DonorWithSpecimens(org.icgc.dcc.song.server.model.entity.composites.DonorWithSpecimens) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with DonorWithSpecimens

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

the class DonorServiceTest method testCreateAndDeleteDonor.

@Test
public void testCreateAndDeleteDonor() {
    val json = JsonUtils.mapper().createObjectNode();
    val studyId = "XYZ234";
    json.put("donorId", "");
    json.put("donorSubmitterId", "Subject X21-Alpha");
    json.put("studyId", studyId);
    json.put("donorGender", "unspecified");
    json.put("species", "human");
    DonorWithSpecimens d = JsonUtils.mapper().convertValue(json, DonorWithSpecimens.class);
    assertThat(d.getDonorId()).isNull();
    val status = service.create(d);
    val id = d.getDonorId();
    assertThat(id).startsWith("DO");
    assertThat(status).isEqualTo(id);
    DonorWithSpecimens check = service.readWithSpecimens(id);
    assertThat(d).isEqualToComparingFieldByField(check);
    service.delete("XYZ234", id);
    assertThat(service.isDonorExist(id)).isFalse();
    val status2 = service.create(d);
    assertThat(status2).isEqualTo(id);
    service.delete("XYZ234", newArrayList(id));
    assertThat(service.isDonorExist(id)).isFalse();
}
Also used : lombok.val(lombok.val) DonorWithSpecimens(org.icgc.dcc.song.server.model.entity.composites.DonorWithSpecimens) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with DonorWithSpecimens

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

the class DonorServiceTest method testSaveStudyDNE.

@Test
public void testSaveStudyDNE() {
    val studyId = DEFAULT_STUDY_ID;
    val randomStudyId = randomGenerator.generateRandomUUIDAsString();
    assertThat(studyService.isStudyExist(randomStudyId)).isFalse();
    val donorSubmitterId = randomGenerator.generateRandomUUIDAsString();
    val d = new DonorWithSpecimens();
    d.setDonorId("");
    d.setDonorSubmitterId(donorSubmitterId);
    d.setStudyId(studyId);
    d.setDonorGender("male");
    val donorId = service.create(d);
    assertThat(service.isDonorExist(donorId)).isTrue();
    assertSongError(() -> service.save(randomStudyId, d), STUDY_ID_DOES_NOT_EXIST);
    val d2 = new DonorWithSpecimens();
    d2.setDonorId("");
    d2.setDonorSubmitterId(randomGenerator.generateRandomUUIDAsString());
    d2.setStudyId(randomStudyId);
    d2.setDonorGender("female");
    assertSongError(() -> service.save(randomStudyId, d2), STUDY_ID_DOES_NOT_EXIST);
}
Also used : lombok.val(lombok.val) DonorWithSpecimens(org.icgc.dcc.song.server.model.entity.composites.DonorWithSpecimens) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

lombok.val (lombok.val)14 DonorWithSpecimens (org.icgc.dcc.song.server.model.entity.composites.DonorWithSpecimens)14 Test (org.junit.Test)12 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)10 SpecimenWithSamples (org.icgc.dcc.song.server.model.entity.composites.SpecimenWithSamples)3 Collectors.toSet (java.util.stream.Collectors.toSet)2 Donor (org.icgc.dcc.song.server.model.entity.Donor)2 Maps (com.google.common.collect.Maps)1 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)1 Collection (java.util.Collection)1 Set (java.util.Set)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 StudyWithDonors (org.icgc.dcc.song.server.model.entity.composites.StudyWithDonors)1