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.financial.rules;
017:
018: import static org.kuali.module.financial.rules.IsDebitTestUtils.Amount.NEGATIVE;
019: import static org.kuali.module.financial.rules.IsDebitTestUtils.Amount.POSITIVE;
020: import static org.kuali.test.fixtures.UserNameFixture.MHKOZLOW;
021:
022: import org.kuali.core.service.DataDictionaryService;
023: import org.kuali.core.service.DocumentService;
024: import org.kuali.core.service.DocumentTypeService;
025: import org.kuali.core.util.KualiDecimal;
026: import org.kuali.kfs.bo.AccountingLine;
027: import org.kuali.kfs.bo.SourceAccountingLine;
028: import org.kuali.kfs.context.KualiTestBase;
029: import org.kuali.kfs.context.SpringContext;
030: import org.kuali.kfs.document.AccountingDocument;
031: import org.kuali.module.financial.document.CashReceiptDocument;
032: import org.kuali.test.ConfigureContext;
033:
034: /**
035: * This class tests the <code>CashReciptDocumentRule</code>s
036: */
037: @ConfigureContext(session=MHKOZLOW)
038: public class CashReceiptDocumentRuleTest extends KualiTestBase {
039:
040: /**
041: * test that an <code>IllegalStateException</code> gets thrown for an error correction document
042: *
043: * @throws Exception
044: */
045: public void testIsDebit_errorCorrection() throws Exception {
046: AccountingDocument accountingDocument = IsDebitTestUtils
047: .getErrorCorrectionDocument(SpringContext
048: .getBean(DocumentService.class),
049: CashReceiptDocument.class);
050: AccountingLine accountingLine = IsDebitTestUtils.getIncomeLine(
051: accountingDocument, SourceAccountingLine.class,
052: POSITIVE);
053:
054: assertTrue(IsDebitTestUtils
055: .isErrorCorrectionIllegalStateException(SpringContext
056: .getBean(DocumentTypeService.class),
057: SpringContext
058: .getBean(DataDictionaryService.class),
059: accountingDocument, accountingLine));
060: }
061:
062: /**
063: * tests false is returned for a positive income
064: *
065: * @throws Exception
066: */
067: public void testIsDebit_income_positveAmount() throws Exception {
068: AccountingDocument accountingDocument = IsDebitTestUtils
069: .getDocument(SpringContext
070: .getBean(DocumentService.class),
071: CashReceiptDocument.class);
072: AccountingLine accountingLine = IsDebitTestUtils.getIncomeLine(
073: accountingDocument, SourceAccountingLine.class,
074: POSITIVE);
075:
076: assertFalse(IsDebitTestUtils.isDebit(SpringContext
077: .getBean(DocumentTypeService.class), SpringContext
078: .getBean(DataDictionaryService.class),
079: accountingDocument, accountingLine));
080: }
081:
082: /**
083: * tests true is returned for a negative income
084: *
085: * @throws Exception
086: */
087: public void testIsDebit_income_negativeAmount() throws Exception {
088: AccountingDocument accountingDocument = IsDebitTestUtils
089: .getDocument(SpringContext
090: .getBean(DocumentService.class),
091: CashReceiptDocument.class);
092: AccountingLine accountingLine = IsDebitTestUtils.getIncomeLine(
093: accountingDocument, SourceAccountingLine.class,
094: NEGATIVE);
095:
096: assertTrue(IsDebitTestUtils.isDebit(SpringContext
097: .getBean(DocumentTypeService.class), SpringContext
098: .getBean(DataDictionaryService.class),
099: accountingDocument, accountingLine));
100:
101: }
102:
103: /**
104: * tests an <code>IllegalStateException</code> is thrown for a zero income
105: *
106: * @throws Exception
107: */
108: public void testIsDebit_income_zeroAmount() throws Exception {
109: AccountingDocument accountingDocument = IsDebitTestUtils
110: .getDocument(SpringContext
111: .getBean(DocumentService.class),
112: CashReceiptDocument.class);
113: AccountingLine accountingLine = IsDebitTestUtils.getIncomeLine(
114: accountingDocument, SourceAccountingLine.class,
115: KualiDecimal.ZERO);
116:
117: assertTrue(IsDebitTestUtils.isDebitIllegalStateException(
118: SpringContext.getBean(DocumentTypeService.class),
119: SpringContext.getBean(DataDictionaryService.class),
120: accountingDocument, accountingLine));
121: }
122:
123: /**
124: * tests true is returned for a positive expense
125: *
126: * @throws Exception
127: */
128: public void testIsDebit_expense_positveAmount() throws Exception {
129: AccountingDocument accountingDocument = IsDebitTestUtils
130: .getDocument(SpringContext
131: .getBean(DocumentService.class),
132: CashReceiptDocument.class);
133: AccountingLine accountingLine = IsDebitTestUtils
134: .getExpenseLine(accountingDocument,
135: SourceAccountingLine.class, POSITIVE);
136:
137: assertTrue(IsDebitTestUtils.isDebit(SpringContext
138: .getBean(DocumentTypeService.class), SpringContext
139: .getBean(DataDictionaryService.class),
140: accountingDocument, accountingLine));
141: }
142:
143: /**
144: * tests false is returned for a negative expense
145: *
146: * @throws Exception
147: */
148: public void testIsDebit_expense_negativeAmount() throws Exception {
149: AccountingDocument accountingDocument = IsDebitTestUtils
150: .getDocument(SpringContext
151: .getBean(DocumentService.class),
152: CashReceiptDocument.class);
153: AccountingLine accountingLine = IsDebitTestUtils
154: .getExpenseLine(accountingDocument,
155: SourceAccountingLine.class, NEGATIVE);
156:
157: assertFalse(IsDebitTestUtils.isDebit(SpringContext
158: .getBean(DocumentTypeService.class), SpringContext
159: .getBean(DataDictionaryService.class),
160: accountingDocument, accountingLine));
161:
162: }
163:
164: /**
165: * tests an <code>IllegalStateException</code> is thrown for a zero expense
166: *
167: * @throws Exception
168: */
169: public void testIsDebit_expense_zeroAmount() throws Exception {
170: AccountingDocument accountingDocument = IsDebitTestUtils
171: .getDocument(SpringContext
172: .getBean(DocumentService.class),
173: CashReceiptDocument.class);
174: AccountingLine accountingLine = IsDebitTestUtils
175: .getExpenseLine(accountingDocument,
176: SourceAccountingLine.class, KualiDecimal.ZERO);
177:
178: assertTrue(IsDebitTestUtils.isDebitIllegalStateException(
179: SpringContext.getBean(DocumentTypeService.class),
180: SpringContext.getBean(DataDictionaryService.class),
181: accountingDocument, accountingLine));
182: }
183:
184: /**
185: * tests true is returned for a positive asset
186: *
187: * @throws Exception
188: */
189: public void testIsDebit_asset_positveAmount() throws Exception {
190: AccountingDocument accountingDocument = IsDebitTestUtils
191: .getDocument(SpringContext
192: .getBean(DocumentService.class),
193: CashReceiptDocument.class);
194: AccountingLine accountingLine = IsDebitTestUtils.getAssetLine(
195: accountingDocument, SourceAccountingLine.class,
196: POSITIVE);
197: assertTrue(IsDebitTestUtils.isDebit(SpringContext
198: .getBean(DocumentTypeService.class), SpringContext
199: .getBean(DataDictionaryService.class),
200: accountingDocument, accountingLine));
201: }
202:
203: /**
204: * tests false is returned for a negative asset
205: *
206: * @throws Exception
207: */
208: public void testIsDebit_asset_negativeAmount() throws Exception {
209: AccountingDocument accountingDocument = IsDebitTestUtils
210: .getDocument(SpringContext
211: .getBean(DocumentService.class),
212: CashReceiptDocument.class);
213: AccountingLine accountingLine = IsDebitTestUtils.getAssetLine(
214: accountingDocument, SourceAccountingLine.class,
215: NEGATIVE);
216: assertFalse(IsDebitTestUtils.isDebit(SpringContext
217: .getBean(DocumentTypeService.class), SpringContext
218: .getBean(DataDictionaryService.class),
219: accountingDocument, accountingLine));
220:
221: }
222:
223: /**
224: * tests an <code>IllegalStateException</code> is thrown for a zero asset
225: *
226: * @throws Exception
227: */
228: public void testIsDebit_asset_zeroAmount() throws Exception {
229: AccountingDocument accountingDocument = IsDebitTestUtils
230: .getDocument(SpringContext
231: .getBean(DocumentService.class),
232: CashReceiptDocument.class);
233: AccountingLine accountingLine = IsDebitTestUtils.getAssetLine(
234: accountingDocument, SourceAccountingLine.class,
235: KualiDecimal.ZERO);
236:
237: assertTrue(IsDebitTestUtils.isDebitIllegalStateException(
238: SpringContext.getBean(DocumentTypeService.class),
239: SpringContext.getBean(DataDictionaryService.class),
240: accountingDocument, accountingLine));
241: }
242:
243: /**
244: * tests false is returned for aity
245: *
246: * @throws Exception
247: */
248: public void testIsDebit_liability_positveAmount() throws Exception {
249: AccountingDocument accountingDocument = IsDebitTestUtils
250: .getDocument(SpringContext
251: .getBean(DocumentService.class),
252: CashReceiptDocument.class);
253: AccountingLine accountingLine = IsDebitTestUtils
254: .getLiabilityLine(accountingDocument,
255: SourceAccountingLine.class, POSITIVE);
256: assertFalse(IsDebitTestUtils.isDebit(SpringContext
257: .getBean(DocumentTypeService.class), SpringContext
258: .getBean(DataDictionaryService.class),
259: accountingDocument, accountingLine));
260: }
261:
262: /**
263: * tests true is returned for a negative liability
264: *
265: * @throws Exception
266: */
267: public void testIsDebit_liability_negativeAmount() throws Exception {
268: AccountingDocument accountingDocument = IsDebitTestUtils
269: .getDocument(SpringContext
270: .getBean(DocumentService.class),
271: CashReceiptDocument.class);
272: AccountingLine accountingLine = IsDebitTestUtils
273: .getLiabilityLine(accountingDocument,
274: SourceAccountingLine.class, NEGATIVE);
275: assertTrue(IsDebitTestUtils.isDebit(SpringContext
276: .getBean(DocumentTypeService.class), SpringContext
277: .getBean(DataDictionaryService.class),
278: accountingDocument, accountingLine));
279:
280: }
281:
282: /**
283: * tests an <code>IllegalStateException</code> is thrown for a zero liability
284: *
285: * @throws Exception
286: */
287: public void testIsDebit_liability_zeroAmount() throws Exception {
288: AccountingDocument accountingDocument = IsDebitTestUtils
289: .getDocument(SpringContext
290: .getBean(DocumentService.class),
291: CashReceiptDocument.class);
292: AccountingLine accountingLine = IsDebitTestUtils
293: .getLiabilityLine(accountingDocument,
294: SourceAccountingLine.class, KualiDecimal.ZERO);
295:
296: assertTrue(IsDebitTestUtils.isDebitIllegalStateException(
297: SpringContext.getBean(DocumentTypeService.class),
298: SpringContext.getBean(DataDictionaryService.class),
299: accountingDocument, accountingLine));
300: }
301:
302: }
|