@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 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 testCheckPosition() throws Exception {
    ContainerWrapper container = childSpc.getParentContainer();

    Assert.assertFalse(container.isPositionFree(childSpc.getPosition()));
    Assert.assertTrue(container.isPositionFree(new RowColPos(2, 3)));
  }
  @Test
  public void testCompareTo() throws BiobankCheckException, Exception {
    parentSpc.setInventoryId("defgh");
    parentSpc.persist();
    SpecimenWrapper sample2 =
        SpecimenHelper.newSpecimen(
            parentSpc,
            childSpc.getSpecimenType(),
            ActivityStatus.ACTIVE,
            childSpc.getProcessingEvent(),
            childSpc.getParentContainer(),
            2,
            3);
    sample2.setInventoryId("awert");
    sample2.persist();
    Assert.assertTrue(parentSpc.compareTo(sample2) > 0);

    sample2.setInventoryId("qwerty");
    sample2.persist();
    Assert.assertTrue(parentSpc.compareTo(sample2) < 0);

    SpecimenBaseWrapper sb = new SpecimenBaseWrapper(appService);
    Assert.assertEquals(0, parentSpc.compareTo(sb));

    // test with a position because compare with position in this case:
    // childSpc is in topD4B1
    // sample2 is in topD4C4
    Assert.assertTrue(childSpc.compareTo(sample2) < 0);
  }
  @Test
  public void testGetPositionString() throws Exception {
    childSpc.setParentFromPositionString("A1", childSpc.getParentContainer());
    Assert.assertTrue(childSpc.getPositionString(false, false).equals("A1"));
    String parentLabel = childSpc.getParentContainer().getLabel();
    Assert.assertTrue(childSpc.getPositionString(true, false).equals(parentLabel + "A1"));
    // getPositionString with no parameters is equivalent to
    // getPositionString(true, true)
    Assert.assertTrue(
        childSpc
            .getPositionString()
            .equals(parentLabel + "A1 (" + topContainer.getContainerType().getNameShort() + ")"));

    childSpc.setParent(null, null);
    Assert.assertNull(childSpc.getPositionString(false, false));
  }
  @Test
  public void testPersistCheckInventoryIdUniqueCaseSensitive()
      throws BiobankCheckException, Exception {
    int i = r.nextInt();
    parentSpc.setInventoryId("toto" + i);
    parentSpc.persist();

    SpecimenWrapper duplicate =
        SpecimenHelper.newSpecimen(
            parentSpc,
            childSpc.getSpecimenType(),
            ActivityStatus.ACTIVE,
            childSpc.getProcessingEvent(),
            childSpc.getParentContainer(),
            2,
            2);
    duplicate.setInventoryId("toto" + i);

    try {
      duplicate.persist();
      Assert.fail("same inventory id !");
    } catch (DuplicatePropertySetException dee) {
      Assert.assertTrue(true);
    }

    duplicate.setInventoryId("TOTO" + r.nextInt());
    duplicate.persist();
  }
  @Test
  public void testPersistCheckInventoryIdUnique() throws BiobankCheckException, Exception {

    SpecimenWrapper duplicate =
        SpecimenHelper.newSpecimen(
            parentSpc,
            childSpc.getSpecimenType(),
            ActivityStatus.ACTIVE,
            childSpc.getProcessingEvent(),
            childSpc.getParentContainer(),
            2,
            2);
    duplicate.setInventoryId(parentSpc.getInventoryId());

    try {
      duplicate.persist();
      Assert.fail("same inventory id !");
    } catch (DuplicatePropertySetException e) {
      Assert.assertTrue(true);
    }
    duplicate.setInventoryId("qqqq" + r.nextInt());
    duplicate.persist();

    duplicate.setInventoryId(parentSpc.getInventoryId());
    try {
      duplicate.persist();
      Assert.fail(
          "still can't save it with  the same inventoryId after a first add with anotehr inventoryId!");
    } catch (DuplicatePropertySetException e) {
      Assert.assertTrue(true);
    }
  }
  @Test
  public void testGetSpecimensInSiteWithPositionLabel() throws Exception {
    ContainerWrapper container = childSpc.getParentContainer();
    ContainerTypeWrapper containerType = container.getContainerType();
    SpecimenTypeWrapper sampleType = containerType.getSpecimenTypeCollection(false).get(0);
    Assert.assertNotNull(sampleType);
    childSpc.setInventoryId(Utils.getRandomString(5));
    childSpc.persist();

    SpecimenHelper.newSpecimen(
        childSpc,
        childSpc.getSpecimenType(),
        ActivityStatus.ACTIVE,
        childSpc.getProcessingEvent(),
        childSpc.getParentContainer(),
        0,
        1);

    SpecimenHelper.newSpecimen(
        childSpc,
        childSpc.getSpecimenType(),
        ActivityStatus.ACTIVE,
        childSpc.getProcessingEvent(),
        childSpc.getParentContainer(),
        1,
        0);

    childSpc =
        SpecimenHelper.newSpecimen(
            childSpc,
            childSpc.getSpecimenType(),
            ActivityStatus.ACTIVE,
            childSpc.getProcessingEvent(),
            childSpc.getParentContainer(),
            0,
            2);
    childSpc.setInventoryId(Utils.getRandomString(5));
    childSpc.persist();

    List<SpecimenWrapper> specimens =
        SpecimenWrapper.getSpecimensInSiteWithPositionLabel(
            appService, site, childSpc.getPositionString(true, false));
    Assert.assertEquals(1, specimens.size());
    Assert.assertEquals(specimens.get(0), childSpc);
  }
  @Test
  public void testGetSpecimensNonActive() throws Exception {
    ContainerWrapper container = childSpc.getParentContainer();
    ContainerTypeWrapper containerType = container.getContainerType();
    SpecimenTypeWrapper sampleType = containerType.getSpecimenTypeCollection(false).get(0);
    Assert.assertNotNull(sampleType);

    ActivityStatus activityStatusNonActive = ActivityStatus.CLOSED;

    List<SpecimenWrapper> activeSpecimens = new ArrayList<SpecimenWrapper>();
    List<SpecimenWrapper> nonActiveSpecimens = new ArrayList<SpecimenWrapper>();

    activeSpecimens.add(childSpc);
    for (int i = 1, n = container.getColCapacity(); i < n; ++i) {
      activeSpecimens.add(
          SpecimenHelper.newSpecimen(
              parentSpc,
              childSpc.getSpecimenType(),
              ActivityStatus.ACTIVE,
              childSpc.getProcessingEvent(),
              childSpc.getParentContainer(),
              0,
              i));

      SpecimenWrapper a =
          SpecimenHelper.newSpecimen(
              parentSpc,
              childSpc.getSpecimenType(),
              ActivityStatus.ACTIVE,
              childSpc.getProcessingEvent(),
              childSpc.getParentContainer(),
              1,
              i);
      a.setActivityStatus(activityStatusNonActive);
      a.persist();
      nonActiveSpecimens.add(a);
    }

    List<SpecimenWrapper> specimens =
        SpecimenWrapper.getSpecimensNonActiveInCenter(appService, site);
    Assert.assertEquals(nonActiveSpecimens.size(), specimens.size());
    Assert.assertTrue(specimens.containsAll(nonActiveSpecimens));
    Assert.assertFalse(specimens.containsAll(activeSpecimens));
  }
