Search in sources :

Example 1 with Sample

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

the class EntityTest method testSample.

@Test
public void testSample() {
    val sample1 = new Sample();
    sample1.setSampleId("a1");
    sample1.setSampleSubmitterId("b1");
    sample1.setSampleType(SAMPLE_TYPES.get(0));
    sample1.setSpecimenId("c1");
    val sample1_same = Sample.create("a1", "b1", "c1", SAMPLE_TYPES.get(0));
    assertEntitiesEqual(sample1, sample1_same, true);
    val sample2 = Sample.create("a2", "b2", "c2", SAMPLE_TYPES.get(1));
    assertEntitiesNotEqual(sample1, sample2);
    sample1.setInfo("key1", "f5c9381090a53c54358feb2ba5b7a3d7");
    sample1_same.setInfo("key2", "6329334b-dcd5-53c8-98fd-9812ac386d30");
    assertEntitiesNotEqual(sample1, sample1_same);
    // Test getters
    assertThat(sample1.getSampleId()).isEqualTo("a1");
    assertThat(sample1.getSampleSubmitterId()).isEqualTo("b1");
    assertThat(sample1.getSampleType()).isEqualTo(SAMPLE_TYPES.get(0));
    assertThat(sample1.getSpecimenId()).isEqualTo("c1");
    assertInfoKVPair(sample1, "key1", "f5c9381090a53c54358feb2ba5b7a3d7");
}
Also used : lombok.val(lombok.val) Sample(org.icgc.dcc.song.server.model.entity.Sample) Test(org.junit.Test)

Example 2 with Sample

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

the class SampleServiceTest method testCreateCorruptedAndAlreadyExists.

@Test
public void testCreateCorruptedAndAlreadyExists() {
    val specimenId = DEFAULT_SPECIMEN_ID;
    val existingStudyId = DEFAULT_STUDY_ID;
    val sample = new Sample();
    sample.setSampleSubmitterId(randomGenerator.generateRandomUUIDAsString());
    sample.setSampleType(randomGenerator.randomElement(newArrayList(SAMPLE_TYPE)));
    sample.setSpecimenId(specimenId);
    // Create a sample
    val sampleId = sampleService.create(existingStudyId, sample);
    assertThat(sampleService.isSampleExist(sampleId)).isTrue();
    // Try to create the sample again, and assert that the right exception is thrown
    assertSongError(() -> sampleService.create(existingStudyId, sample), SAMPLE_ALREADY_EXISTS);
    // 'Accidentally' set the sampleId to something not generated by the idService, and try to create. Should
    // detected the corrupted id field, indicating user might have accidentally set the id, thinking it would be
    // persisted
    val sample2 = new Sample();
    sample2.setSpecimenId(specimenId);
    sample2.setSampleType(randomGenerator.randomElement(newArrayList(SAMPLE_TYPE)));
    sample2.setSampleSubmitterId(randomGenerator.generateRandomUUIDAsString());
    sample2.setSampleId(randomGenerator.generateRandomUUIDAsString());
    assertThat(sampleService.isSampleExist(sample2.getSampleId())).isFalse();
    assertSongError(() -> sampleService.create(existingStudyId, sample2), SAMPLE_ID_IS_CORRUPTED);
}
Also used : lombok.val(lombok.val) Sample(org.icgc.dcc.song.server.model.entity.Sample) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with Sample

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

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

the class SampleServiceTest method testReadAndDeleteByParentId.

@Test
public void testReadAndDeleteByParentId() {
    val studyId = DEFAULT_STUDY_ID;
    val donorId = DEFAULT_DONOR_ID;
    val specimen = new Specimen();
    specimen.setDonorId(donorId);
    specimen.setSpecimenClass(randomGenerator.randomElement(newArrayList(SPECIMEN_CLASS)));
    specimen.setSpecimenType(randomGenerator.randomElement(newArrayList(SPECIMEN_TYPE)));
    specimen.setSpecimenSubmitterId(randomGenerator.generateRandomUUIDAsString());
    // Create specimen
    val specimenId = specimenService.create(studyId, specimen);
    specimen.setSpecimenId(specimenId);
    // Create samples
    val numSamples = 5;
    val expectedSampleIds = Sets.<String>newHashSet();
    for (int i = 0; i < numSamples; i++) {
        val sample = new Sample();
        sample.setSpecimenId(specimenId);
        sample.setSampleType(randomGenerator.randomElement(newArrayList(SAMPLE_TYPE)));
        sample.setSampleSubmitterId(randomGenerator.generateRandomUUIDAsString());
        val sampleId = sampleService.create(studyId, sample);
        expectedSampleIds.add(sampleId);
    }
    // Read the samples by parent Id (specimenId)
    val actualSamples = sampleService.readByParentId(specimenId);
    assertThat(actualSamples).hasSize(numSamples);
    assertThat(actualSamples.stream().map(Sample::getSampleId).collect(toSet())).containsAll(expectedSampleIds);
    // Assert that reading by a non-existent specimenId returns something empty
    val randomSpecimenId = randomGenerator.generateRandomUUIDAsString();
    assertThat(specimenService.isSpecimenExist(randomSpecimenId)).isFalse();
    val emptySampleList = sampleService.readByParentId(randomSpecimenId);
    assertThat(emptySampleList).isEmpty();
    // Delete by parent id
    val response = sampleService.deleteByParentId(specimenId);
    assertThat(response).isEqualTo("OK");
    val emptySampleList2 = sampleService.readByParentId(specimenId);
    assertThat(emptySampleList2).isEmpty();
}
Also used : lombok.val(lombok.val) Specimen(org.icgc.dcc.song.server.model.entity.Specimen) Sample(org.icgc.dcc.song.server.model.entity.Sample) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with Sample

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

the class SampleServiceTest method testCreateStudyDNE.

@Test
public void testCreateStudyDNE() {
    val randomStudyId = randomGenerator.generateRandomUUIDAsString();
    val sample = new Sample();
    assertSongError(() -> sampleService.create(randomStudyId, sample), STUDY_ID_DOES_NOT_EXIST);
}
Also used : lombok.val(lombok.val) Sample(org.icgc.dcc.song.server.model.entity.Sample) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

lombok.val (lombok.val)7 Sample (org.icgc.dcc.song.server.model.entity.Sample)7 Test (org.junit.Test)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 Specimen (org.icgc.dcc.song.server.model.entity.Specimen)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 Donor (org.icgc.dcc.song.server.model.entity.Donor)1 CompositeEntity (org.icgc.dcc.song.server.model.entity.composites.CompositeEntity)1 DonorWithSpecimens (org.icgc.dcc.song.server.model.entity.composites.DonorWithSpecimens)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