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.web.struts.form;
017:
018: import java.util.ArrayList;
019: import java.util.List;
020:
021: import org.kuali.core.util.KualiInteger;
022: import org.kuali.kfs.context.KualiTestBase;
023: import org.kuali.module.kra.bo.BudgetNonpersonnelTest;
024: import org.kuali.module.kra.bo.BudgetPeriodTest;
025: import org.kuali.module.kra.budget.bo.BudgetInstitutionCostShare;
026: import org.kuali.module.kra.budget.bo.BudgetNonpersonnel;
027: import org.kuali.module.kra.budget.bo.BudgetPeriod;
028: import org.kuali.module.kra.budget.bo.BudgetPeriodInstitutionCostShare;
029: import org.kuali.module.kra.budget.bo.BudgetPeriodThirdPartyCostShare;
030: import org.kuali.module.kra.budget.bo.BudgetTaskPeriodIndirectCost;
031: import org.kuali.module.kra.budget.bo.BudgetThirdPartyCostShare;
032: import org.kuali.module.kra.budget.bo.BudgetUser;
033: import org.kuali.module.kra.budget.bo.InstitutionCostSharePersonnel;
034: import org.kuali.module.kra.budget.bo.UserAppointmentTask;
035: import org.kuali.module.kra.budget.bo.UserAppointmentTaskPeriod;
036: import org.kuali.module.kra.budget.web.struts.form.BudgetCostShareFormHelper;
037: import org.kuali.module.kra.budget.web.struts.form.BudgetIndirectCostFormHelper;
038: import org.kuali.test.ConfigureContext;
039:
040: /**
041: * This class tests methods in BudgetOverviewFormHelper.
042: */
043: @ConfigureContext
044: public class BudgetCostShareFormHelperTest extends KualiTestBase {
045:
046: List<BudgetPeriod> periods;
047: List<BudgetUser> personnel;
048: List<BudgetNonpersonnel> budgetNonpersonnelItems;
049: List<InstitutionCostSharePersonnel> institutionCostSharePersonnel;
050: List<BudgetInstitutionCostShare> budgetInstitutionCostShare;
051: List<BudgetThirdPartyCostShare> budgetThirdPartyCostShare;
052: BudgetIndirectCostFormHelper budgetIndirectCostFormHelper;
053:
054: @Override
055: protected void setUp() throws Exception {
056: super .setUp();
057:
058: // Periods
059: periods = BudgetPeriodTest.createBudgetPeriods(2);
060:
061: // Personnel
062: personnel = new ArrayList();
063: BudgetUser budgetUser1 = new BudgetUser();
064: budgetUser1.setFiscalCampusCode("BL");
065: budgetUser1.setPrimaryDepartmentCode("CHEM");
066: UserAppointmentTask userAppointmentTask = new UserAppointmentTask();
067: UserAppointmentTaskPeriod userAppointmentTaskPeriod1 = new UserAppointmentTaskPeriod();
068: userAppointmentTaskPeriod1
069: .setInstitutionCostShareFringeBenefitTotalAmount(new KualiInteger(
070: 2500));
071: userAppointmentTaskPeriod1
072: .setInstitutionCostShareRequestTotalAmount(new KualiInteger(
073: 1500));
074: userAppointmentTaskPeriod1
075: .setBudgetPeriodSequenceNumber(new Integer(0));
076: UserAppointmentTaskPeriod userAppointmentTaskPeriod2 = new UserAppointmentTaskPeriod();
077: userAppointmentTaskPeriod2
078: .setInstitutionCostShareFringeBenefitTotalAmount(new KualiInteger(
079: 3500));
080: userAppointmentTaskPeriod2
081: .setInstitutionCostShareRequestTotalAmount(new KualiInteger(
082: 4500));
083: userAppointmentTaskPeriod2
084: .setBudgetPeriodSequenceNumber(new Integer(1));
085: List userAppointmentTaskPeriod = new ArrayList();
086: userAppointmentTaskPeriod.add(userAppointmentTaskPeriod1);
087: userAppointmentTaskPeriod.add(userAppointmentTaskPeriod2);
088: userAppointmentTask
089: .setUserAppointmentTaskPeriods(userAppointmentTaskPeriod);
090: List userAppointmentTasks = new ArrayList();
091: userAppointmentTasks.add(userAppointmentTask);
092: budgetUser1.setUserAppointmentTasks(userAppointmentTasks);
093: personnel.add(budgetUser1);
094:
095: // University Cost Share Personnel
096: institutionCostSharePersonnel = new ArrayList();
097: InstitutionCostSharePersonnel universityCostSharePersonnel1 = new InstitutionCostSharePersonnel();
098: universityCostSharePersonnel1.setChartOfAccountsCode("BL");
099: universityCostSharePersonnel1.setOrganizationCode("CHEM");
100: institutionCostSharePersonnel
101: .add(universityCostSharePersonnel1);
102:
103: // Nonpersonnel
104: String[] categories = { "CO", "CO", "SC", "SC" };
105: String[] subCategories = { "C1", "C1", "R3", "R1" };
106: String[] subcontractorNumber = { "", "", "1", "2" };
107: budgetNonpersonnelItems = BudgetNonpersonnelTest
108: .createBudgetNonpersonnel(categories, subCategories,
109: subcontractorNumber);
110:
111: // Budget University Cost Share
112: budgetInstitutionCostShare = new ArrayList();
113: BudgetInstitutionCostShare budgetUniversityCostShare1 = new BudgetInstitutionCostShare();
114: List budgetPeriodUniversityCostShare = new ArrayList();
115: BudgetPeriodInstitutionCostShare budgetPeriodUniversityCostShare1 = new BudgetPeriodInstitutionCostShare();
116: budgetPeriodUniversityCostShare1
117: .setBudgetCostShareAmount(new KualiInteger(1000));
118: budgetPeriodUniversityCostShare
119: .add(budgetPeriodUniversityCostShare1);
120: BudgetPeriodInstitutionCostShare budgetPeriodUniversityCostShare2 = new BudgetPeriodInstitutionCostShare();
121: budgetPeriodUniversityCostShare2
122: .setBudgetCostShareAmount(new KualiInteger(2000));
123: budgetPeriodUniversityCostShare
124: .add(budgetPeriodUniversityCostShare2);
125: budgetUniversityCostShare1
126: .setBudgetPeriodCostShare(budgetPeriodUniversityCostShare);
127: budgetInstitutionCostShare.add(budgetUniversityCostShare1);
128:
129: // Budget Third Party Cost Share
130: budgetThirdPartyCostShare = new ArrayList();
131: BudgetThirdPartyCostShare budgetThirdPartyCostShare1 = new BudgetThirdPartyCostShare();
132: List budgetPeriodThirdPartyCostShare = new ArrayList();
133: BudgetPeriodThirdPartyCostShare budgetPeriodThirdPartyCostShare1 = new BudgetPeriodThirdPartyCostShare();
134: budgetPeriodThirdPartyCostShare1
135: .setBudgetCostShareAmount(new KualiInteger(3000));
136: budgetPeriodThirdPartyCostShare
137: .add(budgetPeriodThirdPartyCostShare1);
138: BudgetPeriodThirdPartyCostShare budgetPeriodThirdPartyCostShare2 = new BudgetPeriodThirdPartyCostShare();
139: budgetPeriodThirdPartyCostShare2
140: .setBudgetCostShareAmount(new KualiInteger(4000));
141: budgetPeriodThirdPartyCostShare
142: .add(budgetPeriodThirdPartyCostShare2);
143: budgetThirdPartyCostShare1
144: .setBudgetPeriodCostShare(budgetPeriodThirdPartyCostShare);
145: budgetThirdPartyCostShare.add(budgetThirdPartyCostShare1);
146:
147: // Budget Indirect Cost
148: budgetIndirectCostFormHelper = new BudgetIndirectCostFormHelper();
149: List periodTotalsList = new ArrayList();
150: BudgetTaskPeriodIndirectCost idcPeriod0Exist = new BudgetTaskPeriodIndirectCost();
151: idcPeriod0Exist
152: .setCostShareCalculatedIndirectCost(new KualiInteger(
153: 300));
154: idcPeriod0Exist
155: .setCostShareUnrecoveredIndirectCost(new KualiInteger(
156: 200));
157: periodTotalsList.add(idcPeriod0Exist);
158: BudgetTaskPeriodIndirectCost idcPeriod1Exist = new BudgetTaskPeriodIndirectCost();
159: idcPeriod1Exist
160: .setCostShareCalculatedIndirectCost(new KualiInteger(
161: 100));
162: idcPeriod1Exist
163: .setCostShareUnrecoveredIndirectCost(new KualiInteger(
164: 100));
165: periodTotalsList.add(idcPeriod1Exist);
166: budgetIndirectCostFormHelper.setPeriodTotals(periodTotalsList);
167: }
168:
169: public void testBudgetCostShareFormHelper() {
170: BudgetCostShareFormHelper budgetCostShareFormHelper = new BudgetCostShareFormHelper(
171: periods, personnel, budgetNonpersonnelItems,
172: institutionCostSharePersonnel,
173: budgetInstitutionCostShare, budgetThirdPartyCostShare,
174: budgetIndirectCostFormHelper);
175:
176: testSetupInstitutionDirect(budgetCostShareFormHelper
177: .getInstitutionDirect());
178:
179: testSetupThirdPartyDirect(budgetCostShareFormHelper
180: .getThirdPartyDirect());
181:
182: testSetupSubcontractors(budgetCostShareFormHelper);
183:
184: testSetupTotals(budgetCostShareFormHelper);
185: }
186:
187: private void testSetupInstitutionDirect(
188: BudgetCostShareFormHelper.Direct institutionDirect) {
189: assertEquals("institutionDirect.getTotalBudgeted()[0] = 12000",
190: institutionDirect.getTotalBudgeted()[0],
191: new KualiInteger(12000));
192: assertEquals("institutionDirect.getTotalBudgeted()[1] = 8000",
193: institutionDirect.getTotalBudgeted()[1],
194: new KualiInteger(8000));
195: assertEquals(
196: "institutionDirect.getAmountDistributed()[0] = 5000",
197: institutionDirect.getAmountDistributed()[0],
198: new KualiInteger(5000));
199: assertEquals(
200: "institutionDirect.getAmountDistributed()[1] = 10000",
201: institutionDirect.getAmountDistributed()[1],
202: new KualiInteger(10000));
203: assertEquals(
204: "institutionDirect.getBalanceToBeDistributed()[0] = 7000",
205: institutionDirect.getBalanceToBeDistributed()[0],
206: new KualiInteger(7000));
207: assertEquals(
208: "institutionDirect.getBalanceToBeDistributed()[1] = -2000",
209: institutionDirect.getBalanceToBeDistributed()[1],
210: new KualiInteger(-2000));
211:
212: assertEquals(
213: "institutionDirect.getTotalTotalBudgeted()[0] = 20000",
214: institutionDirect.getTotalTotalBudgeted(),
215: new KualiInteger(20000));
216: assertEquals(
217: "institutionDirect.getTotalAmountDistributed() = 15000",
218: institutionDirect.getTotalAmountDistributed(),
219: new KualiInteger(15000));
220: assertEquals(
221: "institutionDirect.getTotalBalanceToBeDistributed() = 5000",
222: institutionDirect.getTotalBalanceToBeDistributed(),
223: new KualiInteger(5000));
224:
225: assertEquals("institutionDirect.getTotalSource()[0] = 3000",
226: institutionDirect.getTotalSource()[0],
227: new KualiInteger(3000));
228:
229: assertEquals(
230: "institutionDirect.getInstitutionDirectPersonnel()[0][0] = 4000",
231: institutionDirect.getInstitutionDirectPersonnel()[0][0],
232: new KualiInteger(4000));
233: assertEquals(
234: "institutionDirect.getInstitutionDirectPersonnel()[0][1] = 8000",
235: institutionDirect.getInstitutionDirectPersonnel()[0][1],
236: new KualiInteger(8000));
237: assertEquals(
238: "institutionDirect.getTotalInstitutionDirectPersonnel()[0] = 12000",
239: institutionDirect.getTotalInstitutionDirectPersonnel()[0],
240: new KualiInteger(12000));
241: }
242:
243: private void testSetupThirdPartyDirect(
244: BudgetCostShareFormHelper.Direct thirdPartyDirect) {
245: assertEquals("thirdPartyDirect.getTotalBudgeted()[0] = 12000",
246: thirdPartyDirect.getTotalBudgeted()[0],
247: new KualiInteger(12000));
248: assertEquals(
249: "thirdPartyDirect.getAmountDistributed()[0] = 9000",
250: thirdPartyDirect.getAmountDistributed()[0],
251: new KualiInteger(9000));
252: assertEquals(
253: "thirdPartyDirect.getBalanceToBeDistributed()[0] = 3000",
254: thirdPartyDirect.getBalanceToBeDistributed()[0],
255: new KualiInteger(3000));
256:
257: assertEquals(
258: "thirdPartyDirect.getTotalTotalBudgeted()[0] = 12000",
259: thirdPartyDirect.getTotalTotalBudgeted(),
260: new KualiInteger(12000));
261: assertEquals(
262: "thirdPartyDirect.getTotalAmountDistributed()[0] = 13000",
263: thirdPartyDirect.getTotalAmountDistributed(),
264: new KualiInteger(13000));
265: assertEquals(
266: "thirdPartyDirect.getTotalBalanceToBeDistributed()[0] = -1000",
267: thirdPartyDirect.getTotalBalanceToBeDistributed(),
268: new KualiInteger(-1000));
269:
270: assertEquals("thirdPartyDirect.getTotalSource()[0] = 7000",
271: thirdPartyDirect.getTotalSource()[0], new KualiInteger(
272: 7000));
273: }
274:
275: private void testSetupSubcontractors(
276: BudgetCostShareFormHelper budgetCostShareFormHelper) {
277: List<BudgetCostShareFormHelper.Subcontractor> subcontractors = budgetCostShareFormHelper
278: .getSubcontractors();
279:
280: assertTrue("subcontractors.size() == 2",
281: subcontractors.size() == 2);
282:
283: for (BudgetCostShareFormHelper.Subcontractor subcontractor : subcontractors) {
284: assertEquals("totalPeriodAmount = 3000", subcontractor
285: .getTotalPeriodAmount(), new KualiInteger(3000));
286:
287: KualiInteger[] periodAmounts = subcontractor
288: .getPeriodAmounts();
289: assertEquals("periodAmounts[0] = 3000", periodAmounts[0],
290: new KualiInteger(3000));
291: assertEquals("periodAmounts[1] = 0", periodAmounts[1],
292: new KualiInteger(0));
293: }
294:
295: // This test does not do any aggregation (hit Subcontractor.addPeriodAmount). That is not very good but in the
296: // interest of time I'm omitting that. BudgetNonpersonnelCopyOverFormHelperTest could possibly be used for that
297: // although it wouldn't be trivial...
298: }
299:
300: private void testSetupTotals(
301: BudgetCostShareFormHelper budgetCostShareFormHelper) {
302: assertEquals("institutionIndirectCostShare[0] = 500",
303: budgetCostShareFormHelper
304: .getInstitutionIndirectCostShare()[0],
305: new KualiInteger(500));
306: assertEquals("institutionIndirectCostShare[1] = 200",
307: budgetCostShareFormHelper
308: .getInstitutionIndirectCostShare()[1],
309: new KualiInteger(200));
310: assertEquals("total[0] = 20500", budgetCostShareFormHelper
311: .getTotal()[0], new KualiInteger(20500));
312: assertEquals("total[1] = 14200", budgetCostShareFormHelper
313: .getTotal()[1], new KualiInteger(14200));
314:
315: assertEquals("totalInstitutionIndirectCostShare = 700",
316: budgetCostShareFormHelper
317: .getTotalInstitutionIndirectCostShare(),
318: new KualiInteger(700));
319: assertEquals("totalTotal = 34700", budgetCostShareFormHelper
320: .getTotalTotal(), new KualiInteger(34700));
321: }
322: }
|