001: /*
002: * Copyright 2005-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.financial.rules;
017:
018: import static org.kuali.module.financial.rules.AccountingDocumentRuleTestUtils.testAddAccountingLineRule_IsObjectCodeAllowed;
019: import static org.kuali.module.financial.rules.AccountingDocumentRuleTestUtils.testAddAccountingLineRule_IsObjectTypeAllowed;
020: import static org.kuali.module.financial.rules.AccountingDocumentRuleTestUtils.testAddAccountingLineRule_ProcessAddAccountingLineBusinessRules;
021: import static org.kuali.module.financial.rules.AccountingDocumentRuleTestUtils.testAddAccountingLine_IsObjectSubTypeAllowed;
022: import static org.kuali.module.financial.rules.AccountingDocumentRuleTestUtils.testRouteDocumentRule_processRouteDocument;
023: import static org.kuali.module.financial.rules.AccountingDocumentRuleTestUtils.testSaveDocumentRule_ProcessSaveDocument;
024: import static org.kuali.module.financial.rules.IsDebitTestUtils.Amount.NEGATIVE;
025: import static org.kuali.module.financial.rules.IsDebitTestUtils.Amount.POSITIVE;
026: import static org.kuali.test.fixtures.AccountingLineFixture.ACCRUED_INCOME_LINE;
027: import static org.kuali.test.fixtures.AccountingLineFixture.ACCRUED_SICK_PAY_LINE;
028: import static org.kuali.test.fixtures.AccountingLineFixture.LINE10;
029: import static org.kuali.test.fixtures.AccountingLineFixture.LINE8;
030: import static org.kuali.test.fixtures.UserNameFixture.KHUNTLEY;
031:
032: import java.util.ArrayList;
033: import java.util.List;
034:
035: import org.kuali.core.service.DataDictionaryService;
036: import org.kuali.core.service.DocumentService;
037: import org.kuali.core.service.DocumentTypeService;
038: import org.kuali.core.util.KualiDecimal;
039: import org.kuali.kfs.KFSConstants;
040: import org.kuali.kfs.bo.AccountingLine;
041: import org.kuali.kfs.bo.SourceAccountingLine;
042: import org.kuali.kfs.bo.TargetAccountingLine;
043: import org.kuali.kfs.context.KualiTestBase;
044: import org.kuali.kfs.context.SpringContext;
045: import org.kuali.kfs.document.AccountingDocument;
046: import org.kuali.module.financial.document.NonCheckDisbursementDocument;
047: import org.kuali.test.ConfigureContext;
048: import org.kuali.test.DocumentTestUtils;
049:
050: @ConfigureContext(session=KHUNTLEY)
051: public class NonCheckDisbursementDocumentRuleTest extends KualiTestBase {
052: public static final Class<NonCheckDisbursementDocument> DOCUMENT_CLASS = NonCheckDisbursementDocument.class;
053:
054: public void testIsDebit_income_positveAmount() throws Exception {
055: AccountingDocument accountingDocument = IsDebitTestUtils
056: .getDocument(SpringContext
057: .getBean(DocumentService.class),
058: NonCheckDisbursementDocument.class);
059: AccountingLine accountingLine = IsDebitTestUtils.getIncomeLine(
060: accountingDocument, SourceAccountingLine.class,
061: POSITIVE);
062:
063: assertTrue(IsDebitTestUtils.isDebit(SpringContext
064: .getBean(DocumentTypeService.class), SpringContext
065: .getBean(DataDictionaryService.class),
066: accountingDocument, accountingLine));
067: }
068:
069: public void testIsDebit_income_negativeAmount() throws Exception {
070: AccountingDocument accountingDocument = IsDebitTestUtils
071: .getDocument(SpringContext
072: .getBean(DocumentService.class),
073: NonCheckDisbursementDocument.class);
074: AccountingLine accountingLine = IsDebitTestUtils.getIncomeLine(
075: accountingDocument, SourceAccountingLine.class,
076: NEGATIVE);
077:
078: assertTrue(IsDebitTestUtils.isDebitIllegalStateException(
079: SpringContext.getBean(DocumentTypeService.class),
080: SpringContext.getBean(DataDictionaryService.class),
081: accountingDocument, accountingLine));
082: }
083:
084: public void testIsDebit_income_zeroAmount() throws Exception {
085: AccountingDocument accountingDocument = IsDebitTestUtils
086: .getDocument(SpringContext
087: .getBean(DocumentService.class),
088: NonCheckDisbursementDocument.class);
089: AccountingLine accountingLine = IsDebitTestUtils.getIncomeLine(
090: accountingDocument, SourceAccountingLine.class,
091: KualiDecimal.ZERO);
092:
093: assertTrue(IsDebitTestUtils.isDebitIllegalStateException(
094: SpringContext.getBean(DocumentTypeService.class),
095: SpringContext.getBean(DataDictionaryService.class),
096: accountingDocument, accountingLine));
097: }
098:
099: public void testIsDebit_expense_positveAmount() throws Exception {
100: AccountingDocument accountingDocument = IsDebitTestUtils
101: .getDocument(SpringContext
102: .getBean(DocumentService.class),
103: NonCheckDisbursementDocument.class);
104: AccountingLine accountingLine = IsDebitTestUtils
105: .getExpenseLine(accountingDocument,
106: SourceAccountingLine.class, POSITIVE);
107:
108: assertTrue(IsDebitTestUtils.isDebit(SpringContext
109: .getBean(DocumentTypeService.class), SpringContext
110: .getBean(DataDictionaryService.class),
111: accountingDocument, accountingLine));
112: }
113:
114: public void testIsDebit_expense_negativeAmount() throws Exception {
115: AccountingDocument accountingDocument = IsDebitTestUtils
116: .getDocument(SpringContext
117: .getBean(DocumentService.class),
118: NonCheckDisbursementDocument.class);
119: AccountingLine accountingLine = IsDebitTestUtils
120: .getExpenseLine(accountingDocument,
121: SourceAccountingLine.class, NEGATIVE);
122:
123: assertTrue(IsDebitTestUtils.isDebitIllegalStateException(
124: SpringContext.getBean(DocumentTypeService.class),
125: SpringContext.getBean(DataDictionaryService.class),
126: accountingDocument, accountingLine));
127: }
128:
129: public void testIsDebit_expense_zeroAmount() throws Exception {
130: AccountingDocument accountingDocument = IsDebitTestUtils
131: .getDocument(SpringContext
132: .getBean(DocumentService.class),
133: NonCheckDisbursementDocument.class);
134: AccountingLine accountingLine = IsDebitTestUtils
135: .getExpenseLine(accountingDocument,
136: SourceAccountingLine.class, KualiDecimal.ZERO);
137:
138: assertTrue(IsDebitTestUtils.isDebitIllegalStateException(
139: SpringContext.getBean(DocumentTypeService.class),
140: SpringContext.getBean(DataDictionaryService.class),
141: accountingDocument, accountingLine));
142: }
143:
144: public void testIsDebit_asset_positveAmount() throws Exception {
145: AccountingDocument accountingDocument = IsDebitTestUtils
146: .getDocument(SpringContext
147: .getBean(DocumentService.class),
148: NonCheckDisbursementDocument.class);
149: AccountingLine accountingLine = IsDebitTestUtils.getAssetLine(
150: accountingDocument, SourceAccountingLine.class,
151: POSITIVE);
152:
153: assertTrue(IsDebitTestUtils.isDebit(SpringContext
154: .getBean(DocumentTypeService.class), SpringContext
155: .getBean(DataDictionaryService.class),
156: accountingDocument, accountingLine));
157: }
158:
159: public void testIsDebit_asset_negativeAmount() throws Exception {
160: AccountingDocument accountingDocument = IsDebitTestUtils
161: .getDocument(SpringContext
162: .getBean(DocumentService.class),
163: NonCheckDisbursementDocument.class);
164: AccountingLine accountingLine = IsDebitTestUtils.getAssetLine(
165: accountingDocument, SourceAccountingLine.class,
166: NEGATIVE);
167:
168: assertTrue(IsDebitTestUtils.isDebitIllegalStateException(
169: SpringContext.getBean(DocumentTypeService.class),
170: SpringContext.getBean(DataDictionaryService.class),
171: accountingDocument, accountingLine));
172: }
173:
174: public void testIsDebit_asset_zeroAmount() throws Exception {
175: AccountingDocument accountingDocument = IsDebitTestUtils
176: .getDocument(SpringContext
177: .getBean(DocumentService.class),
178: NonCheckDisbursementDocument.class);
179: AccountingLine accountingLine = IsDebitTestUtils.getAssetLine(
180: accountingDocument, SourceAccountingLine.class,
181: KualiDecimal.ZERO);
182:
183: assertTrue(IsDebitTestUtils.isDebitIllegalStateException(
184: SpringContext.getBean(DocumentTypeService.class),
185: SpringContext.getBean(DataDictionaryService.class),
186: accountingDocument, accountingLine));
187: }
188:
189: public void testIsDebit_liability_positveAmount() throws Exception {
190: AccountingDocument accountingDocument = IsDebitTestUtils
191: .getDocument(SpringContext
192: .getBean(DocumentService.class),
193: NonCheckDisbursementDocument.class);
194: AccountingLine accountingLine = IsDebitTestUtils
195: .getLiabilityLine(accountingDocument,
196: SourceAccountingLine.class, POSITIVE);
197:
198: assertTrue(IsDebitTestUtils.isDebit(SpringContext
199: .getBean(DocumentTypeService.class), SpringContext
200: .getBean(DataDictionaryService.class),
201: accountingDocument, accountingLine));
202: }
203:
204: public void testIsDebit_liability_negativeAmount() throws Exception {
205: AccountingDocument accountingDocument = IsDebitTestUtils
206: .getDocument(SpringContext
207: .getBean(DocumentService.class),
208: NonCheckDisbursementDocument.class);
209: AccountingLine accountingLine = IsDebitTestUtils
210: .getLiabilityLine(accountingDocument,
211: SourceAccountingLine.class, NEGATIVE);
212:
213: assertTrue(IsDebitTestUtils.isDebitIllegalStateException(
214: SpringContext.getBean(DocumentTypeService.class),
215: SpringContext.getBean(DataDictionaryService.class),
216: accountingDocument, accountingLine));
217: }
218:
219: public void testIsDebit_liability_zeroAmount() throws Exception {
220: AccountingDocument accountingDocument = IsDebitTestUtils
221: .getDocument(SpringContext
222: .getBean(DocumentService.class),
223: NonCheckDisbursementDocument.class);
224: AccountingLine accountingLine = IsDebitTestUtils
225: .getLiabilityLine(accountingDocument,
226: SourceAccountingLine.class, KualiDecimal.ZERO);
227:
228: assertTrue(IsDebitTestUtils.isDebitIllegalStateException(
229: SpringContext.getBean(DocumentTypeService.class),
230: SpringContext.getBean(DataDictionaryService.class),
231: accountingDocument, accountingLine));
232: }
233:
234: public void testIsDebit_errorCorrection_income_negativeAmount()
235: throws Exception {
236: AccountingDocument accountingDocument = IsDebitTestUtils
237: .getErrorCorrectionDocument(SpringContext
238: .getBean(DocumentService.class),
239: NonCheckDisbursementDocument.class);
240: AccountingLine accountingLine = IsDebitTestUtils.getIncomeLine(
241: accountingDocument, SourceAccountingLine.class,
242: NEGATIVE);
243:
244: assertFalse(IsDebitTestUtils.isDebit(SpringContext
245: .getBean(DocumentTypeService.class), SpringContext
246: .getBean(DataDictionaryService.class),
247: accountingDocument, accountingLine));
248:
249: }
250:
251: public void testIsDebit_errorCorrection_expense_negativeAmount()
252: throws Exception {
253: AccountingDocument accountingDocument = IsDebitTestUtils
254: .getErrorCorrectionDocument(SpringContext
255: .getBean(DocumentService.class),
256: NonCheckDisbursementDocument.class);
257: AccountingLine accountingLine = IsDebitTestUtils
258: .getExpenseLine(accountingDocument,
259: SourceAccountingLine.class, NEGATIVE);
260:
261: assertFalse(IsDebitTestUtils.isDebit(SpringContext
262: .getBean(DocumentTypeService.class), SpringContext
263: .getBean(DataDictionaryService.class),
264: accountingDocument, accountingLine));
265: }
266:
267: public void testIsDebit_errorCorrection_asset_negativeAmount()
268: throws Exception {
269: AccountingDocument accountingDocument = IsDebitTestUtils
270: .getErrorCorrectionDocument(SpringContext
271: .getBean(DocumentService.class),
272: NonCheckDisbursementDocument.class);
273: AccountingLine accountingLine = IsDebitTestUtils.getAssetLine(
274: accountingDocument, SourceAccountingLine.class,
275: NEGATIVE);
276:
277: assertFalse(IsDebitTestUtils.isDebit(SpringContext
278: .getBean(DocumentTypeService.class), SpringContext
279: .getBean(DataDictionaryService.class),
280: accountingDocument, accountingLine));
281: }
282:
283: public void testIsDebit_errorCorrection_liability_negativeAmount()
284: throws Exception {
285: AccountingDocument accountingDocument = IsDebitTestUtils
286: .getErrorCorrectionDocument(SpringContext
287: .getBean(DocumentService.class),
288: NonCheckDisbursementDocument.class);
289: AccountingLine accountingLine = IsDebitTestUtils
290: .getLiabilityLine(accountingDocument,
291: SourceAccountingLine.class, NEGATIVE);
292:
293: assertFalse(IsDebitTestUtils.isDebit(SpringContext
294: .getBean(DocumentTypeService.class), SpringContext
295: .getBean(DataDictionaryService.class),
296: accountingDocument, accountingLine));
297: }
298:
299: public void testIsObjectTypeAllowed_InvalidObjectType()
300: throws Exception {
301: testAddAccountingLineRule_IsObjectTypeAllowed(DOCUMENT_CLASS,
302: getInvalidObjectTypeSourceLine(), false);
303: }
304:
305: public void testIsObjectTypeAllowed_Valid() throws Exception {
306: testAddAccountingLineRule_IsObjectTypeAllowed(DOCUMENT_CLASS,
307: getValidObjectTypeSourceLine(), true);
308: }
309:
310: public void testIsObjectCodeAllowed_Valid() throws Exception {
311: testAddAccountingLineRule_IsObjectCodeAllowed(DOCUMENT_CLASS,
312: getValidObjectCodeSourceLine(), true);
313: }
314:
315: public void testIsObjectCodeAllowed_InvalidObjectCode()
316: throws Exception {
317: testAddAccountingLineRule_IsObjectCodeAllowed(DOCUMENT_CLASS,
318: getInvalidObjectCodeSourceLine(), false);
319: }
320:
321: public void testAddAccountingLine_InvalidObjectSubType()
322: throws Exception {
323: AccountingDocument doc = createDocumentWithInvalidObjectSubType();
324: testAddAccountingLineRule_ProcessAddAccountingLineBusinessRules(
325: doc, false);
326: }
327:
328: public void testAddAccountingLine_Valid() throws Exception {
329: AccountingDocument doc = createDocumentWithValidObjectSubType();
330: testAddAccountingLineRule_ProcessAddAccountingLineBusinessRules(
331: doc, true);
332: }
333:
334: public void testIsObjectSubTypeAllowed_InvalidSubType()
335: throws Exception {
336: testAddAccountingLine_IsObjectSubTypeAllowed(DOCUMENT_CLASS,
337: getInvalidObjectSubTypeTargetLine(), false);
338: }
339:
340: public void testIsObjectSubTypeAllowed_ValidSubType()
341: throws Exception {
342: testAddAccountingLine_IsObjectSubTypeAllowed(DOCUMENT_CLASS,
343: getValidObjectSubTypeTargetLine(), true);
344: }
345:
346: public void testProcessSaveDocument_Valid() throws Exception {
347: testSaveDocumentRule_ProcessSaveDocument(createDocument(), true);
348: }
349:
350: public void testProcessSaveDocument_Invalid() throws Exception {
351: testSaveDocumentRule_ProcessSaveDocument(
352: createDocumentInvalidForSave(), false);
353: }
354:
355: public void testProcessSaveDocument_Invalid1() throws Exception {
356: try {
357: testSaveDocumentRule_ProcessSaveDocument(null, false);
358: fail("validated null doc");
359: } catch (Exception e) {
360: assertTrue(true);
361: }
362: }
363:
364: public void testProcessRouteDocument_Valid() throws Exception {
365: testRouteDocumentRule_processRouteDocument(
366: createDocumentValidForRouting(), true);
367: }
368:
369: public void testProcessRouteDocument_Invalid() throws Exception {
370: testRouteDocumentRule_processRouteDocument(createDocument(),
371: false);
372: }
373:
374: public void testProcessRouteDocument_NoAccountingLines()
375: throws Exception {
376: testRouteDocumentRule_processRouteDocument(createDocument(),
377: false);
378: }
379:
380: private NonCheckDisbursementDocument createDocument()
381: throws Exception {
382: return DocumentTestUtils.createDocument(SpringContext
383: .getBean(DocumentService.class),
384: NonCheckDisbursementDocument.class);
385: }
386:
387: private NonCheckDisbursementDocument createDocumentValidForRouting()
388: throws Exception {
389: return createDocumentWithValidObjectSubType();
390: }
391:
392: private NonCheckDisbursementDocument createDocumentInvalidForSave()
393: throws Exception {
394: return getDocumentParameterNoDescription();
395: }
396:
397: private NonCheckDisbursementDocument createDocumentWithValidObjectSubType()
398: throws Exception {
399: NonCheckDisbursementDocument retval = createDocument();
400: retval
401: .setSourceAccountingLines(getValidObjectSubTypeSourceLines());
402: retval
403: .setTargetAccountingLines(getValidObjectSubTypeTargetLines());
404: return retval;
405: }
406:
407: private NonCheckDisbursementDocument getDocumentParameterNoDescription()
408: throws Exception {
409: NonCheckDisbursementDocument document = DocumentTestUtils
410: .createDocument(SpringContext
411: .getBean(DocumentService.class),
412: NonCheckDisbursementDocument.class);
413: document.getDocumentHeader().setFinancialDocumentDescription(
414: null);
415: return document;
416: }
417:
418: private TargetAccountingLine getValidObjectSubTypeTargetLine()
419: throws Exception {
420: return getAccruedIncomeTargetLineParameter();
421: }
422:
423: private TargetAccountingLine getInvalidObjectSubTypeTargetLine()
424: throws Exception {
425: return getAccruedSickPayTargetLineParameter();
426: }
427:
428: private List<SourceAccountingLine> getValidObjectSubTypeSourceLines()
429: throws Exception {
430: List<SourceAccountingLine> retval = new ArrayList<SourceAccountingLine>();
431: retval.add(getAccruedIncomeSourceLineParameter());
432: retval.add(getAccruedIncomeSourceLineParameter());
433: return retval;
434: }
435:
436: private List<SourceAccountingLine> getInvalidObjectSubTypeSourceLines()
437: throws Exception {
438: List<SourceAccountingLine> retval = new ArrayList<SourceAccountingLine>();
439: retval.add(getAccruedSickPaySourceLineParameter());
440: retval.add(getAccruedSickPaySourceLineParameter());
441: return retval;
442: }
443:
444: private List<TargetAccountingLine> getInvalidObjectSubTypeTargetLines()
445: throws Exception {
446: List<TargetAccountingLine> retval = new ArrayList<TargetAccountingLine>();
447: retval.add(getAccruedSickPayTargetLineParameter());
448: retval.add(getAccruedSickPayTargetLineParameter());
449: return retval;
450: }
451:
452: private List<TargetAccountingLine> getValidObjectSubTypeTargetLines()
453: throws Exception {
454: List<TargetAccountingLine> retval = new ArrayList<TargetAccountingLine>();
455: retval.add(getAccruedIncomeTargetLineParameter());
456: retval.add(getAccruedIncomeTargetLineParameter());
457: return retval;
458: }
459:
460: private SourceAccountingLine getValidObjectTypeSourceLine()
461: throws Exception {
462: return LINE8.createSourceAccountingLine();
463: }
464:
465: private SourceAccountingLine getInvalidObjectTypeSourceLine()
466: throws Exception {
467: return getAccruedSickPaySourceLineParameter();
468: }
469:
470: private SourceAccountingLine getInvalidObjectCodeSourceLine()
471: throws Exception {
472: return LINE10.createSourceAccountingLine();
473: }
474:
475: private SourceAccountingLine getValidObjectCodeSourceLine()
476: throws Exception {
477: return getAccruedIncomeSourceLineParameter();
478: }
479:
480: private NonCheckDisbursementDocument createDocumentWithInvalidObjectSubType()
481: throws Exception {
482: NonCheckDisbursementDocument retval = createDocument();
483: retval
484: .setSourceAccountingLines(getInvalidObjectSubTypeSourceLines());
485: retval
486: .setTargetAccountingLines(getInvalidObjectSubTypeTargetLines());
487: return retval;
488: }
489:
490: private SourceAccountingLine getAccruedIncomeSourceLineParameter()
491: throws Exception {
492: return ACCRUED_INCOME_LINE.createAccountingLine(
493: SourceAccountingLine.class, KFSConstants.GL_DEBIT_CODE);
494: }
495:
496: private SourceAccountingLine getAccruedSickPaySourceLineParameter()
497: throws Exception {
498: return ACCRUED_SICK_PAY_LINE.createAccountingLine(
499: SourceAccountingLine.class, KFSConstants.GL_DEBIT_CODE);
500: }
501:
502: private TargetAccountingLine getAccruedIncomeTargetLineParameter()
503: throws Exception {
504: return ACCRUED_INCOME_LINE
505: .createAccountingLine(TargetAccountingLine.class,
506: KFSConstants.GL_CREDIT_CODE);
507: }
508:
509: private TargetAccountingLine getAccruedSickPayTargetLineParameter()
510: throws Exception {
511: return ACCRUED_SICK_PAY_LINE.createAccountingLine(
512: TargetAccountingLine.class, KFSConstants.GL_DEBIT_CODE);
513: }
514: }
|