📄 groupstester.java
字号:
assertEquals(msg, 0, list.size()); } print(CR + "***** LEAVING GroupsTester.testDeleteChildGroup() *****" + CR);}/** */public void testGroupMemberUpdate() throws Exception{ print(CR + "***** ENTERING GroupsTester.testGroupMemberUpdate() *****" + CR); String msg = null; Iterator itr; Collection list; int idx = 0; Exception e = null; int numAddedEntities = 10; int numDeletedEntities = 5; print("Creating 2 new groups."); IEntityGroup parent = getNewGroup(); parent.setName("parent"); parent.setCreatorID("de3"); String parentKey = parent.getKey(); IEntityGroup child = getNewGroup(); child.setName("child"); child.setCreatorID("de3"); String childKey = child.getKey(); print("Adding " + child + " to " + parent); parent.addMember(child); print("Adding " + numAddedEntities + " members to " + child); for(idx=0; idx<numAddedEntities; idx++) { child.addMember(testEntities[idx]); } print("Now updating " + parent + " and " + child); child.update(); parent.update(); msg = "Retrieving members from " + child; // child should have numAddedEntities group members. print(msg); list = getGroupMembers(child); assertEquals(msg, (numAddedEntities), list.size()); msg = "Retrieving members from " + parent; // parent should have numAddedEntities + 1 group members. print(msg); list = getAllGroupMembers(parent); assertEquals(msg, (numAddedEntities + 1), list.size()); msg = "Retrieving " + parent + " and " + child + " from db."; print(msg); IEntityGroup retrievedParent = GroupService.findGroup(parentKey); IEntityGroup retrievedChild = GroupService.findGroup(childKey); assertEquals(msg, parent, retrievedParent); assertEquals(msg, child, retrievedChild); // retrievedChild should have numAddedEntities group members. msg = "Retrieving members from " + retrievedChild; print(msg); list = getAllGroupMembers(retrievedChild); assertEquals(msg, numAddedEntities, list.size()); // retrievedParent should have numAddedEntities + 1 group members. msg = "Retrieving members from " + retrievedParent; print(msg); list = getAllGroupMembers(retrievedParent); assertEquals(msg, (numAddedEntities + 1), list.size()); print("Deleting " + numDeletedEntities + " members from " + retrievedChild); for(idx=0; idx<numDeletedEntities; idx++) { retrievedChild.removeMember(testEntities[idx]); } // retrievedChild should have (numAddedEntities - numDeletedEntities) members. msg = "Retrieving members from " + retrievedChild; print(msg); list = getAllGroupMembers(retrievedChild); assertEquals(msg, (numAddedEntities - numDeletedEntities), list.size()); msg = "Adding back one member to " + retrievedChild; print(msg); retrievedChild.addMember(testEntities[0]); // retrievedChild should have (numAddedEntities - numDeletedEntities + 1) members. msg = "Retrieving members from " + retrievedChild; print(msg); list = getAllGroupMembers(retrievedChild); assertEquals(msg, (numAddedEntities - numDeletedEntities + 1), list.size()); int numChildMembers = list.size(); print("Now updating " + retrievedChild); retrievedChild.update(); msg = "Re-Retrieving " + retrievedChild + " from db."; print(msg); IEntityGroup reRetrievedChild = GroupService.findGroup(childKey); assertEquals(msg, retrievedChild, reRetrievedChild); // re-RetrievedChild should have (numAddedEntities - numDeletedEntities + 1) members. msg = "Retrieving members from " + reRetrievedChild; print(msg); list = getAllGroupMembers(reRetrievedChild); assertEquals(msg, numChildMembers, list.size()); // Remove parent and child groups from db. msg = "Deleting " + retrievedParent + " and " + reRetrievedChild + " from db."; print(msg); retrievedParent.delete(); reRetrievedChild.delete(); IEntityGroup deletedParent = GroupService.findGroup(parentKey); IEntityGroup deletedChild = GroupService.findGroup(childKey); assertNull(msg, deletedParent); assertNull(msg, deletedChild); print(CR + "***** LEAVING GroupsTester.testGroupMemberUpdate() *****" + CR);}/** */public void testGroupMemberValidation() throws Exception{ print(CR + "***** ENTERING GroupsTester.testGroupMemberValidation() *****" + CR); String msg = null; Iterator itr; Collection list; int idx = 0; Exception e = null; IEntityGroup parent = getNewGroup(); parent.setName("parent"); parent.setCreatorID("de3"); IEntityGroup child = getNewGroup(); child.setName("child"); child.setCreatorID("de3"); IEntityGroup child2 = getNewGroup(); child2.setName("child"); child2.setCreatorID("de3"); IEntity entity1 = getNewEntity("child"); IEntity entity2 = getNewEntity("child"); IEntity ipersonEntity = GroupService.getEntity("00000", IPERSON_CLASS); msg = "Adding " + child + " to " + parent; print(msg); parent.addMember(child); parent.update(); // members not cached. msg = "Retrieving members from " + parent; // parent should have 1 group member. print(msg); list = getGroupMembers(parent); assertEquals(msg, 1, list.size()); // Test adding a group with a duplicate name. msg = "Adding " + child2 + " to " + parent + " (this is allowed)."; print(msg); try { parent.addMember(child2); parent.update(); // members not cached. } catch (GroupsException ge) {e = ge;} assertNull(msg, e); msg = "Retrieving members from " + parent; // parent should now have 2 group members. print(msg); list = getGroupMembers(parent); assertEquals(msg, 2, list.size()); // Test adding an ENTITY with the same name as a member GROUP. msg = "Adding entity w/same name as child group to " + parent; print(msg); parent.addMember(entity1); parent.update(); // members not cached. msg = "Retrieving members from " + parent; // parent should now have 3 group members. print(msg); list = getGroupMembers(parent); assertEquals(msg, 3, list.size()); // Test adding a group member with a duplicate key. msg = "Adding another entity w/same key as child group to " + parent + " (noop)."; print(msg); try { parent.addMember(entity2); parent.update(); // members not cached. e = null; } catch (GroupsException ge) {e = ge;} assertNull(msg, e); msg = "Retrieving members from " + parent; // parent should still have 3 group members. print(msg); list = getGroupMembers(parent); assertEquals(msg, 3, list.size()); // Test adding a group member with a different type: msg = "Adding an entity of different type to " + parent; print(msg); try { parent.addMember(ipersonEntity); parent.update(); // members not cached. e = null; } catch (GroupsException ge) {e = ge;} assertNotNull(msg, e); msg = "Retrieving members from " + parent; // parent should still have 3 group members. print(msg); list = getGroupMembers(parent); assertEquals(msg, 3, list.size()); // Test adding a circular reference. try { child.addMember(parent); child.update(); // members not cached. e = null; } catch (GroupsException ge) { e = ge; } assertNotNull(msg, e); msg = "Retrieving members from " + child; // child should have 0 members. print(msg); list = getGroupMembers(child); assertEquals(msg, 0, list.size()); print(CR + "***** LEAVING GroupsTester.testGroupMemberValidation() *****" + CR);}/** */public void testRetrieveParentGroups() throws Exception{ print(CR + "***** ENTERING GroupsTester.testRetrieveParentGroups() *****" + CR); String msg = null; int numAllGroups = 10; int numContainingGroups = 8; IEntityGroup[] allGroups = new IEntityGroup[numAllGroups]; IEntity testEntity = testEntities[0]; Iterator it = null; Collection list = null; int idx = 0; msg = "Creating " + numAllGroups + " new groups..."; print(msg); for (idx=0; idx < numAllGroups; idx++) { allGroups[idx] = getNewGroup(); assertNotNull(msg, allGroups[idx]); allGroups[idx].setName("Parent Group " + idx); allGroups[idx].setCreatorID("de3"); allGroups[idx].update(); print("Group " + allGroups[idx].getName() + " created."); } msg = numAllGroups + " new groups created"; print(msg); msg = "Adding " + testEntity + " to " + numContainingGroups + " containing groups."; print(msg); for (idx=0; idx<numContainingGroups; idx++) { allGroups[idx].addMember(testEntity); allGroups[idx].update(); } msg = "Getting containing groups for " + testEntity; print(msg); list = new ArrayList(); for (it = testEntity.getContainingGroups(); it.hasNext();) { list.add(it.next()); } assertEquals(msg, numContainingGroups, list.size()); msg = "Adding parents to the immediate containing groups."; print(msg); for (idx=numContainingGroups; idx<numAllGroups; idx++) { IEntityGroup parent = allGroups[idx]; IEntityGroup child = allGroups[idx - 1]; msg = "Adding " + child + " to " + parent; print(msg); parent.addMember(child); parent.update(); } msg = "Getting ALL containing groups for " + testEntity; print(msg); list = new ArrayList(); for (it = testEntity.getAllContainingGroups(); it.hasNext();) { list.add(it.next()); } assertEquals(msg, numAllGroups, list.size()); IEntity duplicateTestEntity = GroupService.getEntity(testEntity.getKey(), testEntity.getType()); msg = "Getting ALL containing groups for DUPLICATE entity:" + testEntity; print(msg); list = new ArrayList(); for (it = duplicateTestEntity.getAllContainingGroups(); it.hasNext();) { list.add(it.next()); } assertEquals(msg, numAllGroups, list.size()); print(CR + "***** LEAVING GroupsTester.testRetrieveParentGroups() *****" + CR);}/** */public void testUpdateLockableGroups() throws Exception{ print(CR + "***** ENTERING GroupsTester.testUpdateLockableGroups() *****" + CR); String msg = null; Class type = TEST_ENTITY_CLASS; int totNumGroups = 3; int totNumEntities = 5; IEntityGroup[] groups = new IEntityGroup[totNumGroups]; IEntity[] entities = new IEntity[totNumEntities]; IGroupMember[] groupMembers = null; Iterator itr = null; ArrayList list = null; int idx = 0; boolean testValue = false; Exception e = null; msg = "Creating " + totNumGroups + " new groups."; print(msg); for (idx=0; idx<totNumGroups; idx++) { groups[idx] = getNewGroup(); groups[idx].update(); assertNotNull(msg, groups[idx]); groups[idx].update(); } msg = "Getting group keys."; print(msg); String[] groupKeys = new String[totNumGroups]; for (idx=0; idx<totNumGroups; idx++) { groupKeys[idx] = groups[idx].getKey(); } msg = "Retrieving lockable group for key " + groupKeys[0]; print(msg); ILockableEntityGroup lockableGroup1 = findLockableGroup(groupKeys[0]); testValue = lockableGroup1.getLock().isValid(); assertTrue(msg, testValue); msg = "Retrieving a duplicate lockable group for key " + groupKeys[0] + " (should FAIL)"; print(msg); try { ILockableEntityGroup lockableGroup2 = findLockableGroup(groupKeys[0]); } catch (GroupsException ge) {e = ge;} assertNotNull(msg, e); e = null; msg = "Checking lock of first group"; print(msg); testValue = lockableGroup1.getLock().isValid(); assertTrue(msg, testValue); String oldName = lockableGroup1.getName(); String newName = "NEW GROUP NAME"; msg = "Update name of lockable group but do not commit."; print(msg); lockableGroup1.setName(newName); assertEquals(msg, newName, lockableGroup1.getName()); msg = "Checking lock of first group"; print(msg); testValue = lockableGroup1.getLock().isValid(); assertTrue(msg, testValue); msg = "Retrieving duplicate group from service; change should NOT be visible."; print(msg); IEntityGroup nonLockableGroup = findGroup(groupKeys[0]); assertEquals(msg, oldName, nonLockableGroup.getName()); msg = "Checking lock of first group"; print(msg); testValue = lockableGroup1.getLock().isValid(); assertTrue(msg, testValue); msg = "Committing change to lockable group"; print(msg); lockableGroup1.update(); testValue = lockableGroup1.getLock().isValid(); assertTrue(msg, ! testValue); msg = "Retrieving duplicate group from service; change should be visible now."; print(msg); nonLockableGroup = findGroup(groupKeys[0]); assertEquals(msg, newName, nonLockableGroup.getName()); msg = "Attempting to delete old version of group " + groupKeys[0] + " (should FAIL.)"; print(msg); try { lockableGroup1.delete(); } catch (GroupsException ge) {e = ge;} assertNotNull(msg, e); e = null; msg = "Attempting to delete NEW version of group " + groupKeys[0]; print(msg); ILockableEntityGroup lockableGroup3 = findLockableGroup(groupKeys[0]); lockableGroup3.delete(); nonLockableGroup = findGroup(groupKeys[0]); assertNull(msg, nonLockableGroup);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -