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 java.util.ArrayList;
019: import java.util.Iterator;
020: import java.util.List;
021:
022: import org.kuali.core.util.KualiInteger;
023: import org.kuali.kfs.context.KualiTestBase;
024: import org.kuali.kfs.context.SpringContext;
025: import org.kuali.module.kra.bo.BudgetNonpersonnelTest;
026: import org.kuali.module.kra.bo.BudgetPeriodTest;
027: import org.kuali.module.kra.budget.bo.Budget;
028: import org.kuali.module.kra.budget.bo.BudgetIndirectCost;
029: import org.kuali.module.kra.budget.bo.BudgetNonpersonnel;
030: import org.kuali.module.kra.budget.bo.BudgetPeriod;
031: import org.kuali.module.kra.budget.bo.BudgetTask;
032: import org.kuali.module.kra.budget.bo.BudgetTaskPeriodIndirectCost;
033: import org.kuali.module.kra.budget.bo.UserAppointmentTaskPeriod;
034: import org.kuali.module.kra.budget.document.BudgetDocument;
035: import org.kuali.module.kra.budget.service.BudgetIndirectCostService;
036: import org.kuali.test.ConfigureContext;
037:
038: @ConfigureContext
039: public class BudgetIndirectCostServiceTest extends KualiTestBase {
040:
041: protected void populateBudgetTasksPeriods(
042: BudgetDocument budgetDocument) {
043:
044: List periods = BudgetPeriodTest.createBudgetPeriods(2);
045: for (int i = 0; i < periods.size(); i++) {
046: BudgetPeriod period = (BudgetPeriod) periods.get(i);
047: period.setDocumentNumber("1234");
048: period.setBudgetPeriodSequenceNumber(i);
049: }
050:
051: BudgetTask task1 = new BudgetTask();
052: task1.setDocumentNumber("1234");
053: task1.setBudgetTaskSequenceNumber(new Integer(0));
054:
055: BudgetTask task2 = new BudgetTask();
056: task2.setDocumentNumber("1234");
057: task2.setBudgetTaskSequenceNumber(new Integer(1));
058:
059: List tasks = new ArrayList();
060: tasks.add(task1);
061: tasks.add(task2);
062:
063: Budget budget = new Budget();
064: budget.setDocumentNumber("1234");
065: budget.setTasks(tasks);
066: budget.setPeriods(periods);
067:
068: budgetDocument.setBudget(budget);
069: }
070:
071: public void testReconcileIndirectCost() {
072: BudgetDocument budgetDocument = new BudgetDocument();
073: // Test new document
074: populateBudgetTasksPeriods(budgetDocument);
075:
076: SpringContext.getBean(BudgetIndirectCostService.class)
077: .reconcileIndirectCost(budgetDocument);
078:
079: BudgetIndirectCost indirectCost = budgetDocument.getBudget()
080: .getIndirectCost();
081: assertEquals(indirectCost.getDocumentNumber(), "1234");
082:
083: List idcList = indirectCost
084: .getBudgetTaskPeriodIndirectCostItems();
085: assertEquals(idcList.size(), 4);
086:
087: BudgetTaskPeriodIndirectCost idc1 = (BudgetTaskPeriodIndirectCost) idcList
088: .get(0);
089: assertEquals(idc1.getDocumentNumber(), "1234");
090: assertEquals(idc1.getBudgetTaskSequenceNumber(), new Integer(0));
091: assertEquals(idc1.getBudgetPeriodSequenceNumber(), new Integer(
092: 0));
093:
094: BudgetTaskPeriodIndirectCost idc2 = (BudgetTaskPeriodIndirectCost) idcList
095: .get(1);
096: assertEquals(idc2.getDocumentNumber(), "1234");
097: assertEquals(idc2.getBudgetTaskSequenceNumber(), new Integer(0));
098: assertEquals(idc2.getBudgetPeriodSequenceNumber(), new Integer(
099: 1));
100:
101: BudgetTaskPeriodIndirectCost idc3 = (BudgetTaskPeriodIndirectCost) idcList
102: .get(2);
103: assertEquals(idc3.getDocumentNumber(), "1234");
104: assertEquals(idc3.getBudgetTaskSequenceNumber(), new Integer(1));
105: assertEquals(idc3.getBudgetPeriodSequenceNumber(), new Integer(
106: 0));
107:
108: BudgetTaskPeriodIndirectCost idc4 = (BudgetTaskPeriodIndirectCost) idcList
109: .get(3);
110: assertEquals(idc4.getDocumentNumber(), "1234");
111: assertEquals(idc4.getBudgetTaskSequenceNumber(), new Integer(1));
112: assertEquals(idc4.getBudgetPeriodSequenceNumber(), new Integer(
113: 1));
114:
115: // Test existing document to be updated
116: BudgetTask newBudgetTask = new BudgetTask();
117: newBudgetTask.setDocumentNumber("1234");
118: newBudgetTask.setBudgetTaskSequenceNumber(2);
119:
120: budgetDocument.getBudget().getTasks().add(newBudgetTask);
121: budgetDocument.getBudget().getPeriods().remove(0);
122: budgetDocument.getBudget().getTasks().remove(1);
123:
124: SpringContext.getBean(BudgetIndirectCostService.class)
125: .reconcileIndirectCost(budgetDocument);
126:
127: indirectCost = budgetDocument.getBudget().getIndirectCost();
128: assertFalse(indirectCost
129: .getBudgetIndirectCostCostShareIndicator());
130: assertFalse(indirectCost
131: .getBudgetUnrecoveredIndirectCostIndicator());
132:
133: idcList = indirectCost.getBudgetTaskPeriodIndirectCostItems();
134: assertEquals(idcList.size(), 2);
135:
136: idc1 = (BudgetTaskPeriodIndirectCost) idcList.get(0);
137: assertEquals(idc1.getDocumentNumber(), "1234");
138: assertEquals(idc1.getBudgetTaskSequenceNumber(), new Integer(0));
139: assertEquals(idc1.getBudgetPeriodSequenceNumber(), new Integer(
140: 1));
141:
142: idc2 = (BudgetTaskPeriodIndirectCost) idcList.get(1);
143: assertEquals(idc2.getDocumentNumber(), "1234");
144: assertEquals(idc2.getBudgetTaskSequenceNumber(), new Integer(2));
145: assertEquals(idc2.getBudgetPeriodSequenceNumber(), new Integer(
146: 1));
147: }
148:
149: public void testRefreshIndirectCost() {
150: BudgetDocument budgetDocument = new BudgetDocument();
151: Budget budget = budgetDocument.getBudget();
152:
153: List periods = BudgetPeriodTest.createBudgetPeriods(2);
154: for (int i = 0; i < periods.size(); i++) {
155: BudgetPeriod period = (BudgetPeriod) periods.get(i);
156: period.setDocumentNumber("1234");
157: period.setBudgetPeriodSequenceNumber(i);
158: }
159: budget.setPeriods(periods);
160:
161: String[] categories = { "CO", "CO", "FL", "SC" };
162: String[] subCategories = { "C1", "C1", "F5", "R2" };
163: String[] subcontractorNumber = { "", "", "", "1" };
164: List nonpersonnelItems = BudgetNonpersonnelTest
165: .createBudgetNonpersonnel(categories, subCategories,
166: subcontractorNumber);
167: for (Iterator iter = nonpersonnelItems.iterator(); iter
168: .hasNext();) {
169: BudgetNonpersonnel nonpersonnel = (BudgetNonpersonnel) iter
170: .next();
171: nonpersonnel.setBudgetPeriodSequenceNumber(new Integer(2));
172: }
173: budget.setNonpersonnelItems(nonpersonnelItems);
174:
175: List userAppointmentTaskPeriods = new ArrayList();
176:
177: assertFalse("Budget periods should not be empty.", budget
178: .getPeriods().isEmpty());
179: BudgetPeriod period1 = (BudgetPeriod) budget.getPeriods()
180: .get(0);
181:
182: UserAppointmentTaskPeriod taskPeriod = new UserAppointmentTaskPeriod();
183: taskPeriod.setBudgetPeriodSequenceNumber(period1
184: .getBudgetPeriodSequenceNumber());
185: taskPeriod.setAgencyRequestTotalAmount(new KualiInteger(39000));
186: taskPeriod.setAgencyFringeBenefitTotalAmount(new KualiInteger(
187: 13000));
188: userAppointmentTaskPeriods.add(taskPeriod);
189:
190: UserAppointmentTaskPeriod taskPeriod2 = new UserAppointmentTaskPeriod();
191: taskPeriod2.setBudgetPeriodSequenceNumber(period1
192: .getBudgetPeriodSequenceNumber());
193: taskPeriod2
194: .setAgencyRequestTotalAmount(new KualiInteger(43000));
195: taskPeriod2.setAgencyFringeBenefitTotalAmount(new KualiInteger(
196: 8500));
197: userAppointmentTaskPeriods.add(taskPeriod2);
198:
199: BudgetPeriod period2 = (BudgetPeriod) budget.getPeriods()
200: .get(1);
201:
202: UserAppointmentTaskPeriod taskPeriod3 = new UserAppointmentTaskPeriod();
203: taskPeriod3.setBudgetPeriodSequenceNumber(period2
204: .getBudgetPeriodSequenceNumber());
205: taskPeriod3
206: .setAgencyRequestTotalAmount(new KualiInteger(74000));
207: taskPeriod3.setAgencyFringeBenefitTotalAmount(new KualiInteger(
208: 21500));
209: userAppointmentTaskPeriods.add(taskPeriod3);
210:
211: budget
212: .setAllUserAppointmentTaskPeriods(userAppointmentTaskPeriods);
213:
214: }
215: }
|