Exemple #10
0
  @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());
  }
Exemple #11
0
  @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());
  }
Exemple #12
0
  @Test
  public void testCheckInventoryIdUnique() throws BiobankCheckException, Exception {
    SpecimenWrapper duplicate =
        SpecimenHelper.newSpecimen(
            parentSpc,
            childSpc.getSpecimenType(),
            ActivityStatus.ACTIVE,
            childSpc.getProcessingEvent(),
            childSpc.getParentContainer(),
            2,
            2);

    duplicate.setInventoryId(parentSpc.getInventoryId());
    try {
      duplicate.checkInventoryIdUnique();
      Assert.fail("The check should detect that this is the same");
    } catch (DuplicateEntryException e) {
      Assert.assertTrue(true);
    }
  }
Exemple #13
0
  @Test
  public void testDelete() throws Exception {
    String name = "testDelete" + r.nextInt();
    SpecimenTypeWrapper type1 = childSpc.getSpecimenType();

    try {
      type1.delete();
      Assert.fail("cannot delete a type in use by a specimen");
    } catch (ModelIsUsedException e) {
      Assert.assertTrue(true);
    }

    SpecimenTypeWrapper type2 = SpecimenTypeHelper.addSpecimenType(name + "_st2");
    SpecimenTypeHelper.removeFromCreated(type2);

    ContainerTypeWrapper typeChild = childSpc.getParentContainer().getContainerType();

    typeChild.addToSpecimenTypeCollection(Arrays.asList(type2));
    typeChild.persist();

    childSpc.reload();
    childSpc.setSpecimenType(type2);
    childSpc.persist();

    try {
      type2.delete();
      Assert.fail("cannot delete a type in use by a specimen");
    } catch (ModelIsUsedException e) {
      Assert.assertTrue(true);
    }

    childSpc.setSpecimenType(type1);
    childSpc.persist();

    typeChild.removeFromSpecimenTypeCollectionWithCheck(Arrays.asList(type2));
    typeChild.persist();

    type2.delete();
  }
