Esempio n. 1
0
  public void testContentDaoCreateAvailability() throws Exception {
    User user = getUser(userDao, "testuser");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(user);

    AvailabilityItem newItem = new HibAvailabilityItem();
    newItem.setOwner(user);
    newItem.setName("test");
    newItem.setIcalUid("icaluid");

    CalendarBuilder cb = new CalendarBuilder();
    net.fortuna.ical4j.model.Calendar calendar =
        cb.build(helper.getInputStream("vavailability.ics"));

    newItem.setAvailabilityCalendar(calendar);

    newItem = (AvailabilityItem) contentDao.createContent(root, newItem);

    Assert.assertTrue(getHibItem(newItem).getId() > -1);
    Assert.assertTrue(newItem.getUid() != null);

    clearSession();

    ContentItem queryItem = contentDao.findContentByUid(newItem.getUid());

    helper.verifyItem(newItem, queryItem);
  }
Esempio n. 2
0
  public void testContentDaoUpdateContent() throws Exception {
    User user = getUser(userDao, "testuser");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(user);

    FileItem item = generateTestContent();

    ContentItem newItem = contentDao.createContent(root, item);
    Date newItemModifyDate = newItem.getModifiedDate();

    clearSession();

    FileItem queryItem = (FileItem) contentDao.findContentByUid(newItem.getUid());

    helper.verifyItem(newItem, queryItem);
    Assert.assertEquals(0, queryItem.getVersion().intValue());

    queryItem.setName("test2");
    queryItem.setDisplayName("this is a test item2");
    queryItem.removeAttribute("customattribute");
    queryItem.setContentLanguage("es");
    queryItem.setContent(helper.getBytes("testdata2.txt"));

    // Make sure modified date changes
    Thread.sleep(1000);
    queryItem = (FileItem) contentDao.updateContent(queryItem);

    clearSession();

    ContentItem queryItem2 = contentDao.findContentByUid(newItem.getUid());
    Assert.assertTrue(queryItem2.getVersion().intValue() > 0);
    helper.verifyItem(queryItem, queryItem2);

    Assert.assertTrue(newItemModifyDate.before(queryItem2.getModifiedDate()));
  }
Esempio n. 3
0
  public void testContentDaoUpdateCollection() throws Exception {
    User user = getUser(userDao, "testuser2");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(user);

    CollectionItem a = new HibCollectionItem();
    a.setName("a");
    a.setOwner(user);

    a = contentDao.createCollection(root, a);

    clearSession();

    Assert.assertTrue(getHibItem(a).getId() > -1);
    Assert.assertNotNull(a.getUid());

    CollectionItem queryItem = contentDao.findCollectionByUid(a.getUid());
    helper.verifyItem(a, queryItem);

    queryItem.setName("b");
    contentDao.updateCollection(queryItem);

    clearSession();

    queryItem = contentDao.findCollectionByUid(a.getUid());
    Assert.assertEquals("b", queryItem.getName());
  }
Esempio n. 4
0
  public void testContentDaoInvalidContentEmptyName() throws Exception {

    User user = getUser(userDao, "testuser");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(user);
    ContentItem item = generateTestContent();
    item.setName("");

    try {
      contentDao.createContent(root, item);
      Assert.fail("able to create invalid content.");
    } catch (InvalidStateException e) {
      Assert.assertEquals("name", e.getInvalidValues()[0].getPropertyName());
    }
  }
 /**
  * Generates ticket.
  *
  * @param item The item.
  * @param owner The owner.
  * @return The ticket.
  */
 private Ticket generateTicket(Item item, User owner) {
   Ticket ticket = new HibTicket();
   ticket.setOwner(owner);
   ticket.setTimeout(Ticket.TIMEOUT_INFINITE);
   contentDao.createTicket(item, ticket);
   return ticket;
 }
Esempio n. 6
0
 public void testCreateDuplicateRootItem() throws Exception {
   User testuser = getUser(userDao, "testuser");
   try {
     contentDao.createRootItem(testuser);
     Assert.fail("able to create duplicate root item");
   } catch (RuntimeException re) {
   }
 }
Esempio n. 7
0
  public void testHomeCollection() throws Exception {
    User testuser2 = getUser(userDao, "testuser2");
    HomeCollectionItem root = contentDao.getRootItem(testuser2);

    Assert.assertNotNull(root);
    root.setName("alsfjal;skfjasd");
    Assert.assertEquals(root.getName(), "testuser2");
  }
