01: /*
02: * Copyright 2005-2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.kuali.core.workflow.service;
18:
19: import java.util.Collection;
20: import java.util.Iterator;
21:
22: import org.kuali.kfs.context.KualiTestBase;
23: import org.kuali.kfs.context.SpringContext;
24: import org.kuali.test.ConfigureContext;
25:
26: import edu.iu.uis.eden.clientapp.vo.NetworkIdVO;
27: import edu.iu.uis.eden.clientapp.vo.UserVO;
28: import edu.iu.uis.eden.clientapp.vo.WorkgroupVO;
29:
30: /**
31: * This class tests the WorkflowGroupr service.
32: */
33: @ConfigureContext
34: public class WorkflowGroupServiceTest extends KualiTestBase {
35:
36: private static final String SUPERVISOR_GROUP_NAME = "KUALI_ROLE_SUPERVISOR";
37: private static final String INQUIRE_ONLY_GROUP_NAME = "KUALI_ROLE_INQUIRE_ONLY";
38:
39: public void testGetByGroupName() throws Exception {
40: WorkgroupVO workgroup = SpringContext.getBean(
41: WorkflowGroupService.class).getWorkgroupByGroupName(
42: SUPERVISOR_GROUP_NAME);
43: assertNotNull(workgroup);
44: assertEquals(SUPERVISOR_GROUP_NAME, workgroup
45: .getWorkgroupName());
46: }
47:
48: public void testGetUsersGroups() throws Exception {
49: WorkgroupVO workgroup = SpringContext.getBean(
50: WorkflowGroupService.class).getWorkgroupByGroupName(
51: SUPERVISOR_GROUP_NAME);
52: UserVO[] users = (UserVO[]) workgroup.getMembers();
53: String username = users[0].getNetworkId();
54: Collection workgroups = SpringContext.getBean(
55: WorkflowGroupService.class).getWorkflowUsersGroups(
56: new NetworkIdVO(username));
57: assertNotNull(workgroups);
58: assertTrue(workgroupsContain(workgroups, workgroup));
59: // the inquiry workgroup
60: //workgroup = SpringContext.getBean(WorkflowGroupService.class).getWorkgroupByGroupName(INQUIRE_ONLY_GROUP_NAME);
61: //assertFalse(workgroupsContain(workgroups, workgroup));
62: }
63:
64: /**
65: * @param workgroup
66: * @return
67: */
68: private boolean workgroupsContain(Collection workgroups,
69: WorkgroupVO workgroup) {
70: boolean workgroupContains = false;
71:
72: Iterator it = workgroups.iterator();
73: while (it.hasNext()) {
74: WorkgroupVO group = (WorkgroupVO) it.next();
75: if (group.getWorkgroupId().longValue() == workgroup
76: .getWorkgroupId().longValue()) {
77: workgroupContains = true;
78: break;
79: }
80: }
81:
82: return workgroupContains;
83: }
84:
85: }
|