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.rules;
017:
018: import static org.kuali.test.fixtures.UserNameFixture.KHUNTLEY;
019: import static org.kuali.test.util.KualiTestAssertionUtils.assertGlobalErrorMapEmpty;
020:
021: import java.util.HashMap;
022: import java.util.Map;
023:
024: import org.kuali.core.document.MaintenanceDocument;
025: import org.kuali.core.service.BusinessObjectService;
026: import org.kuali.kfs.KFSConstants;
027: import org.kuali.kfs.context.SpringContext;
028: import org.kuali.module.chart.bo.Org;
029: import org.kuali.test.ConfigureContext;
030:
031: @ConfigureContext(session=KHUNTLEY)
032: public class OrgRuleTest extends ChartRuleTestBase {
033:
034: private static final String GOOD_CHART = "UA";
035: private static final String BAD_CHART = "ZZ";
036:
037: private static class OrgKeys {
038: private String chartOfAccountsCode;
039: private String organizationCode;
040: private String organizationManager;
041:
042: private OrgKeys(String chartOfAccountsCode,
043: String organizationCode, String organizationManager) {
044: this .chartOfAccountsCode = chartOfAccountsCode;
045: this .organizationCode = organizationCode;
046: this .organizationManager = organizationManager;
047: }
048:
049: static OrgKeys getGoodTopLevelOrgKeys() {
050: return new OrgKeys(TopLevelOrg.CHART_OF_ACCOUNTS_CODE,
051: TopLevelOrg.ORGANIZATION_CODE,
052: TopLevelOrg.ORGANIZATION_MANAGER);
053: }
054:
055: static OrgKeys getBadTopLevelOrgKeys() {
056: return new OrgKeys(CampusOrg.CHART_OF_ACCOUNTS_CODE,
057: CampusOrg.ORGANIZATION_CODE,
058: CampusOrg.ORGANIZATION_MANAGER);
059: }
060:
061: static OrgKeys getCampusOrgKeys() {
062: return new OrgKeys(CampusOrg.CHART_OF_ACCOUNTS_CODE,
063: CampusOrg.ORGANIZATION_CODE,
064: CampusOrg.ORGANIZATION_MANAGER);
065: }
066:
067: static OrgKeys getDepartmentOrgKeys() {
068: return new OrgKeys(DepartmentOrg.CHART_OF_ACCOUNTS_CODE,
069: DepartmentOrg.ORGANIZATION_CODE,
070: DepartmentOrg.ORGANIZATION_MANAGER);
071: }
072:
073: private class TopLevelOrg {
074: private static final String CHART_OF_ACCOUNTS_CODE = "IU";
075: private static final String ORGANIZATION_CODE = "UNIV";
076: private static final String ORGANIZATION_MANAGER = "CAMCSWEE";
077: }
078:
079: private class CampusOrg {
080: private static final String CHART_OF_ACCOUNTS_CODE = "FW";
081: private static final String ORGANIZATION_CODE = "FW";
082: private static final String ORGANIZATION_MANAGER = "MFLANDER";
083: }
084:
085: private class DepartmentOrg {
086: private static final String CHART_OF_ACCOUNTS_CODE = "FW";
087: private static final String ORGANIZATION_CODE = "ANTH";
088: private static final String ORGANIZATION_MANAGER = "HOATES";
089: }
090: }
091:
092: private OrgRule rule;
093: private Org org;
094: private MaintenanceDocument maintDoc;
095:
096: public void testDefaultExistenceChecks_chartOfAccounts_good() {
097: org = (Org) SpringContext.getBean(BusinessObjectService.class)
098: .findByPrimaryKey(
099: Org.class,
100: getPrimaryKeysForTopLevelOrg(OrgKeys
101: .getGoodTopLevelOrgKeys()));
102: maintDoc = this .newMaintDoc(org);
103: testDefaultExistenceCheck(org, "organizationCode", false);
104: assertGlobalErrorMapEmpty();
105: }
106:
107: /**
108: * This tests makes certain that only one top level heirarchy is allowed.
109: */
110: public void testCheckSimpleRules_topLevelHeirarchy_noMoreThanOne() {
111: Org oldBO = (Org) SpringContext.getBean(
112: BusinessObjectService.class).findByPrimaryKey(
113: Org.class,
114: this .getPrimaryKeysForTopLevelOrg(OrgKeys
115: .getGoodTopLevelOrgKeys()));
116: Org newBO = (Org) SpringContext.getBean(
117: BusinessObjectService.class).findByPrimaryKey(
118: Org.class,
119: this .getPrimaryKeysForTopLevelOrg(OrgKeys
120: .getBadTopLevelOrgKeys()));
121: maintDoc = this .newMaintDoc(oldBO, newBO);
122: maintDoc.getNewMaintainableObject().setMaintenanceAction(
123: KFSConstants.MAINTENANCE_EDIT_ACTION); // simulate editing
124: newBO
125: .setReportsToChartOfAccountsCode(OrgKeys.CampusOrg.CHART_OF_ACCOUNTS_CODE); // simulate trying to create a new top
126: // level org
127: newBO
128: .setReportsToOrganizationCode(OrgKeys.CampusOrg.ORGANIZATION_CODE);
129: rule = (OrgRule) this
130: .setupMaintDocRule(maintDoc, OrgRule.class);
131: assertFalse(rule.checkSimpleRules(maintDoc)); // we may not add more than one top level org
132: }
133:
134: /**
135: * This test makes certain that a top level heirarchy can be edited in a maintenance doc.
136: */
137: public void testCheckSimpleRules_topLevelHeirarchy_mayEdit() {
138: rule = new OrgRule();
139: Org oldBO = (Org) SpringContext.getBean(
140: BusinessObjectService.class).findByPrimaryKey(
141: Org.class,
142: this .getPrimaryKeysForTopLevelOrg(OrgKeys
143: .getGoodTopLevelOrgKeys()));
144: Org newBO = (Org) SpringContext.getBean(
145: BusinessObjectService.class).findByPrimaryKey(
146: Org.class,
147: this .getPrimaryKeysForTopLevelOrg(OrgKeys
148: .getGoodTopLevelOrgKeys()));
149: newBO
150: .setReportsToChartOfAccountsCode(OrgKeys.TopLevelOrg.CHART_OF_ACCOUNTS_CODE); // simulate editing top level org
151: newBO
152: .setReportsToOrganizationCode(OrgKeys.TopLevelOrg.ORGANIZATION_CODE);
153: maintDoc = this .newMaintDoc(oldBO, newBO);
154: maintDoc.getNewMaintainableObject().setMaintenanceAction(
155: KFSConstants.MAINTENANCE_EDIT_ACTION); // simulate editing
156: rule = (OrgRule) this
157: .setupMaintDocRule(maintDoc, OrgRule.class);
158: assertTrue(rule.checkSimpleRules(maintDoc)); // it is okay to edit the top level org
159: }
160:
161: /**
162: * This method assures that on edit, a university level org does not need a default account number.
163: */
164: public void testCheckDefaultAccountNumber_canEditUniversity() {
165: Org oldBO = (Org) SpringContext.getBean(
166: BusinessObjectService.class).findByPrimaryKey(
167: Org.class,
168: this .getPrimaryKeysForTopLevelOrg(OrgKeys
169: .getGoodTopLevelOrgKeys()));
170: Org newBO = (Org) SpringContext.getBean(
171: BusinessObjectService.class).findByPrimaryKey(
172: Org.class,
173: this .getPrimaryKeysForTopLevelOrg(OrgKeys
174: .getGoodTopLevelOrgKeys()));
175: newBO.setOrganizationDefaultAccountNumber(null); // simulate no organization default account number
176: maintDoc = this .newMaintDoc(oldBO, newBO);
177: maintDoc.getNewMaintainableObject().setMaintenanceAction(
178: KFSConstants.MAINTENANCE_EDIT_ACTION); // simulate editing
179: rule = (OrgRule) this
180: .setupMaintDocRule(maintDoc, OrgRule.class);
181: assertTrue(rule.checkDefaultAccountNumber(maintDoc)); // it is okay for a university to have no default account number
182: }
183:
184: /**
185: * This method assures that on edit, a campus level org does not need a default account number.
186: */
187: public void testCheckDefaultAccountNumber_canEditCampus() {
188: Org oldBO = (Org) SpringContext.getBean(
189: BusinessObjectService.class).findByPrimaryKey(
190: Org.class,
191: this .getPrimaryKeysForTopLevelOrg(OrgKeys
192: .getCampusOrgKeys()));
193: Org newBO = (Org) SpringContext.getBean(
194: BusinessObjectService.class).findByPrimaryKey(
195: Org.class,
196: this .getPrimaryKeysForTopLevelOrg(OrgKeys
197: .getCampusOrgKeys()));
198: newBO.setOrganizationDefaultAccountNumber(null); // simulate no organization default account number
199: maintDoc = this .newMaintDoc(oldBO, newBO);
200: maintDoc.getNewMaintainableObject().setMaintenanceAction(
201: KFSConstants.MAINTENANCE_EDIT_ACTION); // simulate editing
202: rule = (OrgRule) this
203: .setupMaintDocRule(maintDoc, OrgRule.class);
204: assertTrue(rule.checkDefaultAccountNumber(maintDoc)); // it is okay for a campus to have no default account number
205: }
206:
207: /**
208: * This method assures that on edit, a non-university/non-campus *does* need a default account number.
209: */
210: public void testCheckDefaultAccountNumber_cannotEditDepartment() {
211: Org oldBO = (Org) SpringContext.getBean(
212: BusinessObjectService.class).findByPrimaryKey(
213: Org.class,
214: this .getPrimaryKeysForTopLevelOrg(OrgKeys
215: .getDepartmentOrgKeys()));
216: Org newBO = (Org) SpringContext.getBean(
217: BusinessObjectService.class).findByPrimaryKey(
218: Org.class,
219: this .getPrimaryKeysForTopLevelOrg(OrgKeys
220: .getDepartmentOrgKeys()));
221: newBO.setOrganizationDefaultAccountNumber(null); // simulate no organization default account number
222: maintDoc = this .newMaintDoc(oldBO, newBO);
223: maintDoc.getNewMaintainableObject().setMaintenanceAction(
224: KFSConstants.MAINTENANCE_EDIT_ACTION); // simulate editing
225: rule = (OrgRule) this
226: .setupMaintDocRule(maintDoc, OrgRule.class);
227: assertFalse(rule.checkDefaultAccountNumber(maintDoc)); // it is NOT okay for a non-university/non-campus to have no default
228: // account number
229: }
230:
231: private Map getPrimaryKeysForTopLevelOrg(OrgKeys org) {
232: Map primaryKeys = new HashMap();
233: primaryKeys.put("chartOfAccountsCode", org.chartOfAccountsCode);
234: primaryKeys.put("organizationCode", org.organizationCode);
235: return primaryKeys;
236: }
237: }
|