@Test public void testSetQuantityFromType() throws Exception { SpecimenTypeWrapper type = parentSpc.getSpecimenType(); Assert.assertNull(parentSpc.getQuantity()); parentSpc.setSpecimenType(null); parentSpc.setQuantityFromType(); // no specimen type, no change Assert.assertNull(parentSpc.getQuantity()); parentSpc.setSpecimenType(type); parentSpc.setQuantityFromType(); // no aliquotedspecimen with this type in study, no change Assert.assertNull(parentSpc.getQuantity()); StudyWrapper study = parentSpc.getCollectionEvent().getPatient().getStudy(); AliquotedSpecimenWrapper as = AliquotedSpecimenHelper.addAliquotedSpecimen(study, parentSpc.getSpecimenType()); study.reload(); Assert.assertNotNull(as.getVolume()); Assert.assertTrue(!as.getVolume().equals(BigDecimal.ZERO)); parentSpc.setQuantityFromType(); Assert.assertTrue(as.getVolume().equals(parentSpc.getQuantity())); }
@Test public void testGetSetQuantityFromType() throws Exception { BigDecimal quantity = parentSpc.getQuantity(); parentSpc.setQuantityFromType(); // no sample storages defined yet, should be null Assert.assertTrue(quantity == null); ActivityStatus activeStatus = ActivityStatus.ACTIVE; AliquotedSpecimenWrapper ss1 = new AliquotedSpecimenWrapper(appService); ss1.setSpecimenType(SpecimenTypeHelper.addSpecimenType("ss1")); ss1.setVolume(new BigDecimal(1.0)); ss1.setStudy(parentSpc.getCollectionEvent().getPatient().getStudy()); ss1.setActivityStatus(activeStatus); ss1.persist(); AliquotedSpecimenWrapper ss2 = new AliquotedSpecimenWrapper(appService); ss2.setSpecimenType(SpecimenTypeHelper.addSpecimenType("ss2")); ss2.setVolume(new BigDecimal(2.0)); ss2.setStudy(parentSpc.getCollectionEvent().getPatient().getStudy()); ss2.setActivityStatus(activeStatus); ss2.persist(); AliquotedSpecimenWrapper ss3 = new AliquotedSpecimenWrapper(appService); ss3.setSpecimenType(parentSpc.getSpecimenType()); ss3.setVolume(new BigDecimal(3.0)); ss3.setStudy(parentSpc.getCollectionEvent().getPatient().getStudy()); ss3.setActivityStatus(activeStatus); ss3.persist(); parentSpc .getCollectionEvent() .getPatient() .getStudy() .addToAliquotedSpecimenCollection(Arrays.asList(ss1, ss2, ss3)); // should be 3 parentSpc.setQuantityFromType(); Assert.assertTrue(parentSpc.getQuantity().equals(3.0)); }