/** Test User Access Control Entry DAO */ @Test public void baseUserControlEntryDAOTest() throws Exception { TransactionStatus ts = tm.getTransaction(td); LanguageType lt = new LanguageType(); lt.setName("languageName"); lt.setDescription("languageDescription"); languageTypeDAO.makePersistent(lt); IrClassType languageClassType = new IrClassType(LanguageType.class); irClassTypeDAO.makePersistent(languageClassType); IrAcl irAcl = new IrAcl(lt, languageClassType); irAclDAO.makePersistent(irAcl); // complete the transaction tm.commit(ts); ts = tm.getTransaction(td); UserEmail userEmail = new UserEmail("user@email"); UserManager userManager = new UserManager(); IrUser user = userManager.createUser("passowrd", "userName"); user.setLastName("familyName"); user.setFirstName("forename"); user.addUserEmail(userEmail, true); // save the user userDAO.makePersistent(user); // create the user access control entry IrUserAccessControlEntry uace = irAcl.createUserAccessControlEntry(user); IrClassTypePermission classTypePermission = new IrClassTypePermission(languageClassType); classTypePermission.setName("permissionName"); classTypePermission.setDescription("permissionDescription"); IrClassTypePermission classTypePermission1 = new IrClassTypePermission(languageClassType); classTypePermission1.setName("permissionName1"); classTypePermission1.setDescription("permissionDescription1"); // save the class type permission classTypePermissionDAO.makePersistent(classTypePermission); classTypePermissionDAO.makePersistent(classTypePermission1); uace.addPermission(classTypePermission1); uace.addPermission(classTypePermission); uaceDAO.makePersistent(uace); tm.commit(ts); // start a new transaction ts = tm.getTransaction(td); IrUserAccessControlEntry other = uaceDAO.getById(uace.getId(), false); assert other.equals(uace) : "User access control entries should be equal"; assert uace.getAcl().equals(irAcl) : "Acl's should be equal"; assert irAcl.getUserAccessControlEntry(uace.getId()).equals(uace) : "Access control should bin in the irAcl"; assert uace.getPermissions().size() == 2 : "Should have at least one permission"; assert uace.getIrClassTypePermissions().contains(classTypePermission) : "Should equal the class type permission"; assert uace.getIrUser().equals(user) : "Users should be equal"; assert uaceDAO.getCount() == 1 : "Should have one uace"; // make sure we can get the acl for the role List<IrAcl> acls = irAclDAO.getAllAclsForSid(user); assert acls.size() == 1 : "Should be able to find 1 acl for user " + user + " but found " + acls.size(); // commit the transaction tm.commit(ts); ts = tm.getTransaction(td); // clean up the database irAclDAO.makeTransient(irAclDAO.getById(irAcl.getId(), false)); assert uaceDAO.getById(uace.getId(), false) == null : "Should not be able to find the access control entry"; classTypePermissionDAO.makeTransient( classTypePermissionDAO.getById(classTypePermission.getId(), false)); classTypePermissionDAO.makeTransient( classTypePermissionDAO.getById(classTypePermission1.getId(), false)); irClassTypeDAO.makeTransient(irClassTypeDAO.getById(languageClassType.getId(), false)); // assert irClassTypeDAO.getById(languageClassType.getId(), false) == null : "Should not be able // to find class type " + languageClassType; // start a new transaction userDAO.makeTransient(userDAO.getById(user.getId(), false)); languageTypeDAO.makeTransient(languageTypeDAO.getById(lt.getId(), false)); // commit the transaction tm.commit(ts); }