Exemplo n.º 1
0
 private NodeImage getTestImage() {
   if (testImage == null) {
     testImage = new NodeImage();
     testImage.setUsePermission(NodeImage.EVERYWHERE_USE);
     testImage.setLocation("foo.jpg");
     dao.addImage(testImage, katja, false);
   }
   return testImage;
 }
Exemplo n.º 2
0
  public void testDeleteImage() {
    NodeImage img = new NodeImage();
    img.setLocation("shouldbedeleted.jpg");
    img.setContributor(david);
    dao.addImage(img, david, false);

    int id = img.getId();
    dao.deleteImage(img);

    NodeImage shouldBeNullImg = dao.getImageWithId(id);
    assertNull(shouldBeNullImg);
  }
Exemplo n.º 3
0
 public void testGetImagesForContributor() {
   List list = dao.getImagesForContributor(david);
   assertEquals(list.size(), 545);
   Iterator it = list.iterator();
   while (it.hasNext()) {
     NodeImage nextImage = (NodeImage) it.next();
     int id = nextImage.getContributor() != null ? nextImage.getContributor().getId() : -1;
     int copyrightContrId =
         nextImage.getCopyrightOwnerContributor() != null
             ? nextImage.getCopyrightOwnerContributor().getId()
             : -1;
     assertTrue(id == david.getId() || copyrightContrId == david.getId());
   }
 }
