use of org.icgc.dcc.song.server.model.entity.composites.DonorWithSpecimens in project SONG by overture-stack.
the class DonorServiceTest method testCreateDonorAlreadyExists.
@Test
public void testCreateDonorAlreadyExists() {
val studyId = DEFAULT_STUDY_ID;
val randomGender = randomGenerator.randomElement(newArrayList(DONOR_GENDER));
val randomDonorSubmitterId = randomGenerator.generateRandomUUIDAsString();
val expectedId = idService.generateDonorId(randomDonorSubmitterId, studyId);
val donorWithSpecimens = new DonorWithSpecimens();
donorWithSpecimens.setStudyId(studyId);
donorWithSpecimens.setDonorSubmitterId(randomDonorSubmitterId);
donorWithSpecimens.setDonorGender(randomGender);
donorWithSpecimens.setInfo("someKey", "someValue");
val donorId = service.create(donorWithSpecimens);
assertThat(donorId).isEqualTo(expectedId);
donorWithSpecimens.setDonorId("DO123");
assertSongError(() -> service.create(donorWithSpecimens), DONOR_ID_IS_CORRUPTED);
donorWithSpecimens.setDonorId(expectedId);
assertSongError(() -> service.create(donorWithSpecimens), DONOR_ALREADY_EXISTS);
donorWithSpecimens.setDonorId("");
assertSongError(() -> service.create(donorWithSpecimens), DONOR_ALREADY_EXISTS);
donorWithSpecimens.setDonorId(null);
assertSongError(() -> service.create(donorWithSpecimens), DONOR_ALREADY_EXISTS);
}
use of org.icgc.dcc.song.server.model.entity.composites.DonorWithSpecimens 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);
}
use of org.icgc.dcc.song.server.model.entity.composites.DonorWithSpecimens in project SONG by overture-stack.
the class SpecimenServiceTest method testReadAndDeleteByParentId.
@Test
public void testReadAndDeleteByParentId() {
// Create a donor, and then several specimens, and for each specimen 2 samples
val studyId = DEFAULT_STUDY_ID;
val donor = Donor.create("", randomGenerator.generateRandomUUIDAsString(), studyId, randomGenerator.randomElement(newArrayList(DONOR_GENDER)));
val donorWithSpecimens = new DonorWithSpecimens();
donorWithSpecimens.setDonor(donor);
val donorId = donorService.create(donorWithSpecimens);
val numSpecimens = 5;
val numSamplesPerSpecimen = 2;
val expectedSpecimenIds = Sets.<String>newHashSet();
val expectedSampleIdMap = Maps.<String, Set<String>>newHashMap();
for (int i = 0; i < numSpecimens; i++) {
// Create specimen
val specimen = Specimen.create("", randomGenerator.generateRandomUUIDAsString(), donorId, randomGenerator.randomElement(newArrayList(SPECIMEN_CLASS)), randomGenerator.randomElement(newArrayList(SPECIMEN_TYPE)));
val specimenId = specimenService.create(studyId, specimen);
expectedSpecimenIds.add(specimenId);
// Create samples
for (int j = 0; j < numSamplesPerSpecimen; j++) {
val sample = Sample.create("", randomGenerator.generateRandomUUIDAsString(), specimenId, randomGenerator.randomElement(newArrayList(SAMPLE_TYPE)));
val sampleId = sampleService.create(studyId, sample);
// Store the expected sampleId
if (!expectedSampleIdMap.containsKey(specimenId)) {
expectedSampleIdMap.put(specimenId, newHashSet());
}
val sampleIds = expectedSampleIdMap.get(specimenId);
sampleIds.add(sampleId);
}
}
// ReadByParentId (newly created donorId)
val specimens = specimenService.readByParentId(donorId);
assertThat(specimens).hasSize(numSpecimens);
for (val specimen : specimens) {
val actualSpecimenId = specimen.getSpecimenId();
val actualSampleIds = specimen.getSamples().stream().map(Sample::getSampleId).collect(toSet());
assertThat(expectedSpecimenIds).contains(actualSpecimenId);
assertThat(actualSampleIds).hasSize(numSamplesPerSpecimen);
val expectedSampleIds = expectedSampleIdMap.get(actualSpecimenId);
assertThat(expectedSampleIds).hasSize(numSamplesPerSpecimen);
assertThat(actualSampleIds).isSubsetOf(expectedSampleIds);
assertThat(expectedSampleIds).isSubsetOf(actualSampleIds);
}
// Assert that reading by a non-existent donorId returns something empty
val randomDonorId = randomGenerator.generateRandomUUIDAsString();
assertThat(donorService.isDonorExist(randomDonorId)).isFalse();
val emptySpecimenList = specimenService.readByParentId(randomDonorId);
assertThat(emptySpecimenList).isEmpty();
// Delete by parent id
val response = specimenService.deleteByParentId(donorId);
assertThat(response).isEqualTo("OK");
val emptySpecimenList2 = specimenService.readByParentId(donorId);
assertThat(emptySpecimenList2).isEmpty();
}
use of org.icgc.dcc.song.server.model.entity.composites.DonorWithSpecimens in project SONG by overture-stack.
the class DonorService method readWithSpecimens.
public DonorWithSpecimens readWithSpecimens(@NonNull String id) {
val donor = new DonorWithSpecimens();
donor.setDonor(read(id));
donor.setSpecimens(specimenService.readByParentId(id));
return donor;
}
Aggregations