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