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.kra.service;
017:
018: import static org.kuali.test.util.KualiTestAssertionUtils.assertEquality;
019:
020: import java.util.ArrayList;
021: import java.util.List;
022:
023: import org.kuali.core.util.ObjectUtils;
024: import org.kuali.kfs.context.KualiTestBase;
025: import org.kuali.kfs.context.SpringContext;
026: import org.kuali.module.kra.budget.bo.BudgetInstitutionCostShare;
027: import org.kuali.module.kra.budget.bo.BudgetThirdPartyCostShare;
028: import org.kuali.module.kra.budget.bo.BudgetUser;
029: import org.kuali.module.kra.budget.bo.InstitutionCostSharePersonnel;
030: import org.kuali.module.kra.budget.service.BudgetCostShareService;
031: import org.kuali.test.ConfigureContext;
032: import org.kuali.test.suite.AnnotationTestSuite;
033: import org.kuali.test.suite.CrossSectionSuite;
034:
035: /**
036: * This class tests service methods in BudgetCostShareService.
037: */
038: @AnnotationTestSuite(CrossSectionSuite.class)
039: @ConfigureContext
040: public class BudgetCostShareServiceTest extends KualiTestBase {
041:
042: public void testCleanseCostShare() {
043: String documentHeaderId = "160642";
044:
045: boolean universityCostShareIndicator = true;
046: List<BudgetInstitutionCostShare> budgetInstitutionCostShare = new ArrayList();
047: boolean budgetThirdPartyCostShareIndicator = true;
048: List<BudgetThirdPartyCostShare> budgetThirdPartyCostShare = new ArrayList();
049: List<BudgetUser> personnel = new ArrayList();
050: List<InstitutionCostSharePersonnel> institutionCostSharePersonnel = new ArrayList();
051:
052: // CONDITION: cost share TRUE, all empty lists
053: SpringContext.getBean(BudgetCostShareService.class)
054: .cleanseCostShare(universityCostShareIndicator,
055: budgetInstitutionCostShare,
056: budgetThirdPartyCostShareIndicator,
057: budgetThirdPartyCostShare, personnel,
058: institutionCostSharePersonnel);
059: // RESULT: no data change, but no crashes either
060: assertTrue(
061: "universityCostShareIndicator should never be changed",
062: universityCostShareIndicator);
063: assertTrue("budgetInstitutionCostShare should still be empty",
064: budgetInstitutionCostShare.size() == 0);
065: assertTrue(
066: "budgetThirdPartyCostShareIndicator should never be changed",
067: budgetThirdPartyCostShareIndicator);
068: assertTrue("budgetThirdPartyCostShare should still be empty",
069: budgetThirdPartyCostShare.size() == 0);
070:
071: budgetInstitutionCostShare
072: .add(new BudgetInstitutionCostShare());
073: budgetThirdPartyCostShare.add(new BudgetThirdPartyCostShare());
074:
075: // CONDITION: cost share TRUE, lists have values
076: SpringContext.getBean(BudgetCostShareService.class)
077: .cleanseCostShare(universityCostShareIndicator,
078: budgetInstitutionCostShare,
079: budgetThirdPartyCostShareIndicator,
080: budgetThirdPartyCostShare, personnel,
081: institutionCostSharePersonnel);
082: // RESULT: no data change
083: assertTrue(
084: "universityCostShareIndicator should never be changed",
085: universityCostShareIndicator);
086: assertTrue(
087: "budgetInstitutionCostShare should still contain 1 item",
088: budgetInstitutionCostShare.size() == 1);
089: assertTrue(
090: "budgetThirdPartyCostShareIndicator should never be changed",
091: budgetThirdPartyCostShareIndicator);
092: assertTrue(
093: "budgetInstitutionCostShare should still contain 1 item",
094: budgetThirdPartyCostShare.size() == 1);
095:
096: universityCostShareIndicator = false;
097:
098: // CONDITION: cost share TRUE, lists have values
099: SpringContext.getBean(BudgetCostShareService.class)
100: .cleanseCostShare(universityCostShareIndicator,
101: budgetInstitutionCostShare,
102: budgetThirdPartyCostShareIndicator,
103: budgetThirdPartyCostShare, personnel,
104: institutionCostSharePersonnel);
105: // RESULT: no data change
106: assertFalse(
107: "universityCostShareIndicator should never be changed",
108: universityCostShareIndicator);
109: assertTrue("budgetInstitutionCostShare should now be empty",
110: budgetInstitutionCostShare.size() == 0);
111: assertTrue(
112: "budgetThirdPartyCostShareIndicator should never be changed",
113: budgetThirdPartyCostShareIndicator);
114: assertTrue(
115: "budgetInstitutionCostShare should still contain 1 item",
116: budgetThirdPartyCostShare.size() == 1);
117:
118: universityCostShareIndicator = true;
119: budgetInstitutionCostShare
120: .add(new BudgetInstitutionCostShare());
121: budgetThirdPartyCostShareIndicator = false;
122:
123: // CONDITION: cost share TRUE, lists have values
124: SpringContext.getBean(BudgetCostShareService.class)
125: .cleanseCostShare(universityCostShareIndicator,
126: budgetInstitutionCostShare,
127: budgetThirdPartyCostShareIndicator,
128: budgetThirdPartyCostShare, personnel,
129: institutionCostSharePersonnel);
130: // RESULT: no data change
131: assertTrue(
132: "universityCostShareIndicator should never be changed",
133: universityCostShareIndicator);
134: assertTrue(
135: "budgetInstitutionCostShare should still contain 1 item",
136: budgetInstitutionCostShare.size() == 1);
137: assertFalse(
138: "budgetThirdPartyCostShareIndicator should never be changed",
139: budgetThirdPartyCostShareIndicator);
140: assertTrue("budgetThirdPartyCostShare should now be empty",
141: budgetThirdPartyCostShare.size() == 0);
142:
143: // CONDITION: cost share TRUE, all empty lists
144: SpringContext.getBean(BudgetCostShareService.class)
145: .cleanseCostShare(universityCostShareIndicator,
146: budgetInstitutionCostShare,
147: budgetThirdPartyCostShareIndicator,
148: budgetThirdPartyCostShare, personnel,
149: institutionCostSharePersonnel);
150: // RESULT: no data change, but no crashes either
151: assertTrue("personnel should never be changed", personnel
152: .size() == 0);
153: assertTrue(
154: "institutionCostSharePersonnel should still be empty",
155: institutionCostSharePersonnel.size() == 0);
156:
157: // Create a but if data
158: BudgetUser budgetUser1 = new BudgetUser();
159: budgetUser1.setFiscalCampusCode("BL");
160: budgetUser1.setPrimaryDepartmentCode("CSCI");
161: personnel.add(budgetUser1);
162:
163: InstitutionCostSharePersonnel universityCostSharePerson1 = new InstitutionCostSharePersonnel();
164: universityCostSharePerson1.setDocumentNumber("160642");
165: universityCostSharePerson1.setChartOfAccountsCode("BL");
166: universityCostSharePerson1.setOrganizationCode("CSCI");
167:
168: BudgetUser budgetUser2 = new BudgetUser();
169: budgetUser2.setFiscalCampusCode("IN");
170: budgetUser2.setPrimaryDepartmentCode("CARD");
171: personnel.add(budgetUser2);
172:
173: InstitutionCostSharePersonnel universityCostSharePerson2 = new InstitutionCostSharePersonnel();
174: universityCostSharePerson2.setDocumentNumber("160642");
175: universityCostSharePerson2.setChartOfAccountsCode("IN");
176: universityCostSharePerson2.setOrganizationCode("CARD");
177:
178: // Add data to institutionCostSharePersonnel (this assumes testReconcileCostShare runs clean).
179: SpringContext.getBean(BudgetCostShareService.class)
180: .reconcileCostShare(documentHeaderId, personnel,
181: institutionCostSharePersonnel);
182:
183: // CONDITION: cost share TRUE, personnel 2 items, institutionCostSharePersonnel same 2 items
184: SpringContext.getBean(BudgetCostShareService.class)
185: .cleanseCostShare(universityCostShareIndicator,
186: budgetInstitutionCostShare,
187: budgetThirdPartyCostShareIndicator,
188: budgetThirdPartyCostShare, personnel,
189: institutionCostSharePersonnel);
190: // RESULT: no data change
191: assertTrue("personnel should never be changed", personnel
192: .size() == 2);
193: assertTrue(
194: "institutionCostSharePersonnel should still contain 2 items",
195: institutionCostSharePersonnel.size() == 2);
196:
197: BudgetUser budgetUser3 = new BudgetUser();
198: budgetUser3.setFiscalCampusCode(null);
199: budgetUser3.setPrimaryDepartmentCode(null);
200: personnel.add(budgetUser3);
201:
202: BudgetUser budgetUser4 = new BudgetUser();
203: budgetUser4.setFiscalCampusCode("");
204: budgetUser4.setPrimaryDepartmentCode("");
205: personnel.add(budgetUser4);
206:
207: // CONDITION: Same as above but null / empty data was introduced.
208: SpringContext.getBean(BudgetCostShareService.class)
209: .cleanseCostShare(universityCostShareIndicator,
210: budgetInstitutionCostShare,
211: budgetThirdPartyCostShareIndicator,
212: budgetThirdPartyCostShare, personnel,
213: institutionCostSharePersonnel);
214: // RESULT: Same as above, no crash should occur.
215: assertTrue("personnel should never be changed", personnel
216: .size() == 4);
217: assertTrue(
218: "institutionCostSharePersonnel should still contain 2 items",
219: institutionCostSharePersonnel.size() == 2);
220:
221: personnel.remove(0);
222:
223: // CONDITION: The BL/CSCI entry was removed.
224: SpringContext.getBean(BudgetCostShareService.class)
225: .cleanseCostShare(universityCostShareIndicator,
226: budgetInstitutionCostShare,
227: budgetThirdPartyCostShareIndicator,
228: budgetThirdPartyCostShare, personnel,
229: institutionCostSharePersonnel);
230: // RESULT: The BL/CSCI entry shouldn't be in institutionCostSharePersonnel anymore
231: assertTrue("personnel should never be changed", personnel
232: .size() == 3);
233: assertTrue(
234: "institutionCostSharePersonnel should only contain 1 item now",
235: institutionCostSharePersonnel.size() == 1);
236: assertFalse(
237: "BL/CSCI entry should not be in institutionCostSharePersonnel anymore.",
238: ObjectUtils.collectionContainsObjectWithIdentitcalKey(
239: institutionCostSharePersonnel,
240: universityCostSharePerson1));
241: assertTrue(
242: "IN/CARD entry should still be in institutionCostSharePersonnel.",
243: ObjectUtils.collectionContainsObjectWithIdentitcalKey(
244: institutionCostSharePersonnel,
245: universityCostSharePerson2));
246: }
247:
248: public void testReconcileCostShare() {
249: String documentHeaderId = "160642";
250: List<BudgetUser> personnel = new ArrayList();
251: List<InstitutionCostSharePersonnel> institutionCostSharePersonnel = new ArrayList();
252:
253: // CONDITION: no personnel, no cost share
254: SpringContext.getBean(BudgetCostShareService.class)
255: .reconcileCostShare(documentHeaderId, personnel,
256: institutionCostSharePersonnel);
257: // RESULT: no personnel, no cost share
258: assertEquality(documentHeaderId, "160642");
259: assertTrue("Should still be empty.", personnel.isEmpty());
260: assertTrue("Should still be empty.",
261: institutionCostSharePersonnel.isEmpty());
262:
263: BudgetUser budgetUser1 = new BudgetUser();
264: budgetUser1.setFiscalCampusCode("BL");
265: budgetUser1.setPrimaryDepartmentCode("CSCI");
266: personnel.add(budgetUser1);
267:
268: InstitutionCostSharePersonnel universityCostSharePerson1 = new InstitutionCostSharePersonnel();
269: universityCostSharePerson1.setDocumentNumber("160642");
270: universityCostSharePerson1.setChartOfAccountsCode("BL");
271: universityCostSharePerson1.setOrganizationCode("CSCI");
272:
273: // CONDITION: 1 person, no cost share
274: SpringContext.getBean(BudgetCostShareService.class)
275: .reconcileCostShare(documentHeaderId, personnel,
276: institutionCostSharePersonnel);
277: // RESULT: 1 person, 1 cost share with identical keys
278: assertEquality(documentHeaderId, "160642");
279: assertTrue("Person list should not be changed.", personnel
280: .size() == 1);
281: assertTrue("Person's chart/org should have been added.",
282: institutionCostSharePersonnel.size() == 1);
283: assertTrue("Identical chart/org should have been found.",
284: ObjectUtils.collectionContainsObjectWithIdentitcalKey(
285: institutionCostSharePersonnel,
286: universityCostSharePerson1));
287:
288: personnel.add(budgetUser1);
289:
290: // CONDITION: 2 person, 1 cost share (same keys)
291: SpringContext.getBean(BudgetCostShareService.class)
292: .reconcileCostShare(documentHeaderId, personnel,
293: institutionCostSharePersonnel);
294: // RESULT: 2 person, 1 cost share with identical keys (ie. item not added again)
295: assertEquality(documentHeaderId, "160642");
296: assertTrue("Person list should not be changed.", personnel
297: .size() == 2);
298: assertTrue(
299: "Since the second person's chart/org was identical, it should not be added again.",
300: institutionCostSharePersonnel.size() == 1);
301: assertTrue("Identical chart/org should have been found.",
302: ObjectUtils.collectionContainsObjectWithIdentitcalKey(
303: institutionCostSharePersonnel,
304: universityCostSharePerson1));
305:
306: BudgetUser budgetUser2 = new BudgetUser();
307: budgetUser2.setFiscalCampusCode("IN");
308: budgetUser2.setPrimaryDepartmentCode("CARD");
309: personnel.add(budgetUser2);
310:
311: InstitutionCostSharePersonnel universityCostSharePerson2 = new InstitutionCostSharePersonnel();
312: universityCostSharePerson2.setDocumentNumber("160642");
313: universityCostSharePerson2.setChartOfAccountsCode("IN");
314: universityCostSharePerson2.setOrganizationCode("CARD");
315:
316: // CONDITION: 3 people, 1 cost share (one key same)
317: SpringContext.getBean(BudgetCostShareService.class)
318: .reconcileCostShare(documentHeaderId, personnel,
319: institutionCostSharePersonnel);
320: // RESULT: 3 people, 2 cost share with identical keys
321: assertEquality(documentHeaderId, "160642");
322: assertTrue("Person list should not be changed.", personnel
323: .size() == 3);
324: assertTrue("Person had new chart/org, should have been added.",
325: institutionCostSharePersonnel.size() == 2);
326: assertTrue(
327: "Original person's chart/org should still be there.",
328: ObjectUtils.collectionContainsObjectWithIdentitcalKey(
329: institutionCostSharePersonnel,
330: universityCostSharePerson1));
331: assertTrue("New person's chart/org should have been added.",
332: ObjectUtils.collectionContainsObjectWithIdentitcalKey(
333: institutionCostSharePersonnel,
334: universityCostSharePerson2));
335:
336: BudgetUser budgetUser3 = new BudgetUser();
337: budgetUser3.setFiscalCampusCode(null);
338: budgetUser3.setPrimaryDepartmentCode(null);
339: personnel.add(budgetUser3);
340:
341: BudgetUser budgetUser4 = new BudgetUser();
342: budgetUser4.setFiscalCampusCode("");
343: budgetUser4.setPrimaryDepartmentCode("");
344: personnel.add(budgetUser4);
345:
346: // CONDITION: 5 people, 2 cost share (two keys same)
347: SpringContext.getBean(BudgetCostShareService.class)
348: .reconcileCostShare(documentHeaderId, personnel,
349: institutionCostSharePersonnel);
350: // RESULT: 5 people, 2 cost share with identical keys
351: assertEquality(documentHeaderId, "160642");
352: assertTrue("Person list should not be changed.", personnel
353: .size() == 5);
354: assertTrue(
355: "There should have been no change to chart/org since people added were null org empty string.",
356: institutionCostSharePersonnel.size() == 2);
357: assertTrue(
358: "Original person's chart/org should still be there.",
359: ObjectUtils.collectionContainsObjectWithIdentitcalKey(
360: institutionCostSharePersonnel,
361: universityCostSharePerson1));
362: assertTrue(
363: "Second original person's chart/org should have been added.",
364: ObjectUtils.collectionContainsObjectWithIdentitcalKey(
365: institutionCostSharePersonnel,
366: universityCostSharePerson2));
367: }
368: }
|