/** Test getting the set of root personal items */
  @Test
  public void getRootPersonalItemsDAOTest() throws Exception {

    UserEmail userEmail = new UserEmail("user@email");

    UserManager userManager = new UserManager();
    IrUser user = userManager.createUser("passowrd", "userName");
    user.addUserEmail(userEmail, true);
    user.setAccountExpired(true);
    user.setAccountLocked(true);
    user.setCredentialsExpired(true);

    userDAO.makePersistent(user);

    TransactionStatus ts = tm.getTransaction(td);

    IrUser other = userDAO.getById(user.getId(), false);
    GenericItem genericItem = new GenericItem("aItem");
    VersionedItem versionedItem = new VersionedItem(user, genericItem);
    PersonalItem personalItem = other.createRootPersonalItem(versionedItem);

    // complete the transaction
    tm.commit(ts);

    ts = tm.getTransaction(td);
    other = userDAO.getById(user.getId(), false);
    assert other != null : "Other should not be null";

    Set<PersonalItem> personalItems = other.getRootPersonalItems();

    assert personalItems != null : "Should be able to find the personal items";
    assert personalItems.size() == 1
        : "Root personal items should be 1 but is " + personalItems.size();

    tm.commit(ts);

    ts = tm.getTransaction(td);
    personalItemDAO.makeTransient(personalItemDAO.getById(personalItem.getId(), false));
    versionedItemDAO.makeTransient(versionedItemDAO.getById(versionedItem.getId(), false));
    itemDAO.makeTransient(itemDAO.getById(genericItem.getId(), false));
    userDAO.makeTransient(userDAO.getById(other.getId(), false));
    tm.commit(ts);

    assert userDAO.getById(other.getId(), false) == null : "Should not be able to find other";
  }
  /** Test adding onwer to group spaces */
  @Test
  public void addGroupWorkspaceOwnerDAOTest() throws Exception {

    TransactionStatus ts = tm.getTransaction(td);
    GroupWorkspace groupSpace = new GroupWorkspace("grouName", "groupDescription");

    // create a user who has their own folder
    UserManager userManager = new UserManager();
    IrUser user = userManager.createUser("passowrd", "userName");
    UserEmail userEmail = new UserEmail("user@email");
    user.addUserEmail(userEmail, true);
    user.setAccountExpired(true);
    user.setAccountLocked(true);
    user.setCredentialsExpired(true);

    // create the user and their folder.
    userDAO.makePersistent(user);

    groupSpace.add(user, true);

    groupWorkspaceDAO.makePersistent(groupSpace);
    tm.commit(ts);

    ts = tm.getTransaction(td);
    GroupWorkspace other = groupWorkspaceDAO.getById(groupSpace.getId(), false);
    GroupWorkspaceUser workspaceUser = other.getUser(user);
    assert workspaceUser != null : "Workspace user for " + user + " should not be null";
    assert workspaceUser.isOwner()
        : "Workspace user  " + workspaceUser + " should be owner of project but is not";
    List<GroupWorkspace> workspaces =
        groupWorkspaceDAO.getGroupWorkspacesForUser(user.getId(), 0, 20, OrderType.ASCENDING_ORDER);
    assert workspaces.size() == 1 : "Should find one workspace but found " + workspaces.size();
    assert workspaces.contains(other) : "List should contain " + other + " but does not";
    tm.commit(ts);

    ts = tm.getTransaction(td);
    other = groupWorkspaceDAO.getById(groupSpace.getId(), false);
    groupWorkspaceDAO.makeTransient(other);
    assert groupWorkspaceDAO.getById(other.getId(), false) == null
        : "Should no longer be able to find groupSpace";
    userDAO.makeTransient(userDAO.getById(user.getId(), false));
    tm.commit(ts);
  }