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");
}
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);
}
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);
}
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();
}
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);
}
Aggregations