Exemple #14
0
 @Test
 public void testGetTop() throws Exception {
   Assert.assertFalse(childSpc.getParentContainer().equals(childSpc.getTop()));
   Assert.assertEquals(topContainer, childSpc.getTop());
 }
Exemple #15
0
  @Test
  public void testDebugRandomMethods() throws Exception {
    System.out.println(parentSpc.getProcessingEvent());
    System.out.println(childSpc.getProcessingEvent());

    ContainerWrapper container = childSpc.getParentContainer();
    ContainerTypeWrapper containerType = container.getContainerType();
    SpecimenTypeWrapper spcType = containerType.getSpecimenTypeCollection(false).get(0);
    Assert.assertNotNull(spcType);

    System.out.println(parentSpc.getProcessingEvent());
    System.out.println(childSpc.getProcessingEvent());

    ProcessingEventWrapper pevent =
        ProcessingEventHelper.addProcessingEvent(
            childSpc.getCurrentCenter(), Utils.getRandomDate());

    // add aliquoted specimen
    SpecimenWrapper specimen =
        SpecimenHelper.newSpecimen(
            parentSpc,
            childSpc.getSpecimenType(),
            ActivityStatus.ACTIVE,
            childSpc.getProcessingEvent(),
            childSpc.getParentContainer(),
            2,
            3);
    specimen.setInventoryId(Utils.getRandomString(5));
    specimen.persist();

    pevent.addToSpecimenCollection(Arrays.asList(parentSpc));
    pevent.persist();

    SpecimenWrapper s2 =
        SpecimenHelper.newSpecimen(
            childSpc,
            childSpc.getSpecimenType(),
            ActivityStatus.ACTIVE,
            childSpc.getProcessingEvent(),
            childSpc.getParentContainer(),
            2,
            4);
    s2.setParent(null, null);
    s2.setParentSpecimen(null);
    s2.persist();

    try {
      // should find at least one specimen with a parent that is inside a
      // processing event
      Assert.assertTrue(
          DebugUtil.getRandomLinkedAliquotedSpecimens(appService, site.getId()).size() > 0);
      Assert.assertTrue(DebugUtil.getRandomAssignedSpecimens(appService, site.getId()).size() > 0);
      List<SpecimenWrapper> randomNonAssociatedNonDispatchedSpecimens =
          DebugUtil.getRandomNonAssignedNonDispatchedSpecimens(appService, site.getId(), 10);
      Assert.assertTrue(randomNonAssociatedNonDispatchedSpecimens.size() > 0);
    } catch (Exception e) {
      Assert.fail(e.getCause().getMessage());
    }

    try {
      s2.delete();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }