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

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

    a = contentDao.createCollection(root, a);

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

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

    clearSession();

    ContentItem queryItem = contentDao.findContentByUid(newItem.getUid());
    Assert.assertEquals(queryItem.getParents().size(), 1);

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

    b = contentDao.createCollection(root, b);

    contentDao.addItemToCollection(queryItem, b);

    clearSession();
    queryItem = contentDao.findContentByUid(newItem.getUid());
    Assert.assertEquals(queryItem.getParents().size(), 2);

    b = contentDao.findCollectionByUid(b.getUid());
    contentDao.removeItemFromCollection(queryItem, b);
    clearSession();
    queryItem = contentDao.findContentByUid(newItem.getUid());
    Assert.assertEquals(queryItem.getParents().size(), 1);

    a = contentDao.findCollectionByUid(a.getUid());
    contentDao.removeItemFromCollection(queryItem, a);
    clearSession();
    queryItem = contentDao.findContentByUid(newItem.getUid());
    Assert.assertNull(queryItem);
  }