001: package edu.iu.uis.eden.workgroup;
002:
003: import java.util.Iterator;
004: import java.util.List;
005:
006: import junit.framework.TestCase;
007: import edu.iu.uis.eden.SpringServiceLocator;
008: import edu.iu.uis.eden.user.UserService;
009: import edu.iu.uis.eden.user.WorkflowUser;
010: import edu.iu.uis.eden.user.WorkflowUserId;
011:
012: public class WorkgroupServiceTest extends TestCase {
013:
014: public static final int CURRENT_NUMBER_OF_GROUPS = 37;
015:
016: private WorkflowGroupId groupId = new WorkflowGroupId(
017: new Long(3121));
018: private GroupNameId groupName = new GroupNameId(
019: "HRE Technical Team");
020: private WorkflowUserId workflowUserId = new WorkflowUserId(
021: "100000000401");
022: private WorkgroupService workgroupService;
023: private UserService userService;
024:
025: protected void setUp() throws Exception {
026: SpringServiceLocator.setToTestMode(null);
027: workgroupService = (WorkgroupService) SpringServiceLocator
028: .getService(SpringServiceLocator.WORKGROUP_SRV);
029: userService = (UserService) SpringServiceLocator
030: .getService(SpringServiceLocator.USER_SERVICE);
031: }
032:
033: protected void tearDown() throws Exception {
034: super .tearDown();
035: }
036:
037: public void testGetWorkgroup() throws Exception {
038:
039: Workgroup workgroupById = workgroupService
040: .getWorkgroup(groupId);
041: Workgroup workgroupByName = workgroupService
042: .getWorkgroup(groupName);
043:
044: assertNotNull(workgroupById);
045: assertNotNull(workgroupByName);
046:
047: assertEquals("Didn't fetch the same workgroup", workgroupById
048: .getWorkflowGroupId(), workgroupByName
049: .getWorkflowGroupId());
050: assertEquals("Didn't fetch the same workgroup", workgroupById
051: .getGroupNameId(), workgroupByName.getGroupNameId());
052: verifyMembersWorkflowUsers(workgroupById);
053: verifyMembersWorkflowUsers(workgroupByName);
054: }
055:
056: public void testGetUsersGroups() throws Exception {
057:
058: WorkflowUser user = userService.getWorkflowUser(workflowUserId);
059: List groups = workgroupService.getUsersGroups(user);
060:
061: assertEquals("Didn't return correct number of groups",
062: CURRENT_NUMBER_OF_GROUPS, groups.size());
063: for (Iterator iter = groups.iterator(); iter.hasNext();) {
064: verifyMembersWorkflowUsers((Workgroup) iter.next());
065: }
066: }
067:
068: public void testSearch() throws Exception {
069:
070: Workgroup workgroup = workgroupService.getWorkgroup(groupId);
071: List groups = workgroupService.search(workgroup, false);
072:
073: boolean found = false;
074: for (Iterator iter = groups.iterator(); iter.hasNext();) {
075: Workgroup foundGroup = (Workgroup) iter.next();
076: if (foundGroup.getWorkflowGroupId().equals(
077: workgroup.getWorkflowGroupId())) {
078: found = true;
079: }
080: verifyMembersWorkflowUsers(foundGroup);
081: }
082:
083: assertTrue("Didn't find correct group", found);
084: assertEquals("Returned more than object group", 1, groups
085: .size());
086: }
087:
088: public void testIsUserMemberOfGroup() throws Exception {
089:
090: WorkflowUser member = userService
091: .getWorkflowUser(workflowUserId);
092: assertTrue("IsUserMemberOfGroup didn't return true",
093: workgroupService.isUserMemberOfGroup(groupId, member));
094: }
095:
096: private void verifyMembersWorkflowUsers(Workgroup workgroup) {
097: assertTrue("Workgroup must have member(s)", workgroup
098: .getMembers().size() > 0);
099: for (Iterator iter = workgroup.getMembers().iterator(); iter
100: .hasNext();) {
101: assertTrue("WorkflowUser not used as group member", iter
102: .next() instanceof WorkflowUser);
103: }
104: }
105: }
|