Esempio n. 8
0
  public void testContentDaoCreateNoteDuplicateIcalUid() throws Exception {
    User user = getUser(userDao, "testuser");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(user);

    NoteItem note1 = generateTestNote("note1", "testuser");
    note1.setIcalUid("icaluid");

    contentDao.createContent(root, note1);

    NoteItem note2 = generateTestNote("note2", "testuser");
    note2.setIcalUid("icaluid");

    try {
      contentDao.createContent(root, note2);
      Assert.fail("able to create duplicate icaluid");
    } catch (IcalUidInUseException e) {
    }
  }
Esempio n. 9
0
  public void testContentDaoCreateContent() throws Exception {
    User user = getUser(userDao, "testuser");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(user);

    ContentItem item = generateTestContent();
    item.setName("test");

    ContentItem newItem = contentDao.createContent(root, item);

    Assert.assertTrue(getHibItem(newItem).getId() > -1);
    Assert.assertTrue(newItem.getUid() != null);

    clearSession();

    ContentItem queryItem = contentDao.findContentByUid(newItem.getUid());

    helper.verifyItem(newItem, queryItem);
  }
Esempio n. 10
0
  public void testContentDaoUpdateCollectionTimestamp() throws Exception {
    User user = getUser(userDao, "testuser2");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(user);

    CollectionItem a = new HibCollectionItem();
    a.setName("a");
    a.setOwner(user);

    a = contentDao.createCollection(root, a);
    Integer ver = a.getVersion();
    Date timestamp = a.getModifiedDate();

    clearSession();
    Thread.sleep(1);

    a = contentDao.updateCollectionTimestamp(a);
    Assert.assertTrue(a.getVersion() == ver + 1);
    Assert.assertTrue(timestamp.before(a.getModifiedDate()));
  }
Esempio n. 11
0
  public void testICalendarAttribute() throws Exception {
    User user = getUser(userDao, "testuser");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(user);

    ContentItem item = generateTestContent();

    ICalendarAttribute icalAttr = new HibICalendarAttribute();
    icalAttr.setQName(new HibQName("icalattribute"));
    icalAttr.setValue(helper.getInputStream("vjournal.ics"));
    item.addAttribute(icalAttr);

    ContentItem newItem = contentDao.createContent(root, item);

    clearSession();

    ContentItem queryItem = contentDao.findContentByUid(newItem.getUid());

    Attribute attr = queryItem.getAttribute(new HibQName("icalattribute"));
    Assert.assertNotNull(attr);
    Assert.assertTrue(attr instanceof ICalendarAttribute);

    net.fortuna.ical4j.model.Calendar calendar =
        (net.fortuna.ical4j.model.Calendar) attr.getValue();
    Assert.assertNotNull(calendar);

    net.fortuna.ical4j.model.Calendar expected =
        CalendarUtils.parseCalendar(helper.getInputStream("vjournal.ics"));

    Assert.assertEquals(expected.toString(), calendar.toString());

    calendar.getProperties().add(new ProdId("blah"));

    contentDao.updateContent(queryItem);

    clearSession();

    queryItem = contentDao.findContentByUid(newItem.getUid());

    ICalendarAttribute ica =
        (ICalendarAttribute) queryItem.getAttribute(new HibQName("icalattribute"));
    Assert.assertFalse(expected.toString().equals(ica.getValue().toString()));
  }
Esempio n. 12
0
  public void testDeleteContentByUid() throws Exception {
    User user = getUser(userDao, "testuser");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(user);

    ContentItem item = generateTestContent();

    ContentItem newItem = contentDao.createContent(root, item);

    clearSession();

    ContentItem queryItem = contentDao.findContentByUid(newItem.getUid());
    helper.verifyItem(newItem, queryItem);

    contentDao.removeItemByUid(queryItem.getUid());

    clearSession();

    queryItem = contentDao.findContentByUid(queryItem.getUid());
    Assert.assertNull(queryItem);
  }
Esempio n. 13
0
  public void testContentDaoCreateContentDuplicateUid() throws Exception {
    User user = getUser(userDao, "testuser");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(user);

    ContentItem item1 = generateTestContent();
    item1.setName("test");
    item1.setUid("uid");

    contentDao.createContent(root, item1);

    ContentItem item2 = generateTestContent();
    item2.setName("test2");
    item2.setUid("uid");

    try {
      contentDao.createContent(root, item2);
      clearSession();
      Assert.fail("able to create duplicate uid");
    } catch (UidInUseException e) {
    }
  }
  /**
   * Test subscribe.
   *
   * @throws Exception - if something is wrong this exception is thrown.
   */
  @Test
  public void testSubscribe() throws Exception {
    User user = getUser(userDao, "subuser1");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(user);
    CollectionItem collection = getCollection(root, "subcoll1");
    Ticket ticket = generateTicket(collection, user);

    CollectionSubscription sub1 = new HibCollectionSubscription();
    sub1.setDisplayName("sub1");
    sub1.setCollection(collection);
    sub1.setTicket(ticket);
    user.addSubscription(sub1);
    userDao.updateUser(user);

    clearSession();

    user = getUser(userDao, "subuser1");

    Assert.assertFalse("no subscriptions saved", user.getCollectionSubscriptions().isEmpty());

    CollectionSubscription querySub = user.getSubscription("sub1");
    Assert.assertNotNull("sub1 not found", querySub);
    Assert.assertEquals("sub1 not same subscriber", user.getUid(), querySub.getOwner().getUid());
    Assert.assertEquals(
        "sub1 not same collection", collection.getUid(), querySub.getCollectionUid());
    Assert.assertEquals("sub1 not same ticket", ticket.getKey(), querySub.getTicketKey());

    querySub.setDisplayName("sub2");
    userDao.updateUser(user);

    clearSession();

    user = getUser(userDao, "subuser1");

    querySub = user.getSubscription("sub1");
    Assert.assertNull("sub1 mistakenly found", querySub);

    querySub = user.getSubscription("sub2");
    Assert.assertNotNull("sub2 not found", querySub);

    user.removeSubscription(querySub);
    userDao.updateUser(user);

    clearSession();

    user = getUser(userDao, "subuser1");

    querySub = user.getSubscription("sub1");
    Assert.assertNull("sub1 mistakenly found", querySub);

    querySub = user.getSubscription("sub2");
    Assert.assertNull("sub2 mistakenly found", querySub);
  }
 /**
  * Gets collection.
  *
  * @param parent The parent.
  * @param name The name.
  * @return The collection item.
  * @throws Exception - if something is wrong this exception is thrown.
  */
 private CollectionItem getCollection(CollectionItem parent, String name) throws Exception {
   for (Item child : (Set<Item>) parent.getChildren()) {
     if (child.getName().equals(name)) {
       return (CollectionItem) child;
     }
   }
   CollectionItem collection = new HibCollectionItem();
   collection.setName(name);
   collection.setDisplayName(name);
   collection.setOwner(parent.getOwner());
   return contentDao.createCollection(parent, collection);
 }
Esempio n. 16
0
  public void testContentDaoDeleteCollection() throws Exception {
    User user = getUser(userDao, "testuser2");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(user);

    CollectionItem a = new HibCollectionItem();
    a.setName("a");
    a.setOwner(user);

    a = contentDao.createCollection(root, a);

    clearSession();

    CollectionItem queryItem = contentDao.findCollectionByUid(a.getUid());
    Assert.assertNotNull(queryItem);

    contentDao.removeCollection(queryItem);

    clearSession();

    queryItem = contentDao.findCollectionByUid(a.getUid());
    Assert.assertNull(queryItem);
  }
Esempio n. 17
0
  public void testContentDaoUpdateCollectionWithDuplicateIcalUids() throws Exception {
    User user = getUser(userDao, "testuser");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(user);

    NoteItem note1 = generateTestNote("test1", "testuser");
    NoteItem note2 = generateTestNote("test2", "testuser");

    note1.setUid("1");
    note1.setIcalUid("1");
    note2.setUid("2");
    note2.setIcalUid("1");

    Set<ContentItem> items = new HashSet<ContentItem>();
    items.add(note1);
    items.add(note2);

    try {
      contentDao.updateCollection(root, items);
      Assert.fail("able to create duplicate icaluids!");
    } catch (IcalUidInUseException e) {
    }
  }
Esempio n. 18
0
  public void testContentDaoUpdateCollection2() throws Exception {
    User user = getUser(userDao, "testuser");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(user);

    NoteItem note1 = generateTestNote("test1", "testuser");
    NoteItem note2 = generateTestNote("test2", "testuser");

    note1.setUid("1");
    note2.setUid("2");

    Set<ContentItem> items = new HashSet<ContentItem>();
    items.add(note1);
    items.add(note2);

    contentDao.updateCollection(root, items);

    items.clear();

    note1 = (NoteItem) contentDao.findContentByUid("1");
    note2 = (NoteItem) contentDao.findContentByUid("2");

    items.add(note1);
    items.add(note2);

    Assert.assertNotNull(note1);
    Assert.assertNotNull(note2);

    note1.setDisplayName("changed");
    note2.setIsActive(false);

    contentDao.updateCollection(root, items);

    note1 = (NoteItem) contentDao.findContentByUid("1");
    note2 = (NoteItem) contentDao.findContentByUid("2");

    Assert.assertNotNull(note1);
    Assert.assertEquals("changed", note1.getDisplayName());
    Assert.assertNull(note2);
  }
