/** * Test the persistance methods for extent type Information * * @author Sharmila Rangnathan */ @Test( groups = {"baseTests"}, enabled = true) public class ExtentTypeDAOTest { /** get the application context */ ApplicationContext ctx = ContextHolder.getApplicationContext(); ExtentTypeDAO extentTypeDAO = (ExtentTypeDAO) ctx.getBean("extentTypeDAO"); PlatformTransactionManager tm = (PlatformTransactionManager) ctx.getBean("transactionManager"); TransactionDefinition td = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED); /** Test extent type persistence */ @SuppressWarnings("unchecked") @Test public void baseExtentTypeDAOTest() throws Exception { ExtentType extentType = new ExtentType("extentTypeName", "extentTypeDescription"); // Start the transaction TransactionStatus ts = tm.getTransaction(td); extentTypeDAO.makePersistent(extentType); tm.commit(ts); ts = tm.getTransaction(td); ExtentType other = extentTypeDAO.getById(extentType.getId(), false); assert other.equals(extentType) : "Idententifier types should be equal"; List<ExtentType> itemExtentTypes = extentTypeDAO.getAllOrderByName(0, 1); assert itemExtentTypes.size() == 1 : "One extent type should be found"; assert extentTypeDAO.getAllNameOrder().size() == 1 : "One extent type should be found"; ExtentType itemExtentTypeByName = extentTypeDAO.findByUniqueName(extentType.getName()); assert itemExtentTypeByName.equals(extentType) : "Extent types should be found"; extentTypeDAO.makeTransient(other); assert extentTypeDAO.getById(other.getId(), false) == null : "Should no longer be able to find extent type"; tm.commit(ts); } }
/** * Group space data access object test. * * @author Nathan Sarr */ @Test( groups = {"baseTests"}, enabled = true) public class GroupWorkspaceDAOTest { /** get the application context */ ApplicationContext ctx = ContextHolder.getApplicationContext(); GroupWorkspaceDAO groupWorkspaceDAO = (GroupWorkspaceDAO) ctx.getBean("groupWorkspaceDAO"); PlatformTransactionManager tm = (PlatformTransactionManager) ctx.getBean("transactionManager"); TransactionDefinition td = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED); /** User data access */ IrUserDAO userDAO = (IrUserDAO) ctx.getBean("irUserDAO"); /** Test group space persistence */ @Test public void simpleGroupWorkspaceDAOTest() throws Exception { TransactionStatus ts = tm.getTransaction(td); GroupWorkspace groupSpace = new GroupWorkspace("grouName", "groupDescription"); groupWorkspaceDAO.makePersistent(groupSpace); tm.commit(ts); ts = tm.getTransaction(td); GroupWorkspace other = groupWorkspaceDAO.getById(groupSpace.getId(), false); assert other.equals(groupSpace) : "Group space " + other + " should equal " + groupSpace; 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"; tm.commit(ts); } /** 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); } }
/** * Test the persistance methods for User Access Control Entries * * @author Nathan Sarr */ @Test( groups = {"baseTests"}, enabled = true) public class IrUserAccessControlEntryDAOTest { /* get the application context */ ApplicationContext ctx = ContextHolder.getApplicationContext(); /* transaction manager for handling transactions */ PlatformTransactionManager tm = (PlatformTransactionManager) ctx.getBean("transactionManager"); /* Transaction definition */ TransactionDefinition td = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED); /* Class type data access */ IrClassTypeDAO irClassTypeDAO = (IrClassTypeDAO) ctx.getBean("irClassTypeDAO"); /* Language type data access */ LanguageTypeDAO languageTypeDAO = (LanguageTypeDAO) ctx.getBean("languageTypeDAO"); /* Language type data access */ ContributorTypeDAO contributorTypeDAO = (ContributorTypeDAO) ctx.getBean("contributorTypeDAO"); /* User relational data access */ IrUserDAO userDAO = (IrUserDAO) ctx.getBean("irUserDAO"); /* User access relational data access */ IrUserAccessControlEntryDAO uaceDAO = (IrUserAccessControlEntryDAO) ctx.getBean("irUserAccessControlEntryDAO"); /* Class type permission information */ IrClassTypePermissionDAO classTypePermissionDAO = (IrClassTypePermissionDAO) ctx.getBean("irClassTypePermissionDAO"); /* the Institutional repository acl relational data access */ IrAclDAO irAclDAO = (IrAclDAO) ctx.getBean("irAclDAO"); /** 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); } /** Bulk entry creation */ @Test public void createEntriesForUsersTest() throws ClassNotFoundException { 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); LanguageType lt2 = new LanguageType(); lt.setName("languageName2"); lt.setDescription("languageDescription2"); languageTypeDAO.makePersistent(lt2); IrAcl irAcl = new IrAcl(lt, languageClassType); IrAcl irAcl2 = new IrAcl(lt2, languageClassType); irAclDAO.makePersistent(irAcl); irAclDAO.makePersistent(irAcl2); 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); UserEmail userEmail2 = new UserEmail("user@email2"); IrUser user2 = userManager.createUser("passowrd2", "userName2"); user.setLastName("familyName2"); user.setFirstName("forename2"); user.addUserEmail(userEmail2, true); userDAO.makePersistent(user2); // create some permissions 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); // complete the transaction tm.commit(ts); // start a new transaction ts = tm.getTransaction(td); List<IrUser> users = new LinkedList<IrUser>(); users.add(user); users.add(user2); List<IrAcl> acls = new LinkedList<IrAcl>(); acls.add(irAcl); acls.add(irAcl2); // create user entries for all given acls int count = uaceDAO.createUserControlEntriesForUsers(users, acls); assert count == 4 : "Should have 4 entries but have " + count; List<IrUserAccessControlEntry> entries = new LinkedList<IrUserAccessControlEntry>(); entries.addAll(uaceDAO.getUserControlEntriesForUsers(irAcl, users)); entries.addAll(uaceDAO.getUserControlEntriesForUsers(irAcl2, users)); assert entries.size() == 4 : "Should find 4 entries but found " + entries.size(); // create permissions for all given user control entries List<IrClassTypePermission> permissions = new LinkedList<IrClassTypePermission>(); permissions.add(classTypePermission); permissions.add(classTypePermission1); int permissionEntriesCount = uaceDAO.createPermissionsForUserControlEntries(entries, permissions); assert permissionEntriesCount == 8 : "Should have 8 entries but have " + permissionEntriesCount; // commit the transaction tm.commit(ts); // start a new transaction ts = tm.getTransaction(td); // clean up the database irAclDAO.makeTransient(irAclDAO.getById(irAcl.getId(), false)); irAclDAO.makeTransient(irAclDAO.getById(irAcl2.getId(), false)); userDAO.makeTransient(userDAO.getById(user.getId(), false)); userDAO.makeTransient(userDAO.getById(user2.getId(), false)); languageTypeDAO.makeTransient(languageTypeDAO.getById(lt.getId(), false)); languageTypeDAO.makeTransient(languageTypeDAO.getById(lt2.getId(), false)); classTypePermissionDAO.makeTransient( classTypePermissionDAO.getById(classTypePermission.getId(), false)); classTypePermissionDAO.makeTransient( classTypePermissionDAO.getById(classTypePermission1.getId(), false)); irClassTypeDAO.makeTransient(irClassTypeDAO.getById(languageClassType.getId(), false)); // commit the transaction tm.commit(ts); } /** Bulk entry creation */ @Test public void createEntriesForUsersMultipleClassTypesTest() throws ClassNotFoundException { TransactionStatus ts = tm.getTransaction(td); LanguageType lt = new LanguageType(); lt.setName("languageName"); languageTypeDAO.makePersistent(lt); ContributorType ct = new ContributorType("type"); contributorTypeDAO.makePersistent(ct); IrClassType languageClassType = new IrClassType(LanguageType.class); irClassTypeDAO.makePersistent(languageClassType); IrClassType contributorClassType = new IrClassType(ContributorType.class); irClassTypeDAO.makePersistent(contributorClassType); IrAcl irAcl = new IrAcl(lt, languageClassType); IrAcl irAcl2 = new IrAcl(ct, contributorClassType); irAclDAO.makePersistent(irAcl); irAclDAO.makePersistent(irAcl2); 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); UserEmail userEmail2 = new UserEmail("user@email2"); IrUser user2 = userManager.createUser("passowrd2", "userName2"); user.setLastName("familyName2"); user.setFirstName("forename2"); user.addUserEmail(userEmail2, true); userDAO.makePersistent(user2); // create some permissions IrClassTypePermission classTypePermission = new IrClassTypePermission(languageClassType); classTypePermission.setName("permissionName"); classTypePermission.setDescription("permissionDescription"); IrClassTypePermission classTypePermission1 = new IrClassTypePermission(contributorClassType); classTypePermission1.setName("permissionName1"); classTypePermission1.setDescription("permissionDescription1"); // save the class type permission classTypePermissionDAO.makePersistent(classTypePermission); classTypePermissionDAO.makePersistent(classTypePermission1); // complete the transaction tm.commit(ts); // start a new transaction ts = tm.getTransaction(td); List<IrUser> users = new LinkedList<IrUser>(); users.add(user); users.add(user2); List<IrAcl> acls = new LinkedList<IrAcl>(); acls.add(irAcl); acls.add(irAcl2); // create user entries for all given acls int count = uaceDAO.createUserControlEntriesForUsers(users, acls); assert count == 4 : "Should have 4 entries but have " + count; List<IrUserAccessControlEntry> entries = new LinkedList<IrUserAccessControlEntry>(); entries.addAll(uaceDAO.getUserControlEntriesForUsers(irAcl, users)); entries.addAll(uaceDAO.getUserControlEntriesForUsers(irAcl2, users)); assert entries.size() == 4 : "Should find 4 entries but found " + entries.size(); // create permissions for all given user control entries List<IrClassTypePermission> permissions = new LinkedList<IrClassTypePermission>(); permissions.add(classTypePermission); permissions.add(classTypePermission1); int permissionEntriesCount = uaceDAO.createPermissionsForUserControlEntries(entries, permissions); assert permissionEntriesCount == 4 : "Should have 4 entries but have " + permissionEntriesCount; // commit the transaction tm.commit(ts); // start a new transaction ts = tm.getTransaction(td); // clean up the database irAclDAO.makeTransient(irAclDAO.getById(irAcl.getId(), false)); irAclDAO.makeTransient(irAclDAO.getById(irAcl2.getId(), false)); userDAO.makeTransient(userDAO.getById(user.getId(), false)); userDAO.makeTransient(userDAO.getById(user2.getId(), false)); languageTypeDAO.makeTransient(languageTypeDAO.getById(lt.getId(), false)); contributorTypeDAO.makeTransient(contributorTypeDAO.getById(ct.getId(), false)); classTypePermissionDAO.makeTransient( classTypePermissionDAO.getById(classTypePermission.getId(), false)); classTypePermissionDAO.makeTransient( classTypePermissionDAO.getById(classTypePermission1.getId(), false)); irClassTypeDAO.makeTransient(irClassTypeDAO.getById(languageClassType.getId(), false)); irClassTypeDAO.makeTransient(irClassTypeDAO.getById(contributorClassType.getId(), false)); // commit the transaction tm.commit(ts); } }
/** * Class for testing personal item persistence. * * @author Nathan Sarr */ public class PersonalItemDAOTest { /** get the application context */ ApplicationContext ctx = ContextHolder.getApplicationContext(); /** Transaction manager */ PlatformTransactionManager tm = (PlatformTransactionManager) ctx.getBean("transactionManager"); /** transaction definition */ TransactionDefinition td = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED); /** Properties file with testing specific information. */ PropertiesLoader propertiesLoader = new PropertiesLoader(); /** Get the properties file */ Properties properties = propertiesLoader.getProperties(); /** User relational data access */ IrUserDAO userDAO = (IrUserDAO) ctx.getBean("irUserDAO"); /** personal item relational data access */ PersonalItemDAO personalItemDAO = (PersonalItemDAO) ctx.getBean("personalItemDAO"); VersionedItemDAO versionedItemDAO = (VersionedItemDAO) ctx.getBean("versionedItemDAO"); /** Generic item data access */ GenericItemDAO itemDAO = (GenericItemDAO) ctx.getBean("itemDAO"); /** 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 retrieveing a personal item by a generic item id */ @Test public void getPersonalItemByGenericItemIdDAOTest() { 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"); GenericItem genericItem2 = new GenericItem("aSecondItem"); VersionedItem versionedItem = new VersionedItem(user, genericItem); versionedItem.addNewVersion(genericItem2); 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"; // make sure select works PersonalItem other2 = personalItemDAO.getPersonalItem(genericItem.getId()); assert other2.equals(other) : " other 2 = " + other2 + " other = " + other; PersonalItem other3 = personalItemDAO.getPersonalItem(genericItem2.getId()); assert other3.equals(other) : " other 3 = " + other3 + " other = " + other; 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)); itemDAO.makeTransient(itemDAO.getById(genericItem2.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"; } }