Exemplo n.º 4
0
  public void testFieldsMatching() {
    String comments = "These are comments";
    String copyOwner = "Some copy owner";
    String copyUrl = "Some copy url";
    String copyEmail = "Some copy email";
    String copyDate = "Some copy date";
    String scientificName = "A scientific name";
    String altText = "Some alt text";
    String reference = "A reference";
    String creator = "The creator";
    String identifier = "Identifier";
    String acks = "Acknowledge nothing";
    String geoLocation = "Nogales";
    String sex = "Male";
    String stage = "Young";
    String bodyPart = "Heart";
    String size = "A size";
    String view = "Good";
    boolean fossil = true;
    byte use = NodeImage.RESTRICTED_USE;
    boolean checkedOutOnline = false;
    boolean checkedOut = true;
    String period = "Jurassic";
    String collection = "Collection";
    String collectionAcronym = "NSF";
    String type = "Odd";
    String collector = "Collector";
    String location = "NewImage.jpg";
    Date creationDate = new Date();
    Calendar cal = Calendar.getInstance();
    cal.setTime(creationDate);
    cal.add(Calendar.HOUR, 1);
    Date lastEditedDate = cal.getTime();
    cal.add(Calendar.HOUR, 1);
    Date checkoutDate = cal.getTime();
    String userCreationDate = "some creation date";
    boolean publicDomain = true;
    String additionalDateTimeInfo = "AdditionalInfo";
    String alive = "dead";
    String season = "Fall";
    String imageType = "Photo";
    String voucherNumber = "some voucher";
    String voucherNumberCollection = "some collection of voucher numbers";
    String notes = "some notes";
    String behavior = "some weird behavior";
    NodeImage image = new NodeImage();
    boolean isSpecimen = false;
    boolean isHabitat = true;
    boolean isUltrastructure = false;
    boolean isEquipment = true;
    boolean isBodyparts = true;
    boolean isPeopleWorking = true;
    image.setVoucherNumber(voucherNumber);
    image.setVoucherNumberCollection(voucherNumberCollection);
    image.setNotes(notes);
    image.setBehavior(behavior);
    image.setIsPeopleWorking(isPeopleWorking);
    image.setIsSpecimen(isSpecimen);
    image.setIsHabitat(isHabitat);
    image.setIsUltrastructure(isUltrastructure);
    image.setIsEquipment(isEquipment);
    image.setIsBodyParts(isBodyparts);
    image.setUserCreationDate(userCreationDate);
    image.setAdditionalDateTimeInfo(additionalDateTimeInfo);
    image.setAlive(alive);
    image.setSeason(season);
    image.setImageType(imageType);
    image.setCheckoutDate(checkoutDate);
    image.setCheckedOutContributor(katja);
    image.setCheckedOut(checkedOut);
    image.setOnlineCheckedOut(checkedOutOnline);
    image.setComments(comments);
    image.setCopyrightOwner(copyOwner);
    image.setCopyrightUrl(copyUrl);
    image.setCopyrightEmail(copyEmail);
    image.setCopyrightDate(copyDate);
    image.setScientificName(scientificName);
    image.setAltText(altText);
    image.setReference(reference);
    image.setCreator(creator);
    image.setIdentifier(identifier);
    image.setAcknowledgements(acks);
    image.setGeoLocation(geoLocation);
    image.setSex(sex);
    image.setStage(stage);
    image.setBodyPart(bodyPart);
    image.setSize(size);
    image.setView(view);
    image.setIsFossil(fossil);
    image.setUsePermission(use);
    image.setPeriod(period);
    image.setCollection(collection);
    image.setCollectionAcronym(collectionAcronym);
    image.setType(type);
    image.setCollector(collector);
    image.setLocation(location);
    image.setInPublicDomain(publicDomain);
    image.setContributor(david);
    image.setCopyrightOwnerContributor(katja);
    dao.addImage(image, david, false);
    image.setCreationDate(creationDate);
    image.setLastEditedDate(lastEditedDate);
    image.setLastEditedContributor(chris);
    dao.saveImage(image);
    int id = image.getId();

    NodeImage foundImage = dao.getImageWithId(id);
    assertEquals(foundImage.getVoucherNumber(), voucherNumber);
    assertEquals(foundImage.getVoucherNumberCollection(), voucherNumberCollection);
    assertEquals(foundImage.getNotes(), notes);
    assertEquals(foundImage.getBehavior(), behavior);
    assertEquals(foundImage.getIsPeopleWorking(), isPeopleWorking);
    assertEquals(foundImage.getIsSpecimen(), isSpecimen);
    assertEquals(foundImage.getIsHabitat(), isHabitat);
    assertEquals(foundImage.getIsEquipment(), isEquipment);
    assertEquals(foundImage.getIsUltrastructure(), isUltrastructure);
    assertEquals(foundImage.getIsBodyParts(), isBodyparts);
    assertEquals(foundImage.getAdditionalDateTimeInfo(), additionalDateTimeInfo);
    assertEquals(foundImage.getAlive(), alive);
    assertEquals(foundImage.getSeason(), season);
    assertEquals(foundImage.getImageType(), imageType);
    assertEquals(foundImage.getUserCreationDate(), userCreationDate);
    assertEquals(foundImage.getCheckedOut(), checkedOut);
    assertEquals(foundImage.getOnlineCheckedOut(), checkedOutOnline);
    assertEquals(foundImage.getComments(), comments);
    assertEquals(foundImage.getCopyrightOwner(), copyOwner);
    assertEquals(foundImage.getCopyrightUrl(), copyUrl);
    assertEquals(foundImage.getCopyrightEmail(), copyEmail);
    assertEquals(foundImage.getCopyrightDate(), copyDate);
    assertEquals(foundImage.getScientificName(), scientificName);
    assertEquals(foundImage.getAltText(), altText);
    assertEquals(foundImage.getReference(), reference);
    assertEquals(foundImage.getCreator(), creator);
    assertEquals(foundImage.getIdentifier(), identifier);
    assertEquals(foundImage.getAcknowledgements(), acks);
    assertEquals(foundImage.getGeoLocation(), geoLocation);
    assertEquals(foundImage.getSex(), sex);
    assertEquals(foundImage.getStage(), stage);
    assertEquals(foundImage.getBodyPart(), bodyPart);
    assertEquals(foundImage.getSize(), size);
    assertEquals(foundImage.getView(), view);
    assertEquals(foundImage.getIsFossil(), fossil);
    assertEquals(foundImage.getUsePermission(), use);
    assertEquals(foundImage.getPeriod(), period);
    assertEquals(foundImage.getCollection(), collection);
    assertEquals(foundImage.getCollectionAcronym(), collectionAcronym);
    assertEquals(foundImage.getType(), type);
    assertEquals(foundImage.getCollector(), collector);
    assertEquals(foundImage.getLocation(), location);
    assertEquals(foundImage.getInPublicDomain(), publicDomain);
    assertEquals(foundImage.getContributor().getId(), david.getId());
    assertEquals(foundImage.getCopyrightOwnerContributor().getId(), david.getId());
    checkDates(foundImage.getCreationDate(), creationDate);
    checkDates(foundImage.getLastEditedDate(), lastEditedDate);
    checkDates(foundImage.getCheckoutDate(), checkoutDate);
    assertEquals(foundImage.getCheckedOutContributor().getId(), katja.getId());
    assertEquals(foundImage.getLastEditedContributor().getId(), chris.getId());
  }
Exemplo n.º 5
0
 private void testVampStellateResult(List list) {
   assertTrue(list.size() == 1);
   NodeImage img = (NodeImage) list.get(0);
   assertEquals(img.getLocation(), "VampStellate17.jpg");
 }
Exemplo n.º 6
0
 private void testEukaryotesResult(List list) {
   NodeImage img1 = (NodeImage) list.get(0);
   assertTrue(list.size() == 1);
   assertTrue(img1.getId() == 40);
 }
Exemplo n.º 7
0
 public void testAddImage() {
   NodeImage image = getTestImage();
   int id = image.getId();
   NodeImage foundImage = dao.getImageWithId(id);
   assertNotNull(foundImage);
 }
Exemplo n.º 8
0
  public void testQuerying() {
    Hashtable hash = new Hashtable();
    hash.put(ImageDAO.IMAGE_ID, new Integer(1));
    testVampStellateResult(dao.getImagesMatchingCriteria(hash));
    hash.clear();
    hash.put(ImageDAO.FILENAME, "VampStellate17.jpg");
    testVampStellateResult(dao.getImagesMatchingCriteria(hash));
    hash.put(ImageDAO.IMAGE_ID, new Integer(1));
    testVampStellateResult(dao.getImagesMatchingCriteria(hash));
    // -- not sure what I was thinking here.  the way this used to work, it would return the image
    // regardless of the node name.
    // hash.remove(ImageDAO.IMAGE_ID);
    // hash.put(ImageDAO.GROUP, "XXXXXXXX");
    // testVampStellateResult(dao.getImagesMatchingCriteria(hash));
    hash.clear();
    hash.put(ImageDAO.GROUP, "Eukaryotes");
    testEukaryotesResult(dao.getImagesMatchingCriteria(hash));
    hash.put(ImageDAO.GROUP, "Eukarya");
    testEukaryotesResult(dao.getImagesMatchingCriteria(hash));
    hash.put(ImageDAO.GROUP, "eUKarya");
    testEukaryotesResult(dao.getImagesMatchingCriteria(hash));

    hash.clear();
    hash.put(ImageDAO.SCIENTIFIC_NAME, "Crinoidea");
    List list = dao.getImagesMatchingCriteria(hash);
    NodeImage img = (NodeImage) list.get(0);
    assertEquals(img.getId(), 8);
    // This image is set to use 0, so we shouldn't get any results
    hash.put(ImageDAO.IMAGE_USE, new Byte((byte) 0));
    list = dao.getImagesMatchingCriteria(hash);
    assertEquals(list.size(), 0);

    hash.clear();
    hash.put(ImageDAO.CONTRIBUTOR, david);
    list = dao.getImagesMatchingCriteria(hash);
    assertEquals(list.size(), 4);
    hash.put(ImageDAO.SCIENTIFIC_NAME, "Bembidion umbratum");
    list = dao.getImagesMatchingCriteria(hash);
    assertEquals(list.size(), 1);
    // This image is set to use 2, so we should get the same result
    hash.put(ImageDAO.IMAGE_USE, new Byte((byte) 0));
    list = dao.getImagesMatchingCriteria(hash);
    assertEquals(list.size(), 1);
    hash.clear();
    hash.put(ImageDAO.COPYOWNER_CONTRIBUTOR, david);
    list = dao.getImagesMatchingCriteria(hash);
    Iterator it = list.iterator();
    while (it.hasNext()) {
      img = (NodeImage) it.next();
      assertEquals(img.getCopyrightOwnerContributor().getId(), david.getId());
    }

    hash.clear();
    hash.put(ImageDAO.COPYOWNER, "David Maddison");
    list = dao.getImagesMatchingCriteria(hash);
    // This should match 10 imgs.  David is the copy owner contributor on 9, and his name is in the
    // copyright
    // owner field for 1 img.
    assertEquals(list.size(), 10);

    hash.clear();
    hash.put(ImageDAO.ANY_DATA, "arizona");
    list = dao.getImagesMatchingCriteria(hash);
    assertEquals(list.size(), 4);

    hash.clear();
    hash.put(ImageDAO.ANY_DATA, "ari");
    list = dao.getImagesMatchingCriteria(hash);
    assertEquals(list.size(), 8);
  }
Exemplo n.º 9
0
  public void testNodeManipulations() {
    NodeDAO nodeDao = (NodeDAO) context.getBean("nodeDAO");
    NodeImage image = getTestImage();
    Node life = (Node) nodeDao.findNodesExactlyNamed("Life on Earth").get(0);
    Node viruses = (Node) nodeDao.findNodesExactlyNamed("Viruses").get(0);
    Node eukaryotes = (Node) nodeDao.findNodesExactlyNamed("Eukaryotes").get(0);

    image.addToNodesSet(life);
    dao.saveImage(image);
    NodeImage foundImage = dao.getImageWithId(image.getId());
    assertTrue(foundImage.getNodesSet().size() == 1);
    Node firstNode = (Node) new Vector(foundImage.getNodesSet()).get(0);
    assertEquals(firstNode.getId(), life.getId());
    image.addToNodesSet(viruses);
    dao.saveImage(image);
    foundImage = dao.getImageWithId(image.getId());
    assertTrue(foundImage.getNodesSet().size() == 2);
    Vector nodes = new Vector(foundImage.getNodesSet());
    firstNode = (Node) nodes.get(0);
    Node secondNode = (Node) nodes.get(1);
    assertTrue(firstNode.getId() == life.getId() || firstNode.getId() == viruses.getId());
    assertTrue(secondNode.getId() == life.getId() || secondNode.getId() == viruses.getId());

    image.removeFromNodesSet(life);
    image.removeFromNodesSet(viruses);
    image.addToNodesSet(eukaryotes);
    dao.saveImage(image);
    foundImage = dao.getImageWithId(image.getId());
    assertTrue(foundImage.getNodesSet().size() == 1);
    nodes = new Vector(foundImage.getNodesSet());
    firstNode = (Node) nodes.get(0);
    assertTrue(firstNode.getId() == eukaryotes.getId());
    dao.deleteImage(image);
  }