001: /*
002: * Copyright 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.bo;
017:
018: import java.sql.Timestamp;
019:
020: import org.kuali.kfs.bo.AccountingLine;
021: import org.kuali.kfs.bo.AccountingLineOverride;
022: import org.kuali.kfs.bo.SourceAccountingLine;
023: import org.kuali.kfs.context.KualiTestBase;
024: import org.kuali.module.chart.bo.Account;
025: import org.kuali.test.ConfigureContext;
026:
027: /**
028: * This class tests AccountingLineOverride.
029: */
030: @ConfigureContext
031: public class AccountingLineOverrideTest extends KualiTestBase {
032: private static final AccountingLineOverride EXPIRED = AccountingLineOverride
033: .valueOf(AccountingLineOverride.CODE.EXPIRED_ACCOUNT);
034: private static final AccountingLineOverride NONE = AccountingLineOverride
035: .valueOf(AccountingLineOverride.CODE.NONE);
036: private static final AccountingLineOverride EXPIRED_AND_NON_FRINGE = AccountingLineOverride
037: .valueOf(AccountingLineOverride.CODE.EXPIRED_ACCOUNT_AND_NON_FRINGE_ACCOUNT_USED);
038: private static final AccountingLineOverride NON_FRINGE = AccountingLineOverride
039: .valueOf(AccountingLineOverride.CODE.NON_FRINGE_ACCOUNT_USED);
040:
041: public void testValueOf_String_none() {
042: AccountingLineOverride expired = AccountingLineOverride
043: .valueOf(AccountingLineOverride.CODE.NONE);
044: assertEquals(AccountingLineOverride.CODE.NONE, expired
045: .getCode());
046: assertEquals(
047: false,
048: expired
049: .hasComponent(AccountingLineOverride.COMPONENT.EXPIRED_ACCOUNT));
050: assertEquals(
051: false,
052: expired
053: .hasComponent(AccountingLineOverride.COMPONENT.NON_FRINGE_ACCOUNT_USED));
054: }
055:
056: public void testValueOf_String_expiredAccount() {
057: AccountingLineOverride expired = AccountingLineOverride
058: .valueOf(AccountingLineOverride.CODE.EXPIRED_ACCOUNT);
059: assertEquals(AccountingLineOverride.CODE.EXPIRED_ACCOUNT,
060: expired.getCode());
061: assertEquals(
062: true,
063: expired
064: .hasComponent(AccountingLineOverride.COMPONENT.EXPIRED_ACCOUNT));
065: assertEquals(
066: false,
067: expired
068: .hasComponent(AccountingLineOverride.COMPONENT.NON_FRINGE_ACCOUNT_USED));
069: }
070:
071: public void testValueOf_String_nonBudgetedObject() {
072: AccountingLineOverride expired = AccountingLineOverride
073: .valueOf(AccountingLineOverride.CODE.NON_BUDGETED_OBJECT);
074: assertEquals(AccountingLineOverride.CODE.NON_BUDGETED_OBJECT,
075: expired.getCode());
076: assertEquals(
077: false,
078: expired
079: .hasComponent(AccountingLineOverride.COMPONENT.EXPIRED_ACCOUNT));
080: assertEquals(
081: true,
082: expired
083: .hasComponent(AccountingLineOverride.COMPONENT.NON_BUDGETED_OBJECT));
084: }
085:
086: public void testValueOf_String_double() {
087: AccountingLineOverride expired = AccountingLineOverride
088: .valueOf(AccountingLineOverride.CODE.EXPIRED_ACCOUNT_AND_NON_FRINGE_ACCOUNT_USED);
089: assertEquals(
090: AccountingLineOverride.CODE.EXPIRED_ACCOUNT_AND_NON_FRINGE_ACCOUNT_USED,
091: expired.getCode());
092: assertEquals(
093: true,
094: expired
095: .hasComponent(AccountingLineOverride.COMPONENT.EXPIRED_ACCOUNT));
096: assertEquals(
097: true,
098: expired
099: .hasComponent(AccountingLineOverride.COMPONENT.NON_FRINGE_ACCOUNT_USED));
100: assertEquals(
101: false,
102: expired
103: .hasComponent(AccountingLineOverride.COMPONENT.NON_BUDGETED_OBJECT));
104: }
105:
106: public void testValueOf_String_invalid() {
107: try {
108: AccountingLineOverride.valueOf("foo");
109: fail("got invalid code");
110: } catch (IllegalArgumentException e) {
111: // good
112: }
113: }
114:
115: public void testValueOf_String_null() {
116: try {
117: AccountingLineOverride.valueOf((String) null);
118: fail("got null code");
119: } catch (IllegalArgumentException e) {
120: // good
121: }
122: }
123:
124: public void testValueOf_IntegerArray_none() {
125: AccountingLineOverride expired = AccountingLineOverride
126: .valueOf(new Integer[] {});
127: assertEquals(AccountingLineOverride.CODE.NONE, expired
128: .getCode());
129: assertEquals(
130: false,
131: expired
132: .hasComponent(AccountingLineOverride.COMPONENT.EXPIRED_ACCOUNT));
133: assertEquals(
134: false,
135: expired
136: .hasComponent(AccountingLineOverride.COMPONENT.NON_FRINGE_ACCOUNT_USED));
137: }
138:
139: public void testValueOf_IntegerArray_expiredAccount() {
140: AccountingLineOverride expired = AccountingLineOverride
141: .valueOf(new Integer[] { AccountingLineOverride.COMPONENT.EXPIRED_ACCOUNT });
142: assertEquals(AccountingLineOverride.CODE.EXPIRED_ACCOUNT,
143: expired.getCode());
144: assertEquals(
145: true,
146: expired
147: .hasComponent(AccountingLineOverride.COMPONENT.EXPIRED_ACCOUNT));
148: assertEquals(
149: false,
150: expired
151: .hasComponent(AccountingLineOverride.COMPONENT.NON_FRINGE_ACCOUNT_USED));
152: }
153:
154: public void testValueOf_IntegerArray_double() {
155: AccountingLineOverride expired = AccountingLineOverride
156: .valueOf(new Integer[] {
157: AccountingLineOverride.COMPONENT.EXPIRED_ACCOUNT,
158: AccountingLineOverride.COMPONENT.NON_FRINGE_ACCOUNT_USED });
159: assertEquals(
160: AccountingLineOverride.CODE.EXPIRED_ACCOUNT_AND_NON_FRINGE_ACCOUNT_USED,
161: expired.getCode());
162: assertEquals(
163: true,
164: expired
165: .hasComponent(AccountingLineOverride.COMPONENT.EXPIRED_ACCOUNT));
166: assertEquals(
167: true,
168: expired
169: .hasComponent(AccountingLineOverride.COMPONENT.NON_FRINGE_ACCOUNT_USED));
170: assertEquals(
171: false,
172: expired
173: .hasComponent(AccountingLineOverride.COMPONENT.NON_BUDGETED_OBJECT));
174: }
175:
176: public void testValueOf_IntegerArray_doubleReverse() {
177: AccountingLineOverride expired = AccountingLineOverride
178: .valueOf(new Integer[] {
179: AccountingLineOverride.COMPONENT.NON_FRINGE_ACCOUNT_USED,
180: AccountingLineOverride.COMPONENT.EXPIRED_ACCOUNT });
181: assertEquals(
182: AccountingLineOverride.CODE.EXPIRED_ACCOUNT_AND_NON_FRINGE_ACCOUNT_USED,
183: expired.getCode());
184: assertEquals(
185: true,
186: expired
187: .hasComponent(AccountingLineOverride.COMPONENT.EXPIRED_ACCOUNT));
188: assertEquals(
189: true,
190: expired
191: .hasComponent(AccountingLineOverride.COMPONENT.NON_FRINGE_ACCOUNT_USED));
192: assertEquals(
193: false,
194: expired
195: .hasComponent(AccountingLineOverride.COMPONENT.NON_BUDGETED_OBJECT));
196: }
197:
198: public void testValueOf_IntegerArray_invalid() {
199: try {
200: AccountingLineOverride
201: .valueOf(new Integer[] {
202: AccountingLineOverride.COMPONENT.NON_BUDGETED_OBJECT,
203: AccountingLineOverride.COMPONENT.NON_FRINGE_ACCOUNT_USED });
204: fail("got invalid components");
205: } catch (IllegalArgumentException e) {
206: // good
207: }
208: }
209:
210: public void testValueOf_IntegerArray_null() {
211: try {
212: AccountingLineOverride.valueOf((Integer[]) null);
213: fail("got null components");
214: } catch (NullPointerException e) {
215: // good
216: }
217: }
218:
219: public void testIsValidCode_valid() {
220: assertEquals(
221: true,
222: AccountingLineOverride
223: .isValidCode(AccountingLineOverride.CODE.EXPIRED_ACCOUNT_AND_NON_BUDGETED_OBJECT));
224: }
225:
226: public void testIsValidCode_invalid() {
227: assertEquals(false, AccountingLineOverride.isValidCode("foo"));
228: }
229:
230: public void testIsValidCode_empty() {
231: assertEquals(false, AccountingLineOverride.isValidCode(""));
232: }
233:
234: public void testIsValidCode_blank() {
235: assertEquals(false, AccountingLineOverride.isValidCode(" "));
236: }
237:
238: public void testIsValidCode_null() {
239: assertEquals(false, AccountingLineOverride.isValidCode(null));
240: }
241:
242: public void testIsValidComponentSet_valid() {
243: assertEquals(
244: true,
245: AccountingLineOverride
246: .isValidComponentSet(new Integer[] {
247: AccountingLineOverride.COMPONENT.EXPIRED_ACCOUNT,
248: AccountingLineOverride.COMPONENT.NON_BUDGETED_OBJECT }));
249: }
250:
251: public void testIsValidComponentSet_invalid() {
252: assertEquals(false, AccountingLineOverride
253: .isValidComponentSet(new Integer[] { new Integer(4) }));
254: }
255:
256: public void testIsValidComponentSet_empty() {
257: assertEquals(true, AccountingLineOverride
258: .isValidComponentSet(new Integer[] {}));
259: }
260:
261: public void testIsValidComponentSet_null() {
262: try {
263: AccountingLineOverride.isValidComponentSet(null);
264: fail("null valid check didn't throw an exception");
265: } catch (NullPointerException e) {
266: // good
267: }
268: }
269:
270: public void testMask_expiredToNone() {
271: assertSame(NONE, EXPIRED.mask(NONE));
272: }
273:
274: public void testMask_noneToExpired() {
275: assertSame(NONE, NONE.mask(EXPIRED));
276: }
277:
278: public void testMask_expiredAndNonFringeToExpired() {
279: assertSame(EXPIRED, EXPIRED_AND_NON_FRINGE.mask(EXPIRED));
280: }
281:
282: public void testMask_nonFringeToExpired() {
283: assertSame(NONE, NON_FRINGE.mask(EXPIRED));
284: }
285:
286: public void testPopulateFromInput_none() {
287: AccountingLine line = new SourceAccountingLine();
288: assertEquals(AccountingLineOverride.CODE.NONE, line
289: .getOverrideCode());
290: AccountingLineOverride.populateFromInput(line);
291: assertEquals(AccountingLineOverride.CODE.NONE, line
292: .getOverrideCode());
293: }
294:
295: public void testPopulateFromInput_expiredAccount() {
296: AccountingLine line = new SourceAccountingLine();
297: line.setAccountExpiredOverride(true);
298: assertEquals(AccountingLineOverride.CODE.NONE, line
299: .getOverrideCode());
300: AccountingLineOverride.populateFromInput(line);
301: assertEquals(AccountingLineOverride.CODE.EXPIRED_ACCOUNT, line
302: .getOverrideCode());
303: }
304:
305: public void testPopulateFromInput_nonBudgetedObject() {
306: AccountingLine line = new SourceAccountingLine();
307: line.setObjectBudgetOverride(true);
308: assertEquals(AccountingLineOverride.CODE.NONE, line
309: .getOverrideCode());
310: AccountingLineOverride.populateFromInput(line);
311: assertEquals(AccountingLineOverride.CODE.NON_BUDGETED_OBJECT,
312: line.getOverrideCode());
313: }
314:
315: public void testProcessForOutput_none() {
316: AccountingLine line = new SourceAccountingLine();
317: assertEquals(AccountingLineOverride.CODE.NONE, line
318: .getOverrideCode());
319: assertEquals(false, line.getAccountExpiredOverride());
320: assertEquals(false, line.getAccountExpiredOverrideNeeded());
321: AccountingLineOverride.processForOutput(line);
322: assertEquals(false, line.getAccountExpiredOverride());
323: assertEquals(false, line.getAccountExpiredOverrideNeeded());
324: assertEquals(AccountingLineOverride.CODE.NONE, line
325: .getOverrideCode());
326: }
327:
328: @SuppressWarnings("deprecation")
329: public void testProcessForOutput_unexpired() {
330: AccountingLine line = new SourceAccountingLine();
331: line.setAccount(getUnexpiredAccount());
332: assertEquals(AccountingLineOverride.CODE.NONE, line
333: .getOverrideCode());
334: assertEquals(false, line.getAccountExpiredOverride());
335: assertEquals(false, line.getAccountExpiredOverrideNeeded());
336: AccountingLineOverride.processForOutput(line);
337: assertEquals(false, line.getAccountExpiredOverride());
338: assertEquals(false, line.getAccountExpiredOverrideNeeded());
339: assertEquals(AccountingLineOverride.CODE.NONE, line
340: .getOverrideCode());
341: }
342:
343: @SuppressWarnings("deprecation")
344: public void testProcessForOutput_expired() {
345: AccountingLine line = new SourceAccountingLine();
346: line
347: .setOverrideCode(AccountingLineOverride.CODE.EXPIRED_ACCOUNT);
348: line.setAccount(getExpiredAccount());
349: assertEquals(false, line.getAccountExpiredOverride());
350: assertEquals(false, line.getAccountExpiredOverrideNeeded());
351: AccountingLineOverride.processForOutput(line);
352: assertEquals(true, line.getAccountExpiredOverride());
353: assertEquals(true, line.getAccountExpiredOverrideNeeded());
354: assertEquals(AccountingLineOverride.CODE.EXPIRED_ACCOUNT, line
355: .getOverrideCode());
356: }
357:
358: @SuppressWarnings("deprecation")
359: public void testProcessForOutput_nonBudgetedObject() {
360: AccountingLine line = new SourceAccountingLine();
361: line.setAccount(getClosedAccount());
362: assertEquals(AccountingLineOverride.CODE.NONE, line
363: .getOverrideCode());
364: assertEquals(false, line.getAccountExpiredOverride());
365: assertEquals(false, line.getAccountExpiredOverrideNeeded());
366: AccountingLineOverride.processForOutput(line);
367: assertEquals(false, line.getAccountExpiredOverride());
368: assertEquals(false, line.getAccountExpiredOverrideNeeded());
369: assertEquals(AccountingLineOverride.CODE.NONE, line
370: .getOverrideCode());
371: }
372:
373: @SuppressWarnings("deprecation")
374: public void testProcessForOutput_alreadyExpired() {
375: AccountingLine line = new SourceAccountingLine();
376: line
377: .setOverrideCode(AccountingLineOverride.CODE.EXPIRED_ACCOUNT);
378: line.setAccount(getExpiredAccount());
379: line.setAccountExpiredOverride(true);
380: line.setAccountExpiredOverrideNeeded(true);
381: AccountingLineOverride.processForOutput(line);
382: assertEquals(true, line.getAccountExpiredOverride());
383: assertEquals(true, line.getAccountExpiredOverrideNeeded());
384: assertEquals(AccountingLineOverride.CODE.EXPIRED_ACCOUNT, line
385: .getOverrideCode());
386: }
387:
388: @SuppressWarnings("deprecation")
389: public void testProcessForOutput_becomingExpired() {
390: AccountingLine line = new SourceAccountingLine();
391: line.setAccount(getExpiredAccount());
392: assertEquals(AccountingLineOverride.CODE.NONE, line
393: .getOverrideCode());
394: assertEquals(false, line.getAccountExpiredOverride());
395: assertEquals(false, line.getAccountExpiredOverrideNeeded());
396: AccountingLineOverride.processForOutput(line);
397: assertEquals(false, line.getAccountExpiredOverride());
398: assertEquals(true, line.getAccountExpiredOverrideNeeded());
399: assertEquals(AccountingLineOverride.CODE.NONE, line
400: .getOverrideCode());
401: }
402:
403: @SuppressWarnings("deprecation")
404: public void testProcessForOutput_becomingUnexpired() {
405: AccountingLine line = new SourceAccountingLine();
406: line
407: .setOverrideCode(AccountingLineOverride.CODE.EXPIRED_ACCOUNT);
408: line.setAccount(getUnexpiredAccount());
409: line.setAccountExpiredOverride(true);
410: line.setAccountExpiredOverrideNeeded(true);
411: AccountingLineOverride.processForOutput(line);
412: assertEquals(true, line.getAccountExpiredOverride());
413: assertEquals(false, line.getAccountExpiredOverrideNeeded());
414: assertEquals(AccountingLineOverride.CODE.EXPIRED_ACCOUNT, line
415: .getOverrideCode());
416: }
417:
418: @SuppressWarnings("deprecation")
419: public void testProcessForOutput_becomingClosed() {
420: AccountingLine line = new SourceAccountingLine();
421: line.setAccount(getClosedAccount());
422: assertEquals(AccountingLineOverride.CODE.NONE, line
423: .getOverrideCode());
424: assertEquals(false, line.getAccountExpiredOverride());
425: assertEquals(false, line.getAccountExpiredOverrideNeeded());
426: AccountingLineOverride.processForOutput(line);
427: assertEquals(false, line.getAccountExpiredOverride());
428: assertEquals(false, line.getAccountExpiredOverrideNeeded());
429: assertEquals(AccountingLineOverride.CODE.NONE, line
430: .getOverrideCode());
431: }
432:
433: private Account getClosedAccount() {
434: Account account = getExpiredAccount();
435: account.setAccountClosedIndicator(true);
436: return account;
437: }
438:
439: private Account getExpiredAccount() {
440: Account account = new Account();
441: account.setAccountExpirationDate(new Timestamp(42)); // this account expired near the beginning of the era (1970)
442: return account;
443: }
444:
445: private Account getUnexpiredAccount() {
446: Account account = new Account();
447: account.setAccountExpirationDate(new Timestamp(
448: Long.MAX_VALUE / 2)); // this account expires far in the future
449: return account;
450: }
451: }
|