Esempio n. 19
0
  public void testCalendarAttribute() throws Exception {
    User user = getUser(userDao, "testuser");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(user);

    ContentItem item = generateTestContent();

    CalendarAttribute calAttr =
        new HibCalendarAttribute(new HibQName("calendarattribute"), "2002-10-10T00:00:00+05:00");
    item.addAttribute(calAttr);

    ContentItem newItem = contentDao.createContent(root, item);

    clearSession();

    ContentItem queryItem = contentDao.findContentByUid(newItem.getUid());

    Attribute attr = queryItem.getAttribute(new HibQName("calendarattribute"));
    Assert.assertNotNull(attr);
    Assert.assertTrue(attr instanceof CalendarAttribute);

    Calendar cal = (Calendar) attr.getValue();
    Assert.assertEquals(cal.getTimeZone().getID(), "GMT+05:00");
    Assert.assertTrue(cal.equals(calAttr.getValue()));

    attr.setValue("2003-10-10T00:00:00+02:00");

    contentDao.updateContent(queryItem);

    clearSession();

    queryItem = contentDao.findContentByUid(newItem.getUid());
    Attribute queryAttr = queryItem.getAttribute(new HibQName("calendarattribute"));
    Assert.assertNotNull(queryAttr);
    Assert.assertTrue(queryAttr instanceof CalendarAttribute);

    cal = (Calendar) queryAttr.getValue();
    Assert.assertEquals(cal.getTimeZone().getID(), "GMT+02:00");
    Assert.assertTrue(cal.equals(attr.getValue()));
  }
Esempio n. 20
0
  public void testTombstoneDeleteContent() throws Exception {
    User user = getUser(userDao, "testuser");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(user);

    ContentItem item = generateTestContent();

    ContentItem newItem = contentDao.createContent(root, item);

    clearSession();

    ContentItem queryItem = contentDao.findContentByUid(newItem.getUid());
    helper.verifyItem(newItem, queryItem);

    Assert.assertTrue(queryItem.getVersion().equals(0));

    contentDao.removeContent(queryItem);

    clearSession();

    queryItem = contentDao.findContentByUid(newItem.getUid());
    Assert.assertNull(queryItem);

    root = (CollectionItem) contentDao.getRootItem(user);
    Assert.assertEquals(root.getTombstones().size(), 1);

    Tombstone ts = root.getTombstones().iterator().next();

    Assert.assertTrue(ts instanceof ItemTombstone);
    Assert.assertEquals(((ItemTombstone) ts).getItemUid(), newItem.getUid());

    item = generateTestContent();
    item.setUid(newItem.getUid());

    contentDao.createContent(root, item);

    clearSession();

    queryItem = contentDao.findContentByUid(newItem.getUid());

    Assert.assertNotNull(queryItem);

    root = (CollectionItem) contentDao.getRootItem(user);
    Assert.assertEquals(root.getTombstones().size(), 0);
  }
Esempio n. 21
0
  public void testTimestampAttribute() throws Exception {
    User user = getUser(userDao, "testuser");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(user);

    ContentItem item = generateTestContent();
    Date dateVal = new Date();
    TimestampAttribute tsAttr =
        new HibTimestampAttribute(new HibQName("timestampattribute"), dateVal);
    item.addAttribute(tsAttr);

    ContentItem newItem = contentDao.createContent(root, item);

    clearSession();

    ContentItem queryItem = contentDao.findContentByUid(newItem.getUid());

    Attribute attr = queryItem.getAttribute(new HibQName("timestampattribute"));
    Assert.assertNotNull(attr);
    Assert.assertTrue(attr instanceof TimestampAttribute);

    Date val = (Date) attr.getValue();
    Assert.assertTrue(dateVal.equals(val));

    dateVal.setTime(dateVal.getTime() + 101);
    attr.setValue(dateVal);

    contentDao.updateContent(queryItem);

    clearSession();

    queryItem = contentDao.findContentByUid(newItem.getUid());
    Attribute queryAttr = queryItem.getAttribute(new HibQName("timestampattribute"));
    Assert.assertNotNull(queryAttr);
    Assert.assertTrue(queryAttr instanceof TimestampAttribute);

    val = (Date) queryAttr.getValue();
    Assert.assertTrue(dateVal.equals(val));
  }
