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);
  }
  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);
  }