001: /*
002: * Copyright 2006-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.chart.service;
017:
018: import java.util.Iterator;
019: import java.util.Map;
020:
021: import org.kuali.core.bo.user.AuthenticationUserId;
022: import org.kuali.core.bo.user.UniversalUser;
023: import org.kuali.core.exceptions.UserNotFoundException;
024: import org.kuali.core.service.KualiModuleService;
025: import org.kuali.kfs.bo.AccountResponsibility;
026: import org.kuali.kfs.context.KualiTestBase;
027: import org.kuali.kfs.context.SpringContext;
028: import org.kuali.module.chart.bo.Chart;
029: import org.kuali.module.chart.bo.ChartUser;
030: import org.kuali.test.ConfigureContext;
031:
032: @ConfigureContext
033: public class ChartUserServiceTest extends KualiTestBase {
034: private UniversalUser user = new UniversalUser();
035: private static final String PRIMARY_DEPARTMENT_CODE1 = "BL-PSY";
036: private static final String PRIMARY_DEPARTMENT_CODE2 = "UA-FMOP";
037:
038: private ChartUser getChartUser(String userID)
039: throws UserNotFoundException {
040: return ((ChartUserService) SpringContext.getBean(
041: KualiModuleService.class)
042: .getModule(ChartUser.MODULE_ID).getModuleUserService())
043: .getModuleUser(ChartUser.MODULE_ID,
044: new AuthenticationUserId(userID));
045: }
046:
047: private ChartUserService getChartUserService() {
048: return (ChartUserService) SpringContext.getBean(
049: KualiModuleService.class)
050: .getModule(ChartUser.MODULE_ID).getModuleUserService();
051: }
052:
053: public void testGetUser() throws Exception {
054: ChartUser chartUser = getChartUser(TestConstants.Data2.AUTHENTICATION_USER_ID);
055: assertNotNull(chartUser);
056: assertTrue(chartUser.getUniversalUser()
057: .getPersonUserIdentifier().equalsIgnoreCase(
058: TestConstants.Data2.AUTHENTICATION_USER_ID));
059: assertNotNull(chartUser.getUniversalUser());
060: assertNotNull(chartUser.getUniversalUser().getGroups());
061: assertTrue(chartUser.getUniversalUser().getGroups().size() > 0);
062: }
063:
064: public void testGetAccountResponsibilities() throws Exception {
065:
066: ChartUser chartUser = getChartUser(TestConstants.Data4.USER_ID1);
067: Map accountResponsibilities = chartUser
068: .getAccountResponsibilities();
069: assertNotNull(accountResponsibilities);
070:
071: assertTrue(accountResponsibilities.size() > 0);
072: Iterator it = accountResponsibilities.values().iterator();
073: while (it.hasNext()) {
074: AccountResponsibility accountResponsibility = (AccountResponsibility) it
075: .next();
076: assertNotNull("Account should not be null",
077: accountResponsibility.getAccount());
078: // TODO: do we need to do any type specific checking?
079: // accountResponsibility.getAccountResponsibilityType();
080: assertNotNull("documentTypeId should not be null",
081: accountResponsibility.getDocumentTypeId());
082: assertNotNull("maximumDollarAmount should not be null",
083: accountResponsibility.getMaximumDollarAmount());
084: assertNotNull("minimumDollarAmount should not be null",
085: accountResponsibility.getMinimumDollarAmount());
086: }
087:
088: }
089:
090: public void testGetChartResponsibilities() throws Exception {
091: ChartUser chartUser = getChartUser("RRUFFNER");
092: Map chartResponsibilities = chartUser
093: .getChartResponsibilities();
094: assertNotNull(chartResponsibilities);
095:
096: assertTrue(chartResponsibilities.size() > 0);
097: Iterator it = chartResponsibilities.values().iterator();
098: while (it.hasNext()) {
099: Chart chart = (Chart) it.next();
100: assertNotNull("Chart should not be null", chart);
101: }
102: }
103:
104: public void testGetEmptyChartResponsibilities() throws Exception {
105: ChartUser chartUser = getChartUser(TestConstants.Data4.USER_ID1);
106: Map chartResponsibilities = chartUser
107: .getChartResponsibilities();
108: assertFalse(chartResponsibilities.size() > 0);
109: }
110:
111: public void testWorkgroupMemberships() throws Exception {
112: ChartUser chartUser = getChartUser(TestConstants.Data2.AUTHENTICATION_USER_ID_THAT_IS_SUPERVISOR);
113: System.out.println(chartUser.getUniversalUser()
114: .getPersonUserIdentifier()
115: + " groups: "
116: + chartUser.getUniversalUser().getGroups());
117: assertTrue(
118: TestConstants.Data2.AUTHENTICATION_USER_ID_THAT_IS_SUPERVISOR
119: + " should be in supervisor group", chartUser
120: .getUniversalUser().isSupervisorUser());
121: assertTrue(
122: TestConstants.Data2.AUTHENTICATION_USER_ID_THAT_IS_SUPERVISOR
123: + " should be in admin group", chartUser
124: .isAdministratorUser());
125: assertTrue(chartUser.getUniversalUser().isMember(
126: TestConstants.Data2.KUALI_DV_ADMIN_WORKGROUP));
127: assertTrue(chartUser.getUniversalUser().isMember(
128: TestConstants.Data2.KUALI_JV_USER_WORKGROUP));
129:
130: chartUser = getChartUser(TestConstants.Data4.USER_ID1);
131: assertFalse(chartUser.getUniversalUser().isMember(
132: TestConstants.Data2.WORKFLOW_ADMIN_WORKGROUP));
133: assertFalse(chartUser.isAdministratorUser());
134: assertFalse(chartUser.getUniversalUser().isSupervisorUser());
135: assertFalse(chartUser.getUniversalUser().isMember(
136: TestConstants.Data2.KUALI_DV_ADMIN_WORKGROUP));
137: assertFalse(chartUser.getUniversalUser().isMember(
138: TestConstants.Data2.KUALI_JV_USER_WORKGROUP));
139:
140: }
141:
142: public void testGetDefaultChartCode() throws Exception {
143: user.setPrimaryDepartmentCode(PRIMARY_DEPARTMENT_CODE1);
144: assertEquals(SpringContext.getBean(ChartUserService.class)
145: .getDefaultChartCode(user), "BL");
146: user.setPrimaryDepartmentCode(PRIMARY_DEPARTMENT_CODE2);
147: assertEquals(SpringContext.getBean(ChartUserService.class)
148: .getDefaultChartCode(user), "UA");
149: }
150:
151: public void testGetDefaultOrganizationCode() throws Exception {
152: user.setPrimaryDepartmentCode(PRIMARY_DEPARTMENT_CODE1);
153: assertEquals(SpringContext.getBean(ChartUserService.class)
154: .getDefaultOrganizationCode(user), "PSY");
155: user.setPrimaryDepartmentCode(PRIMARY_DEPARTMENT_CODE2);
156: assertEquals(SpringContext.getBean(ChartUserService.class)
157: .getDefaultOrganizationCode(user), "FMOP");
158: }
159: }
|