Esempio n. 22
0
  public void testContentDaoLoadChildren() throws Exception {
    User user = getUser(userDao, "testuser");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(user);

    ContentItem item = generateTestContent();
    item.setName("test");

    ContentItem newItem = contentDao.createContent(root, item);

    Assert.assertTrue(getHibItem(newItem).getId() > -1);
    Assert.assertTrue(newItem.getUid() != null);

    clearSession();

    Set<ContentItem> children = contentDao.loadChildren(root, null);
    Assert.assertEquals(1, children.size());

    children = contentDao.loadChildren(root, newItem.getModifiedDate());
    Assert.assertEquals(0, children.size());

    children = contentDao.loadChildren(root, new Date(newItem.getModifiedDate().getTime() - 1));
    Assert.assertEquals(1, children.size());
  }
Esempio n. 23
0
  public void testContentDaoDeleteUserContent() throws Exception {
    User user1 = getUser(userDao, "testuser1");
    User user2 = getUser(userDao, "testuser2");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(user1);

    // Create test content, with owner of user2
    ContentItem item = generateTestContent();
    item.setOwner(user2);

    // create content in user1's home collection
    ContentItem newItem = contentDao.createContent(root, item);

    clearSession();

    user1 = getUser(userDao, "testuser1");
    user2 = getUser(userDao, "testuser2");

    // remove user2's content, which should include the item created
    // in user1's home collections
    contentDao.removeUserContent(user2);

    root = (CollectionItem) contentDao.getRootItem(user1);
    Assert.assertEquals(0, root.getChildren().size());
  }
Esempio n. 24
0
  public void testContentDaoTriageStatus() throws Exception {
    User user = getUser(userDao, "testuser");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(user);

    ContentItem item = generateTestContent();
    item.setName("test");
    TriageStatus initialTriageStatus = new HibTriageStatus();
    TriageStatusUtil.initialize(initialTriageStatus);
    item.setTriageStatus(initialTriageStatus);

    ContentItem newItem = contentDao.createContent(root, item);

    Assert.assertTrue(getHibItem(newItem).getId() > -1);
    Assert.assertTrue(newItem.getUid() != null);

    clearSession();

    ContentItem queryItem = contentDao.findContentByUid(newItem.getUid());
    TriageStatus triageStatus = queryItem.getTriageStatus();
    Assert.assertEquals(initialTriageStatus, triageStatus);

    triageStatus.setCode(TriageStatus.CODE_LATER);
    triageStatus.setAutoTriage(false);
    BigDecimal rank = new BigDecimal("-98765.43");
    triageStatus.setRank(rank);

    contentDao.updateContent(queryItem);
    clearSession();

    queryItem = contentDao.findContentByUid(newItem.getUid());
    triageStatus = queryItem.getTriageStatus();
    Assert.assertEquals(triageStatus.getAutoTriage(), Boolean.FALSE);
    Assert.assertEquals(triageStatus.getCode(), new Integer(TriageStatus.CODE_LATER));
    Assert.assertEquals(triageStatus.getRank(), rank);

    queryItem.setTriageStatus(null);
    contentDao.updateContent(queryItem);
    clearSession();
    // should be null triagestatus
    queryItem = contentDao.findContentByUid(newItem.getUid());
    triageStatus = queryItem.getTriageStatus();
    Assert.assertNull(triageStatus);
  }
Esempio n. 25
0
  public void testFindItem() throws Exception {
    User testuser2 = getUser(userDao, "testuser2");

    CollectionItem root = (CollectionItem) contentDao.getRootItem(testuser2);

    CollectionItem a = new HibCollectionItem();
    a.setName("a");
    a.setOwner(getUser(userDao, "testuser2"));

    a = contentDao.createCollection(root, a);

    clearSession();

    Item queryItem = contentDao.findItemByUid(a.getUid());
    Assert.assertNotNull(queryItem);
    Assert.assertTrue(queryItem instanceof CollectionItem);

    queryItem = contentDao.findItemByPath("/testuser2/a");
    Assert.assertNotNull(queryItem);
    Assert.assertTrue(queryItem instanceof CollectionItem);

    ContentItem item = generateTestContent();

    a = contentDao.findCollectionByUid(a.getUid());
    item = contentDao.createContent(a, item);

    clearSession();

    queryItem = contentDao.findItemByPath("/testuser2/a/test");
    Assert.assertNotNull(queryItem);
    Assert.assertTrue(queryItem instanceof ContentItem);

    clearSession();

    queryItem = contentDao.findItemParentByPath("/testuser2/a/test");
    Assert.assertNotNull(queryItem);
    Assert.assertEquals(a.getUid(), queryItem.getUid());
  }
Esempio n. 26
0
  public void testItemDaoCopy() throws Exception {
    User testuser2 = getUser(userDao, "testuser2");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(testuser2);

    CollectionItem a = new HibCollectionItem();
    a.setName("a");
    a.setOwner(getUser(userDao, "testuser2"));

    a = contentDao.createCollection(root, a);

    CollectionItem b = new HibCollectionItem();
    b.setName("b");
    b.setOwner(getUser(userDao, "testuser2"));

    b = contentDao.createCollection(a, b);

    CollectionItem c = new HibCollectionItem();
    c.setName("c");
    c.setOwner(getUser(userDao, "testuser2"));

    c = contentDao.createCollection(b, c);

    ContentItem d = generateTestContent("d", "testuser2");

    d = contentDao.createContent(c, d);

    CollectionItem e = new HibCollectionItem();
    e.setName("e");
    e.setOwner(getUser(userDao, "testuser2"));

    e = contentDao.createCollection(a, e);

    clearSession();

    root = (CollectionItem) contentDao.getRootItem(testuser2);
    e = contentDao.findCollectionByUid(e.getUid());
    b = contentDao.findCollectionByUid(b.getUid());

    // verify can't copy root collection
    try {
      contentDao.copyItem(root, "/testuser2/a/blah", true);
      Assert.fail("able to copy root collection");
    } catch (IllegalArgumentException iae) {
    }

    // verify can't move to root collection
    try {
      contentDao.copyItem(e, "/testuser2", true);
      Assert.fail("able to move to root collection");
    } catch (ItemNotFoundException infe) {
    }

    // verify can't create loop
    try {
      contentDao.copyItem(b, "/testuser2/a/b/c/new", true);
      Assert.fail("able to create loop");
    } catch (ModelValidationException iae) {
    }

    clearSession();

    // verify that copy works
    b = contentDao.findCollectionByPath("/testuser2/a/b");

    contentDao.copyItem(b, "/testuser2/a/e/bcopy", true);

    clearSession();

    CollectionItem queryCollection = contentDao.findCollectionByPath("/testuser2/a/e/bcopy");
    Assert.assertNotNull(queryCollection);

    queryCollection = contentDao.findCollectionByPath("/testuser2/a/e/bcopy/c");
    Assert.assertNotNull(queryCollection);

    d = contentDao.findContentByUid(d.getUid());
    ContentItem dcopy = contentDao.findContentByPath("/testuser2/a/e/bcopy/c/d");
    Assert.assertNotNull(dcopy);
    Assert.assertEquals(d.getName(), dcopy.getName());
    Assert.assertNotSame(d.getUid(), dcopy.getUid());
    helper.verifyBytes(((FileItem) d).getContent(), ((FileItem) dcopy).getContent());

    clearSession();

    b = contentDao.findCollectionByPath("/testuser2/a/b");

    contentDao.copyItem(b, "/testuser2/a/e/bcopyshallow", false);

    clearSession();

    queryCollection = contentDao.findCollectionByPath("/testuser2/a/e/bcopyshallow");
    Assert.assertNotNull(queryCollection);

    queryCollection = contentDao.findCollectionByPath("/testuser2/a/e/bcopyshallow/c");
    Assert.assertNull(queryCollection);

    clearSession();
    d = contentDao.findContentByUid(d.getUid());
    contentDao.copyItem(d, "/testuser2/dcopy", true);

    clearSession();

    dcopy = contentDao.findContentByPath("/testuser2/dcopy");
    Assert.assertNotNull(dcopy);
  }
Esempio n. 27
0
  public void testItemDaoMove() throws Exception {
    User testuser2 = getUser(userDao, "testuser2");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(testuser2);

    CollectionItem a = new HibCollectionItem();
    a.setName("a");
    a.setOwner(getUser(userDao, "testuser2"));

    a = contentDao.createCollection(root, a);

    CollectionItem b = new HibCollectionItem();
    b.setName("b");
    b.setOwner(getUser(userDao, "testuser2"));

    b = contentDao.createCollection(a, b);

    CollectionItem c = new HibCollectionItem();
    c.setName("c");
    c.setOwner(getUser(userDao, "testuser2"));

    c = contentDao.createCollection(b, c);

    ContentItem d = generateTestContent("d", "testuser2");

    d = contentDao.createContent(c, d);

    CollectionItem e = new HibCollectionItem();
    e.setName("e");
    e.setOwner(getUser(userDao, "testuser2"));

    e = contentDao.createCollection(a, e);

    clearSession();

    root = (CollectionItem) contentDao.getRootItem(testuser2);
    e = contentDao.findCollectionByUid(e.getUid());
    b = contentDao.findCollectionByUid(b.getUid());

    // verify can't move root collection
    try {
      contentDao.moveItem("/testuser2", "/testuser2/a/blah");
      Assert.fail("able to move root collection");
    } catch (IllegalArgumentException iae) {
    }

    // verify can't move to root collection
    try {
      contentDao.moveItem("/testuser2/a/e", "/testuser2");
      Assert.fail("able to move to root collection");
    } catch (ItemNotFoundException infe) {
    }

    // verify can't create loop
    try {
      contentDao.moveItem("/testuser2/a/b", "/testuser2/a/b/c/new");
      Assert.fail("able to create loop");
    } catch (ModelValidationException iae) {
    }

    clearSession();

    // verify that move works
    b = contentDao.findCollectionByPath("/testuser2/a/b");

    contentDao.moveItem("/testuser2/a/b", "/testuser2/a/e/b");

    clearSession();

    CollectionItem queryCollection = contentDao.findCollectionByPath("/testuser2/a/e/b");
    Assert.assertNotNull(queryCollection);

    contentDao.moveItem("/testuser2/a/e/b", "/testuser2/a/e/bnew");

    clearSession();
    queryCollection = contentDao.findCollectionByPath("/testuser2/a/e/bnew");
    Assert.assertNotNull(queryCollection);

    Item queryItem = contentDao.findItemByPath("/testuser2/a/e/bnew/c/d");
    Assert.assertNotNull(queryItem);
    Assert.assertTrue(queryItem instanceof ContentItem);
  }
Esempio n. 28
0
  public void testContentDaoAdvanced() throws Exception {
    User testuser2 = getUser(userDao, "testuser2");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(testuser2);

    CollectionItem a = new HibCollectionItem();
    a.setName("a");
    a.setOwner(getUser(userDao, "testuser2"));

    a = contentDao.createCollection(root, a);

    CollectionItem b = new HibCollectionItem();
    b.setName("b");
    b.setOwner(getUser(userDao, "testuser2"));

    b = contentDao.createCollection(a, b);

    ContentItem c = generateTestContent("c", "testuser2");

    c = contentDao.createContent(b, c);

    ContentItem d = generateTestContent("d", "testuser2");

    d = contentDao.createContent(a, d);

    clearSession();

    a = contentDao.findCollectionByUid(a.getUid());
    b = contentDao.findCollectionByUid(b.getUid());
    c = contentDao.findContentByUid(c.getUid());
    d = contentDao.findContentByUid(d.getUid());
    root = contentDao.getRootItem(testuser2);

    Assert.assertNotNull(a);
    Assert.assertNotNull(b);
    Assert.assertNotNull(d);
    Assert.assertNotNull(root);

    // test children
    Collection children = a.getChildren();
    Assert.assertEquals(2, children.size());
    verifyContains(children, b);
    verifyContains(children, d);

    children = root.getChildren();
    Assert.assertEquals(1, children.size());
    verifyContains(children, a);

    // test get by path
    ContentItem queryC = contentDao.findContentByPath("/testuser2/a/b/c");
    Assert.assertNotNull(queryC);
    helper.verifyInputStream(
        helper.getInputStream("testdata1.txt"), ((FileItem) queryC).getContent());
    Assert.assertEquals("c", queryC.getName());

    // test get path/uid abstract
    Item queryItem = contentDao.findItemByPath("/testuser2/a/b/c");
    Assert.assertNotNull(queryItem);
    Assert.assertTrue(queryItem instanceof ContentItem);

    queryItem = contentDao.findItemByUid(a.getUid());
    Assert.assertNotNull(queryItem);
    Assert.assertTrue(queryItem instanceof CollectionItem);

    // test delete
    contentDao.removeContent(c);
    queryC = contentDao.findContentByUid(c.getUid());
    Assert.assertNull(queryC);

    contentDao.removeCollection(a);

    CollectionItem queryA = contentDao.findCollectionByUid(a.getUid());
    Assert.assertNull(queryA);

    ContentItem queryD = contentDao.findContentByUid(d.getUid());
    Assert.assertNull(queryD);
  }
