@Test public void testCheckPosition() throws Exception { ContainerWrapper container = childSpc.getParentContainer(); Assert.assertFalse(container.isPositionFree(childSpc.getPosition())); Assert.assertTrue(container.isPositionFree(new RowColPos(2, 3))); }
@Test public void testGetSetParent() throws Exception { Assert.assertTrue(childSpc.hasParent()); ContainerWrapper oldParent = childSpc.getParentContainer(); ContainerTypeWrapper type = ContainerTypeHelper.addContainerType(site, "newCtType", "ctNew", 1, 4, 5, true); type.addToSpecimenTypeCollection(Arrays.asList(childSpc.getSpecimenType())); type.persist(); ContainerWrapper parent = ContainerHelper.addContainer("newcontainerParent", "ccNew", site, type); childSpc.setParent(parent, childSpc.getPosition()); childSpc.persist(); // check to make sure gone from old parent oldParent.reload(); Assert.assertTrue(oldParent.getSpecimens().size() == 0); // check to make sure added to new parent parent.reload(); Assert.assertTrue(childSpc.getParentContainer() != null); Collection<SpecimenWrapper> sampleWrappers = parent.getSpecimens().values(); boolean found = false; for (SpecimenWrapper sampleWrapper : sampleWrappers) { if (sampleWrapper.getId().equals(childSpc.getId())) found = true; } Assert.assertTrue(found); // test for no parent SpecimenWrapper specimen2 = new SpecimenWrapper(appService); Assert.assertFalse(specimen2.hasParent()); }
@Test public void testPersistPositionAlreadyUsed() throws BiobankCheckException, Exception { parentSpc.persist(); RowColPos pos = childSpc.getPosition(); SpecimenWrapper duplicate = SpecimenHelper.newSpecimen( parentSpc, childSpc.getSpecimenType(), ActivityStatus.ACTIVE, childSpc.getProcessingEvent(), childSpc.getParentContainer(), pos.getRow(), pos.getCol()); try { duplicate.persist(); Assert.fail("should not be allowed to add an specimen in a position that is not empty"); } catch (BiobankSessionException bce) { Assert.assertTrue(true); } duplicate.setParent(duplicate.getParentContainer(), new RowColPos(2, 3)); duplicate.persist(); duplicate.setInventoryId(Utils.getRandomString(5)); duplicate.persist(); }
@Test public void testGetSetPosition() throws Exception { RowColPos position = new RowColPos(1, 3); childSpc.setParent(childSpc.getParentContainer(), position); RowColPos newPosition = childSpc.getPosition(); Assert.assertEquals(position.getRow(), newPosition.getRow()); Assert.assertEquals(position.getCol(), newPosition.getCol()); // ensure position remains after persist childSpc.persist(); childSpc.reload(); newPosition = childSpc.getPosition(); Assert.assertEquals(position.getRow(), newPosition.getRow()); Assert.assertEquals(position.getCol(), newPosition.getCol()); // test setting position to null childSpc.setParent(null, null); childSpc.persist(); childSpc.reload(); Assert.assertEquals(null, childSpc.getPosition()); Assert.assertEquals(null, childSpc.getParentContainer()); }
@Test public void testSetSpecimenPositionFromString() throws Exception { childSpc.setParentFromPositionString("A1", childSpc.getParentContainer()); childSpc.persist(); Assert.assertTrue(childSpc.getPositionString(false, false).equals("A1")); RowColPos pos = childSpc.getPosition(); Assert.assertTrue((pos.getCol() == 0) && (pos.getRow() == 0)); childSpc.setParentFromPositionString("C2", childSpc.getParentContainer()); childSpc.persist(); Assert.assertTrue(childSpc.getPositionString(false, false).equals("C2")); pos = childSpc.getPosition(); Assert.assertTrue((pos.getCol() == 1) && (pos.getRow() == 2)); try { childSpc.setParentFromPositionString("79", childSpc.getParentContainer()); Assert.fail("invalid position"); } catch (Exception bce) { Assert.assertTrue(true); } SpecimenWrapper specimen = new SpecimenWrapper(appService); Assert.assertNull(specimen.getPositionString()); }