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.KHUNTLEY;
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.AdvanceDepositDocument;
032: import org.kuali.test.ConfigureContext;
033:
034: /**
035: * This class tests the <code>AdvanceDepositDocumentRule</code>s
036: */
037: @ConfigureContext(session=KHUNTLEY)
038: public class AdvanceDepositDocumentRuleTest 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: AdvanceDepositDocument.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: AdvanceDepositDocument.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: AdvanceDepositDocument.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: AdvanceDepositDocument.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: AdvanceDepositDocument.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: AdvanceDepositDocument.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: AdvanceDepositDocument.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: AdvanceDepositDocument.class);
194: AccountingLine accountingLine = IsDebitTestUtils.getAssetLine(
195: accountingDocument, SourceAccountingLine.class,
196: POSITIVE);
197:
198: assertTrue(IsDebitTestUtils.isDebit(SpringContext
199: .getBean(DocumentTypeService.class), SpringContext
200: .getBean(DataDictionaryService.class),
201: accountingDocument, accountingLine));
202: }
203:
204: /**
205: * tests false is returned for a negative asset
206: *
207: * @throws Exception
208: */
209: public void testIsDebit_asset_negativeAmount() throws Exception {
210: AccountingDocument accountingDocument = IsDebitTestUtils
211: .getDocument(SpringContext
212: .getBean(DocumentService.class),
213: AdvanceDepositDocument.class);
214: AccountingLine accountingLine = IsDebitTestUtils.getAssetLine(
215: accountingDocument, SourceAccountingLine.class,
216: NEGATIVE);
217:
218: assertFalse(IsDebitTestUtils.isDebit(SpringContext
219: .getBean(DocumentTypeService.class), SpringContext
220: .getBean(DataDictionaryService.class),
221: accountingDocument, accountingLine));
222:
223: }
224:
225: /**
226: * tests an <code>IllegalStateException</code> is thrown for a zero asset
227: *
228: * @throws Exception
229: */
230: public void testIsDebit_asset_zeroAmount() throws Exception {
231: AccountingDocument accountingDocument = IsDebitTestUtils
232: .getDocument(SpringContext
233: .getBean(DocumentService.class),
234: AdvanceDepositDocument.class);
235: AccountingLine accountingLine = IsDebitTestUtils.getAssetLine(
236: accountingDocument, SourceAccountingLine.class,
237: KualiDecimal.ZERO);
238:
239: assertTrue(IsDebitTestUtils.isDebitIllegalStateException(
240: SpringContext.getBean(DocumentTypeService.class),
241: SpringContext.getBean(DataDictionaryService.class),
242: accountingDocument, accountingLine));
243: }
244:
245: /**
246: * tests false is returned for a positive liability
247: *
248: * @throws Exception
249: */
250: public void testIsDebit_liability_positveAmount() throws Exception {
251: AccountingDocument accountingDocument = IsDebitTestUtils
252: .getDocument(SpringContext
253: .getBean(DocumentService.class),
254: AdvanceDepositDocument.class);
255: AccountingLine accountingLine = IsDebitTestUtils
256: .getLiabilityLine(accountingDocument,
257: SourceAccountingLine.class, POSITIVE);
258:
259: assertFalse(IsDebitTestUtils.isDebit(SpringContext
260: .getBean(DocumentTypeService.class), SpringContext
261: .getBean(DataDictionaryService.class),
262: accountingDocument, accountingLine));
263: }
264:
265: /**
266: * tests true is returned for a negative liability
267: *
268: * @throws Exception
269: */
270: public void testIsDebit_liability_negativeAmount() throws Exception {
271: AccountingDocument accountingDocument = IsDebitTestUtils
272: .getDocument(SpringContext
273: .getBean(DocumentService.class),
274: AdvanceDepositDocument.class);
275: AccountingLine accountingLine = IsDebitTestUtils
276: .getLiabilityLine(accountingDocument,
277: SourceAccountingLine.class, NEGATIVE);
278:
279: assertTrue(IsDebitTestUtils.isDebit(SpringContext
280: .getBean(DocumentTypeService.class), SpringContext
281: .getBean(DataDictionaryService.class),
282: accountingDocument, accountingLine));
283:
284: }
285:
286: /**
287: * tests an <code>IllegalStateException</code> is thrown for a zero liability
288: *
289: * @throws Exception
290: */
291: public void testIsDebit_liability_zeroAmount() throws Exception {
292: AccountingDocument accountingDocument = IsDebitTestUtils
293: .getDocument(SpringContext
294: .getBean(DocumentService.class),
295: AdvanceDepositDocument.class);
296: AccountingLine accountingLine = IsDebitTestUtils
297: .getLiabilityLine(accountingDocument,
298: SourceAccountingLine.class, KualiDecimal.ZERO);
299:
300: assertTrue(IsDebitTestUtils.isDebitIllegalStateException(
301: SpringContext.getBean(DocumentTypeService.class),
302: SpringContext.getBean(DataDictionaryService.class),
303: accountingDocument, accountingLine));
304: }
305:
306: }
|