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 static org.kuali.test.util.KualiTestAssertionUtils.assertEquality;
019:
020: import org.kuali.core.util.KualiDecimal;
021: import org.kuali.core.util.KualiInteger;
022: import org.kuali.kfs.context.KualiTestBase;
023: import org.kuali.module.kra.budget.bo.BudgetNonpersonnel;
024: import org.kuali.module.kra.budget.web.struts.form.BudgetNonpersonnelCopyOverBoHelper;
025: import org.kuali.test.ConfigureContext;
026:
027: /**
028: * This class tests methods in BudgetNonpersonnelCopyOverBoHelper.
029: */
030: @ConfigureContext
031: public class BudgetNonpersonnelCopyOverBoHelperTest extends
032: KualiTestBase {
033:
034: public void testBudgetNonpersonnelCopyOverBoHelper() {
035: // BudgetNonpersonnelCopyOverBoHelper()
036: BudgetNonpersonnelCopyOverBoHelper budgetNonpersonnel = new BudgetNonpersonnelCopyOverBoHelper();
037: assertEquality(budgetNonpersonnel
038: .getBudgetNonpersonnelSequenceNumber(), new Integer(-1));
039:
040: // //** BudgetNonpersonnelCopyOverBoHelper(BudgetNonpersonnel budgetNonpersonnel)
041: budgetNonpersonnel = createBudgetNonpersonnelCopyOverBoHelper();
042:
043: // indicators not changed when copyToFuturePeriods false
044: budgetNonpersonnel.setCopyToFuturePeriods(false);
045: budgetNonpersonnel.setAgencyCopyIndicator(false);
046: budgetNonpersonnel
047: .setBudgetInstitutionCostShareCopyIndicator(false);
048: budgetNonpersonnel
049: .setBudgetThirdPartyCostShareCopyIndicator(false);
050: BudgetNonpersonnelCopyOverBoHelper newBudgetNonpersonnel1 = new BudgetNonpersonnelCopyOverBoHelper(
051: budgetNonpersonnel);
052: assertFalse(newBudgetNonpersonnel1.getAgencyCopyIndicator());
053: assertFalse(newBudgetNonpersonnel1
054: .getBudgetInstitutionCostShareCopyIndicator());
055: assertFalse(newBudgetNonpersonnel1
056: .getBudgetThirdPartyCostShareCopyIndicator());
057:
058: // indicators changed when copyToFuturePeriods true
059: budgetNonpersonnel.setCopyToFuturePeriods(true);
060: newBudgetNonpersonnel1 = new BudgetNonpersonnelCopyOverBoHelper(
061: budgetNonpersonnel);
062: assertTrue(newBudgetNonpersonnel1.getAgencyCopyIndicator());
063: assertTrue(newBudgetNonpersonnel1
064: .getBudgetInstitutionCostShareCopyIndicator());
065: assertTrue(newBudgetNonpersonnel1
066: .getBudgetThirdPartyCostShareCopyIndicator());
067:
068: // inflation values equal to non inflation values
069: assertEquality(newBudgetNonpersonnel1
070: .getBudgetInflatedAgencyAmount(),
071: new KualiInteger(1000));
072: assertEquality(newBudgetNonpersonnel1
073: .getBudgetInflatedInstitutionCostShareAmount(),
074: new KualiInteger(2000));
075: assertEquality(newBudgetNonpersonnel1
076: .getBudgetInflatedThirdPartyCostShareAmount(),
077: new KualiInteger(3000));
078:
079: // //** BudgetNonpersonnelCopyOverBoHelper(BudgetNonpersonnel budgetNonpersonnel, int inflationLength, KualiDecimal
080: // budgetNonpersonnelInflationRate)
081: budgetNonpersonnel = createBudgetNonpersonnelCopyOverBoHelper();
082:
083: // indicators false, don't modify amounts
084: budgetNonpersonnel.setAgencyCopyIndicator(false);
085: budgetNonpersonnel
086: .setBudgetInstitutionCostShareCopyIndicator(false);
087: budgetNonpersonnel
088: .setBudgetThirdPartyCostShareCopyIndicator(false);
089: BudgetNonpersonnelCopyOverBoHelper newBudgetNonpersonnel2 = new BudgetNonpersonnelCopyOverBoHelper(
090: budgetNonpersonnel, 5, new KualiDecimal(10.0));
091: assertEquality(newBudgetNonpersonnel2.getAgencyRequestAmount(),
092: new KualiInteger(1000));
093: assertEquality(newBudgetNonpersonnel2
094: .getBudgetInstitutionCostShareAmount(),
095: new KualiInteger(2000));
096: assertEquality(newBudgetNonpersonnel2
097: .getBudgetThirdPartyCostShareAmount(),
098: new KualiInteger(3000));
099:
100: // indicators true, set amounts to 0
101: budgetNonpersonnel.setAgencyCopyIndicator(true);
102: budgetNonpersonnel
103: .setBudgetInstitutionCostShareCopyIndicator(true);
104: budgetNonpersonnel
105: .setBudgetThirdPartyCostShareCopyIndicator(true);
106: newBudgetNonpersonnel2 = new BudgetNonpersonnelCopyOverBoHelper(
107: budgetNonpersonnel, 5, new KualiDecimal(10.0));
108: assertEquality(newBudgetNonpersonnel2.getAgencyRequestAmount(),
109: new KualiInteger(0));
110: assertEquality(newBudgetNonpersonnel2
111: .getBudgetInstitutionCostShareAmount(),
112: new KualiInteger(0));
113: assertEquality(newBudgetNonpersonnel2
114: .getBudgetThirdPartyCostShareAmount(),
115: new KualiInteger(0));
116:
117: // inflation over 5 periods, 10%
118: assertEquality(newBudgetNonpersonnel2
119: .getBudgetInflatedAgencyAmount(), new KualiInteger(
120: 11274));
121: assertEquality(newBudgetNonpersonnel2
122: .getBudgetInflatedInstitutionCostShareAmount(),
123: new KualiInteger(12884));
124: assertEquality(newBudgetNonpersonnel2
125: .getBudgetInflatedThirdPartyCostShareAmount(),
126: new KualiInteger(14495));
127:
128: // //** BudgetNonpersonnelCopyOverBoHelper(BudgetNonpersonnel originBudgetNonpersonnel, Integer
129: // budgetPeriodSequenceNumberOverride, int inflationLength, KualiDecimal budgetNonpersonnelInflationRate)
130: budgetNonpersonnel = createBudgetNonpersonnelCopyOverBoHelper();
131:
132: // indicators not changed when copyToFuturePeriods false
133: budgetNonpersonnel.setCopyToFuturePeriods(false);
134: budgetNonpersonnel.setAgencyCopyIndicator(false);
135: budgetNonpersonnel
136: .setBudgetInstitutionCostShareCopyIndicator(false);
137: budgetNonpersonnel
138: .setBudgetThirdPartyCostShareCopyIndicator(false);
139: BudgetNonpersonnelCopyOverBoHelper newBudgetNonpersonnel3 = new BudgetNonpersonnelCopyOverBoHelper(
140: budgetNonpersonnel, new Integer(11), 5,
141: new KualiDecimal(10.0));
142: assertFalse(newBudgetNonpersonnel3.getAgencyCopyIndicator());
143: assertFalse(newBudgetNonpersonnel3
144: .getBudgetInstitutionCostShareCopyIndicator());
145: assertFalse(newBudgetNonpersonnel3
146: .getBudgetThirdPartyCostShareCopyIndicator());
147:
148: // indicators changed when copyToFuturePeriods true
149: budgetNonpersonnel.setCopyToFuturePeriods(true);
150: newBudgetNonpersonnel3 = new BudgetNonpersonnelCopyOverBoHelper(
151: budgetNonpersonnel, new Integer(11), 5,
152: new KualiDecimal(10.0));
153: assertTrue(newBudgetNonpersonnel3.getAgencyCopyIndicator());
154: assertTrue(newBudgetNonpersonnel3
155: .getBudgetInstitutionCostShareCopyIndicator());
156: assertTrue(newBudgetNonpersonnel3
157: .getBudgetThirdPartyCostShareCopyIndicator());
158:
159: // budgetPeriodSequenceNumber = budgetPeriodSequenceNumberOverride
160: assertEquality(newBudgetNonpersonnel3
161: .getBudgetPeriodSequenceNumber(), new Integer(11));
162:
163: // amounts always set to 0
164: assertEquality(newBudgetNonpersonnel3.getAgencyRequestAmount(),
165: new KualiInteger(0));
166: assertEquality(newBudgetNonpersonnel3
167: .getBudgetInstitutionCostShareAmount(),
168: new KualiInteger(0));
169: assertEquality(newBudgetNonpersonnel3
170: .getBudgetThirdPartyCostShareAmount(),
171: new KualiInteger(0));
172:
173: // should be equal to the budgetNonpersonnelSequenceNumber
174: assertEquality(newBudgetNonpersonnel3
175: .getBudgetOriginSequenceNumber(), new Integer(173));
176:
177: // origin amounts should be equal to the amounts passed in
178: assertEquality(newBudgetNonpersonnel3
179: .getBudgetOriginAgencyAmount(), new KualiInteger(1000));
180: assertEquality(newBudgetNonpersonnel3
181: .getBudgetOriginInstitutionCostShareAmount(),
182: new KualiInteger(2000));
183: assertEquality(newBudgetNonpersonnel3
184: .getBudgetOriginThirdPartyCostShareAmount(),
185: new KualiInteger(3000));
186:
187: // budgetNonpersonnelSequenceNumber always null
188: assertNull(newBudgetNonpersonnel3
189: .getBudgetNonpersonnelSequenceNumber());
190:
191: // inflation over 5 periods, 10%
192: assertEquality(newBudgetNonpersonnel3
193: .getBudgetInflatedAgencyAmount(),
194: new KualiInteger(1611));
195: assertEquality(newBudgetNonpersonnel3
196: .getBudgetInflatedInstitutionCostShareAmount(),
197: new KualiInteger(3221));
198: assertEquality(newBudgetNonpersonnel3
199: .getBudgetInflatedThirdPartyCostShareAmount(),
200: new KualiInteger(4832));
201: }
202:
203: public void testGetBudgetNonpersonnel() {
204: BudgetNonpersonnelCopyOverBoHelper budgetNonpersonnel = createBudgetNonpersonnelCopyOverBoHelper();
205:
206: // agencyCopyIndicator = false
207: budgetNonpersonnel.setAgencyCopyIndicator(false);
208: budgetNonpersonnel
209: .setBudgetInstitutionCostShareCopyIndicator(false);
210: budgetNonpersonnel
211: .setBudgetThirdPartyCostShareCopyIndicator(false);
212: budgetNonpersonnel.setCopyToFuturePeriods(true);
213: BudgetNonpersonnel newBudgetNonpersonnel1 = budgetNonpersonnel
214: .getBudgetNonpersonnel();
215: assertEquality(newBudgetNonpersonnel1.getAgencyRequestAmount(),
216: new KualiInteger(1000));
217: assertEquality(newBudgetNonpersonnel1
218: .getBudgetInstitutionCostShareAmount(),
219: new KualiInteger(2000));
220: assertEquality(newBudgetNonpersonnel1
221: .getBudgetThirdPartyCostShareAmount(),
222: new KualiInteger(3000));
223: assertFalse(newBudgetNonpersonnel1.getCopyToFuturePeriods()); // should always be false per interface requirement
224:
225: // agencyCopyIndicator = true
226: budgetNonpersonnel.setAgencyCopyIndicator(true);
227: budgetNonpersonnel
228: .setBudgetInstitutionCostShareCopyIndicator(true);
229: budgetNonpersonnel
230: .setBudgetThirdPartyCostShareCopyIndicator(true);
231: budgetNonpersonnel.setCopyToFuturePeriods(false);
232: BudgetNonpersonnel newBudgetNonpersonnel2 = budgetNonpersonnel
233: .getBudgetNonpersonnel();
234: assertEquality(newBudgetNonpersonnel2.getAgencyRequestAmount(),
235: new KualiInteger(4000));
236: assertEquality(newBudgetNonpersonnel2
237: .getBudgetInstitutionCostShareAmount(),
238: new KualiInteger(5000));
239: assertEquality(newBudgetNonpersonnel2
240: .getBudgetThirdPartyCostShareAmount(),
241: new KualiInteger(6000));
242: assertFalse(newBudgetNonpersonnel2.getCopyToFuturePeriods()); // should always be false per interface requirement
243:
244: // KULERA-491 bug: getBudgetNonpersonnel doesn't return object of type gBudgetNonpersonnel which confused OJB.
245: boolean exceptionThrown = false;
246: try {
247: BudgetNonpersonnelCopyOverBoHelper newBudgetNonpersonnel3 = (BudgetNonpersonnelCopyOverBoHelper) budgetNonpersonnel
248: .getBudgetNonpersonnel();
249: } catch (ClassCastException e) {
250: exceptionThrown = true;
251: }
252: assertTrue(
253: "BudgetNonpersonnel.getBudgetNonpersonnel should not return an object of type BudgetNonpersonnelCopyOverBoHelper because "
254: + "that confuses OJB. It can only store BudgetNonpersonnel.",
255: exceptionThrown);
256: }
257:
258: /**
259: * Helper to give a representation of a re-occuring BudgetNonpersonnelCopyOverBoHelper object. Note this may not be a valid
260: * representation of how the object looks like in production. The reason for that is that it's easier to test if I fudge some of
261: * the data (ie. inflation amounts are not actually the inflated amounts, if they are it's harder for me to tell if they are
262: * indeed properly inflated).
263: *
264: * @return
265: */
266: private BudgetNonpersonnelCopyOverBoHelper createBudgetNonpersonnelCopyOverBoHelper() {
267: BudgetNonpersonnelCopyOverBoHelper budgetNonpersonnel = new BudgetNonpersonnelCopyOverBoHelper();
268:
269: budgetNonpersonnel
270: .setBudgetNonpersonnelSequenceNumber(new Integer(173));
271:
272: budgetNonpersonnel
273: .setAgencyRequestAmount(new KualiInteger(1000));
274: budgetNonpersonnel
275: .setBudgetInstitutionCostShareAmount(new KualiInteger(
276: 2000));
277: budgetNonpersonnel
278: .setBudgetThirdPartyCostShareAmount(new KualiInteger(
279: 3000));
280:
281: budgetNonpersonnel
282: .setBudgetInflatedAgencyAmount(new KualiInteger(4000));
283: budgetNonpersonnel
284: .setBudgetInflatedInstitutionCostShareAmount(new KualiInteger(
285: 5000));
286: budgetNonpersonnel
287: .setBudgetInflatedThirdPartyCostShareAmount(new KualiInteger(
288: 6000));
289:
290: budgetNonpersonnel
291: .setBudgetOriginAgencyAmount(new KualiInteger(7000));
292: budgetNonpersonnel
293: .setBudgetOriginInstitutionCostShareAmount(new KualiInteger(
294: 8000));
295: budgetNonpersonnel
296: .setBudgetOriginThirdPartyCostShareAmount(new KualiInteger(
297: 9000));
298:
299: budgetNonpersonnel.setAgencyCopyIndicator(false);
300: budgetNonpersonnel
301: .setBudgetInstitutionCostShareCopyIndicator(false);
302: budgetNonpersonnel
303: .setBudgetThirdPartyCostShareCopyIndicator(false);
304:
305: budgetNonpersonnel.setCopyToFuturePeriods(true);
306:
307: return budgetNonpersonnel;
308: }
309: }
|