Esempio n. 29
0
  public void testContentAttributes() throws Exception {
    User user = getUser(userDao, "testuser");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(user);

    ContentItem item = generateTestContent();
    item.addIntegerAttribute("intattribute", new Long(22));
    item.addBooleanAttribute("booleanattribute", Boolean.TRUE);

    DecimalAttribute decAttr =
        new HibDecimalAttribute(new HibQName("decimalattribute"), new BigDecimal("1.234567"));
    item.addAttribute(decAttr);

    // TODO: figure out db date type is handled because i'm seeing
    // issues with accuracy
    // item.addAttribute(new DateAttribute("dateattribute", new Date()));

    HashSet<String> values = new HashSet<String>();
    values.add("value1");
    values.add("value2");
    item.addMultiValueStringAttribute("multistringattribute", values);

    HashMap<String, String> dictionary = new HashMap<String, String>();
    dictionary.put("key1", "value1");
    dictionary.put("key2", "value2");
    item.addDictionaryAttribute("dictionaryattribute", dictionary);

    ContentItem newItem = contentDao.createContent(root, item);

    Assert.assertTrue(getHibItem(newItem).getId() > -1);
    Assert.assertTrue(newItem.getUid() != null);

    clearSession();

    ContentItem queryItem = contentDao.findContentByUid(newItem.getUid());

    Attribute attr = queryItem.getAttribute(new HibQName("decimalattribute"));
    Assert.assertNotNull(attr);
    Assert.assertTrue(attr instanceof DecimalAttribute);
    Assert.assertEquals(attr.getValue().toString(), "1.234567");

    Set<String> querySet = (Set<String>) queryItem.getAttributeValue("multistringattribute");
    Assert.assertTrue(querySet.contains("value1"));
    Assert.assertTrue(querySet.contains("value2"));

    Map<String, String> queryDictionary =
        (Map<String, String>) queryItem.getAttributeValue("dictionaryattribute");
    Assert.assertEquals("value1", queryDictionary.get("key1"));
    Assert.assertEquals("value2", queryDictionary.get("key2"));

    Attribute custom = queryItem.getAttribute("customattribute");
    Assert.assertEquals("customattributevalue", custom.getValue());

    helper.verifyItem(newItem, queryItem);

    // set attribute value to null
    custom.setValue(null);

    querySet.add("value3");
    queryDictionary.put("key3", "value3");

    queryItem.removeAttribute("intattribute");

    contentDao.updateContent(queryItem);

    clearSession();

    queryItem = contentDao.findContentByUid(newItem.getUid());
    querySet = (Set) queryItem.getAttributeValue("multistringattribute");
    queryDictionary = (Map) queryItem.getAttributeValue("dictionaryattribute");
    Attribute queryAttribute = queryItem.getAttribute("customattribute");

    Assert.assertTrue(querySet.contains("value3"));
    Assert.assertEquals("value3", queryDictionary.get("key3"));
    Assert.assertNotNull(queryAttribute);
    Assert.assertNull(queryAttribute.getValue());
    Assert.assertNull(queryItem.getAttribute("intattribute"));
  }
Esempio n. 30
0
  public void testXmlAttribute() throws Exception {
    User user = getUser(userDao, "testuser");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(user);

    ContentItem item = generateTestContent();

    org.w3c.dom.Element testElement = createTestElement();
    org.w3c.dom.Element testElement2 = createTestElement();

    testElement2.setAttribute("foo", "bar");

    Assert.assertFalse(testElement.isEqualNode(testElement2));

    XmlAttribute xmlAttr = new HibXmlAttribute(new HibQName("xmlattribute"), testElement);
    item.addAttribute(xmlAttr);

    ContentItem newItem = contentDao.createContent(root, item);

    clearSession();

    ContentItem queryItem = contentDao.findContentByUid(newItem.getUid());

    Attribute attr = queryItem.getAttribute(new HibQName("xmlattribute"));
    Assert.assertNotNull(attr);
    Assert.assertTrue(attr instanceof XmlAttribute);

    org.w3c.dom.Element element = (org.w3c.dom.Element) attr.getValue();

    Assert.assertEquals(DomWriter.write(testElement), DomWriter.write(element));

    Date modifyDate = attr.getModifiedDate();

    // Sleep a couple millis to make sure modifyDate doesn't change
    Thread.sleep(2);

    contentDao.updateContent(queryItem);

    clearSession();

    queryItem = contentDao.findContentByUid(newItem.getUid());

    attr = queryItem.getAttribute(new HibQName("xmlattribute"));

    // Attribute shouldn't have been updated
    Assert.assertEquals(modifyDate, attr.getModifiedDate());

    attr.setValue(testElement2);

    // Sleep a couple millis to make sure modifyDate doesn't change
    Thread.sleep(2);
    modifyDate = attr.getModifiedDate();

    contentDao.updateContent(queryItem);

    clearSession();

    queryItem = contentDao.findContentByUid(newItem.getUid());

    attr = queryItem.getAttribute(new HibQName("xmlattribute"));
    Assert.assertNotNull(attr);
    Assert.assertTrue(attr instanceof XmlAttribute);
    // Attribute should have been updated
    Assert.assertTrue(modifyDate.before(attr.getModifiedDate()));

    element = (org.w3c.dom.Element) attr.getValue();

    Assert.assertEquals(DomWriter.write(testElement2), DomWriter.write(element));
  }