Search in sources :

Example 1 with Sample

use of uk.ac.bbsrc.tgac.miso.core.data.Sample in project miso-lims by miso-lims.

the class DefaultSampleServiceTest method testCreateDetailedSampleNoParent.

@Test
public void testCreateDetailedSampleNoParent() throws Exception {
    SampleTissue sample = makeUnsavedChildTissue();
    SampleIdentity fakeParent = new SampleIdentityImpl();
    fakeParent.setExternalName("non-existing");
    sample.setParent(fakeParent);
    mockShellProjectWithRealLookup(sample);
    mockUser();
    // because of mocked dao, we can't actually continue with the same parent sample that should be created, but the partial
    // parent sample that gets created is caught and examined below
    SampleIdentity parent = makeParentIdentityWithLookup();
    Mockito.when(sampleStore.create(Mockito.any(Sample.class))).thenReturn(parent.getId());
    mockValidRelationship(parent.getSampleClass(), sample.getSampleClass());
    Long newId = 31L;
    Mockito.when(sampleStore.create(sample)).thenReturn(newId);
    Mockito.when(sampleStore.getSample(newId)).thenReturn(sample);
    sut.create(sample);
    ArgumentCaptor<Sample> createdCapture = ArgumentCaptor.forClass(Sample.class);
    Mockito.verify(sampleStore, Mockito.times(2)).create(createdCapture.capture());
    Sample partialParent = createdCapture.getAllValues().get(0);
    assertTrue(LimsUtils.isIdentitySample(partialParent));
    Sample partialChild = createdCapture.getAllValues().get(1);
    assertTrue(LimsUtils.isTissueSample(partialChild));
    ArgumentCaptor<Sample> updatedCapture = ArgumentCaptor.forClass(Sample.class);
    Mockito.verify(sampleStore, Mockito.times(3)).update(updatedCapture.capture());
    // note: finalParent is not actually derived from partialParent because of mocked dao (above), but it should be the parent
    // linked to finalChild
    Sample finalParent = updatedCapture.getAllValues().get(0);
    Sample finalChild = updatedCapture.getAllValues().get(1);
    assertNotNull("Child sample should have parent", ((SampleTissue) finalChild).getParent());
    assertEquals("Unexpected parent ID", ((SampleTissue) finalChild).getParent().getId(), finalParent.getId());
}
Also used : SampleTissue(uk.ac.bbsrc.tgac.miso.core.data.SampleTissue) SampleIdentityImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.SampleIdentityImpl) SampleIdentity(uk.ac.bbsrc.tgac.miso.core.data.SampleIdentity) DetailedSample(uk.ac.bbsrc.tgac.miso.core.data.DetailedSample) Sample(uk.ac.bbsrc.tgac.miso.core.data.Sample) Test(org.junit.Test)

Example 2 with Sample

use of uk.ac.bbsrc.tgac.miso.core.data.Sample in project miso-lims by miso-lims.

the class DefaultSampleServiceTest method testValidateRelationshipForSimpleSample.

@Test
public void testValidateRelationshipForSimpleSample() throws Exception {
    // Simple sample has no DetailedSample attributes.
    Sample child = new SampleImpl();
    // Simple sample has no parent.
    Sample parent = null;
    assertTrue("Simple sample with a null parent and null DetailedSample is a valid relationship", sut.isValidRelationship(parent, child));
}
Also used : DetailedSample(uk.ac.bbsrc.tgac.miso.core.data.DetailedSample) Sample(uk.ac.bbsrc.tgac.miso.core.data.Sample) SampleImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.SampleImpl) Test(org.junit.Test)

Example 3 with Sample

use of uk.ac.bbsrc.tgac.miso.core.data.Sample in project miso-lims by miso-lims.

the class DefaultSampleServiceTest method testPlainSampleIdentificationBarcodeGeneration.

@Test
public void testPlainSampleIdentificationBarcodeGeneration() throws Exception {
    Sample sample = new SampleImpl();
    sample.setAlias("alias");
    mockShellProjectWithRealLookup(sample);
    assertNull("identificationBarcode should be null before save for test", sample.getIdentificationBarcode());
    sut.setAutoGenerateIdBarcodes(true);
    Mockito.when(sampleStore.getSample(Mockito.anyLong())).thenReturn(sample);
    sut.create(sample);
    ArgumentCaptor<Sample> updatedCapture = ArgumentCaptor.forClass(Sample.class);
    Mockito.verify(sampleStore).update(updatedCapture.capture());
    Sample updated = updatedCapture.getValue();
    assertNotNull("identificationBarcode should be generated", updated.getIdentificationBarcode());
}
Also used : DetailedSample(uk.ac.bbsrc.tgac.miso.core.data.DetailedSample) Sample(uk.ac.bbsrc.tgac.miso.core.data.Sample) SampleImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.SampleImpl) Test(org.junit.Test)

