/** Test personal item persistence */ @Test public void rootPersonalItemDAOTest() { TransactionStatus ts = tm.getTransaction(td); UserEmail userEmail = new UserEmail("user@email"); // create a user who has their own folder IrUser user = new IrUser("user", "password"); user.setPasswordEncoding("none"); user.addUserEmail(userEmail, true); // create the user userDAO.makePersistent(user); tm.commit(ts); ts = tm.getTransaction(td); GenericItem genericItem = new GenericItem("aItem"); VersionedItem versionedItem = new VersionedItem(user, genericItem); PersonalItem personalItem = new PersonalItem(user, versionedItem); personalItemDAO.makePersistent(personalItem); tm.commit(ts); ts = tm.getTransaction(td); PersonalItem other = personalItemDAO.getById(personalItem.getId(), false); VersionedItem otherVersionedItem = other.getVersionedItem(); assert otherVersionedItem != null : "Versioned Item should be found"; assert otherVersionedItem.getOwner() != null : "Owner should not be null"; assert other.equals(personalItem) : "The personal item " + personalItem + " should be found"; personalItemDAO.makeTransient(other); versionedItemDAO.makeTransient(otherVersionedItem); itemDAO.makeTransient(itemDAO.getById(genericItem.getId(), false)); userDAO.makeTransient(userDAO.getById(user.getId(), false)); tm.commit(ts); }
/** 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"; }