Example 4 with Sample

use of uk.ac.bbsrc.tgac.miso.core.data.Sample in project miso-lims by miso-lims.

the class DefaultSampleServiceTest method makePlainSample.

private Sample makePlainSample() {
    Sample sample = new SampleImpl();
    sample.setId(77L);
    sample.setAlias("alias");
    sample.setName("name");
    return sample;
}
Also used : DetailedSample(uk.ac.bbsrc.tgac.miso.core.data.DetailedSample) Sample(uk.ac.bbsrc.tgac.miso.core.data.Sample) SampleImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.SampleImpl)

Example 5 with Sample

use of uk.ac.bbsrc.tgac.miso.core.data.Sample in project miso-lims by miso-lims.

the class DefaultSampleServiceTest method testCreatePlainSample.

@Test
public void testCreatePlainSample() throws Exception {
    Sample sample = new SampleImpl();
    String expectedAlias = "not_generated";
    sample.setAlias(expectedAlias);
    Project expectedProject = mockShellProjectWithRealLookup(sample);
    User expectedLastModifier = mockUser();
    String expectedName = "generated_name";
    Mockito.when(namingScheme.generateNameFor((Sample) Mockito.any())).thenReturn(expectedName);
    Mockito.when(namingScheme.generateSampleAlias((Sample) Mockito.any())).thenReturn("bad");
    Mockito.when(sampleStore.getSample(Mockito.anyLong())).thenReturn(sample);
    sut.create(sample);
    ArgumentCaptor<Sample> createdCapture = ArgumentCaptor.forClass(Sample.class);
    Mockito.verify(sampleStore).create(createdCapture.capture());
    Sample created = createdCapture.getValue();
    assertEquals("shell project should be replaced by real project", expectedProject.getAlias(), created.getProject().getAlias());
    assertNotNull("modification details should be added", created.getLastModifier());
    assertEquals("modification details should be added", expectedLastModifier.getId(), created.getLastModifier().getId());
    assertTrue("expected a plain sample", LimsUtils.isPlainSample(created));
    // name generators get called after initial save
    ArgumentCaptor<Sample> updatedCapture = ArgumentCaptor.forClass(Sample.class);
    Mockito.verify(sampleStore).update(updatedCapture.capture());
    Sample updated = updatedCapture.getValue();
    assertEquals("name should be generated", expectedName, updated.getName());
    assertEquals("alias should not be generated", expectedAlias, updated.getAlias());
    assertNull("identificationBarcode should not be generated", updated.getIdentificationBarcode());
    assertTrue("expected a plain sample", LimsUtils.isPlainSample(updated));
}
Also used : Project(uk.ac.bbsrc.tgac.miso.core.data.Project) User(com.eaglegenomics.simlims.core.User) DetailedSample(uk.ac.bbsrc.tgac.miso.core.data.DetailedSample) Sample(uk.ac.bbsrc.tgac.miso.core.data.Sample) SampleImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.SampleImpl) Test(org.junit.Test)

Aggregations

Sample (uk.ac.bbsrc.tgac.miso.core.data.Sample)94 DetailedSample (uk.ac.bbsrc.tgac.miso.core.data.DetailedSample)59 Test (org.junit.Test)55 SampleImpl (uk.ac.bbsrc.tgac.miso.core.data.impl.SampleImpl)37 AbstractDAOTest (uk.ac.bbsrc.tgac.miso.AbstractDAOTest)24 TransferSample (uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferSample)19 SampleIdentity (uk.ac.bbsrc.tgac.miso.core.data.SampleIdentity)11 User (com.eaglegenomics.simlims.core.User)9 Project (uk.ac.bbsrc.tgac.miso.core.data.Project)9 Date (java.util.Date)8 Library (uk.ac.bbsrc.tgac.miso.core.data.Library)8 SampleTissue (uk.ac.bbsrc.tgac.miso.core.data.SampleTissue)8 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 SampleStock (uk.ac.bbsrc.tgac.miso.core.data.SampleStock)7 WorksetSample (uk.ac.bbsrc.tgac.miso.core.data.impl.workset.WorksetSample)7 Criteria (org.hibernate.Criteria)6 PostMapping (org.springframework.web.bind.annotation.PostMapping)6 Pool (uk.ac.bbsrc.tgac.miso.core.data.Pool)6 ProjectImpl (uk.ac.bbsrc.tgac.miso.core.data.impl.ProjectImpl)6