/* * The Kuali Financial System, a comprehensive financial management system for higher education. * * Copyright 2005-2014 The Kuali Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package org.kuali.kfs.fp.document.validation.impl; import static org.kuali.kfs.sys.fixture.UserNameFixture.lraab; import static org.kuali.kfs.sys.service.IsDebitTestUtils.Amount.NEGATIVE; import static org.kuali.kfs.sys.service.IsDebitTestUtils.Amount.POSITIVE; import org.kuali.kfs.fp.document.DisbursementVoucherDocument; import org.kuali.kfs.sys.ConfigureContext; import org.kuali.kfs.sys.businessobject.AccountingLine; import org.kuali.kfs.sys.businessobject.SourceAccountingLine; import org.kuali.kfs.sys.context.KualiTestBase; import org.kuali.kfs.sys.context.SpringContext; import org.kuali.kfs.sys.document.AccountingDocument; import org.kuali.kfs.sys.service.IsDebitTestUtils; import org.kuali.rice.core.api.util.type.KualiDecimal; import org.kuali.rice.kns.service.DataDictionaryService; import org.kuali.rice.krad.service.DocumentService; /** * This class tests the DisbursementVoucherDocumentRule */ @ConfigureContext(session = lraab) public class DisbursementVoucherDocumentRuleTest extends KualiTestBase { /** * test that an <code>IllegalStateException</code> gets thrown for an error correction document * * @throws Exception */ public void testIsDebit_errorCorrection() throws Exception { AccountingDocument accountingDocument = IsDebitTestUtils.getErrorCorrectionDocument(SpringContext.getBean(DocumentService.class), DisbursementVoucherDocument.class); AccountingLine accountingLine = IsDebitTestUtils.getIncomeLine(accountingDocument, SourceAccountingLine.class, POSITIVE); assertTrue(IsDebitTestUtils.isErrorCorrectionIllegalStateException(SpringContext.getBean(DataDictionaryService.class), SpringContext.getBean(DataDictionaryService.class), accountingDocument, accountingLine)); } /** * tests true is returned for a positive income * * @throws Exception */ public void testIsDebit_income_positveAmount() throws Exception { AccountingDocument accountingDocument = IsDebitTestUtils.getDocument(SpringContext.getBean(DocumentService.class), DisbursementVoucherDocument.class); AccountingLine accountingLine = IsDebitTestUtils.getIncomeLine(accountingDocument, SourceAccountingLine.class, POSITIVE); assertTrue(IsDebitTestUtils.isDebit(SpringContext.getBean(DataDictionaryService.class), SpringContext.getBean(DataDictionaryService.class), accountingDocument, accountingLine)); } /** * tests an <code>IllegalStateExcpetion</code> is thrown for a negative income * * @throws Exception */ public void testIsDebit_income_negativeAmount() throws Exception { AccountingDocument accountingDocument = IsDebitTestUtils.getDocument(SpringContext.getBean(DocumentService.class), DisbursementVoucherDocument.class); AccountingLine accountingLine = IsDebitTestUtils.getIncomeLine(accountingDocument, SourceAccountingLine.class, NEGATIVE); assertTrue(IsDebitTestUtils.isDebitIllegalStateException(SpringContext.getBean(DataDictionaryService.class), SpringContext.getBean(DataDictionaryService.class), accountingDocument, accountingLine)); } /** * tests an <code>IllegalStateException</code> is thrown for a zero income * * @throws Exception */ public void testIsDebit_income_zeroAmount() throws Exception { AccountingDocument accountingDocument = IsDebitTestUtils.getDocument(SpringContext.getBean(DocumentService.class), DisbursementVoucherDocument.class); AccountingLine accountingLine = IsDebitTestUtils.getIncomeLine(accountingDocument, SourceAccountingLine.class, KualiDecimal.ZERO); assertTrue(IsDebitTestUtils.isDebitIllegalStateException(SpringContext.getBean(DataDictionaryService.class), SpringContext.getBean(DataDictionaryService.class), accountingDocument, accountingLine)); } /** * tests true is returned for a positive expense * * @throws Exception */ public void testIsDebit_expense_positveAmount() throws Exception { AccountingDocument accountingDocument = IsDebitTestUtils.getDocument(SpringContext.getBean(DocumentService.class), DisbursementVoucherDocument.class); AccountingLine accountingLine = IsDebitTestUtils.getExpenseLine(accountingDocument, SourceAccountingLine.class, POSITIVE); assertTrue(IsDebitTestUtils.isDebit(SpringContext.getBean(DataDictionaryService.class), SpringContext.getBean(DataDictionaryService.class), accountingDocument, accountingLine)); } /** * tests an <code>IllegalStateException</code> is thrown for a negative expense * * @throws Exception */ public void testIsDebit_expense_negativeAmount() throws Exception { AccountingDocument accountingDocument = IsDebitTestUtils.getDocument(SpringContext.getBean(DocumentService.class), DisbursementVoucherDocument.class); AccountingLine accountingLine = IsDebitTestUtils.getExpenseLine(accountingDocument, SourceAccountingLine.class, NEGATIVE); assertTrue(IsDebitTestUtils.isDebitIllegalStateException(SpringContext.getBean(DataDictionaryService.class), SpringContext.getBean(DataDictionaryService.class), accountingDocument, accountingLine)); } /** * tests an <code>IllegalStateException</code> is thrown for a zero expense * * @throws Exception */ public void testIsDebit_expense_zeroAmount() throws Exception { AccountingDocument accountingDocument = IsDebitTestUtils.getDocument(SpringContext.getBean(DocumentService.class), DisbursementVoucherDocument.class); AccountingLine accountingLine = IsDebitTestUtils.getExpenseLine(accountingDocument, SourceAccountingLine.class, KualiDecimal.ZERO); assertTrue(IsDebitTestUtils.isDebitIllegalStateException(SpringContext.getBean(DataDictionaryService.class), SpringContext.getBean(DataDictionaryService.class), accountingDocument, accountingLine)); } /** * tests true is returned for a positive asset * * @throws Exception */ public void testIsDebit_asset_positveAmount() throws Exception { AccountingDocument accountingDocument = IsDebitTestUtils.getDocument(SpringContext.getBean(DocumentService.class), DisbursementVoucherDocument.class); AccountingLine accountingLine = IsDebitTestUtils.getAssetLine(accountingDocument, SourceAccountingLine.class, POSITIVE); assertTrue(IsDebitTestUtils.isDebit(SpringContext.getBean(DataDictionaryService.class), SpringContext.getBean(DataDictionaryService.class), accountingDocument, accountingLine)); } /** * tests an <code>IllegalStateException</code> is thrown for a negative asset * * @throws Exception */ public void testIsDebit_asset_negativeAmount() throws Exception { AccountingDocument accountingDocument = IsDebitTestUtils.getDocument(SpringContext.getBean(DocumentService.class), DisbursementVoucherDocument.class); AccountingLine accountingLine = IsDebitTestUtils.getAssetLine(accountingDocument, SourceAccountingLine.class, NEGATIVE); assertTrue(IsDebitTestUtils.isDebitIllegalStateException(SpringContext.getBean(DataDictionaryService.class), SpringContext.getBean(DataDictionaryService.class), accountingDocument, accountingLine)); } /** * tests an <code>IllegalStateException</code> is thrown for a zero asset * * @throws Exception */ public void testIsDebit_asset_zeroAmount() throws Exception { AccountingDocument accountingDocument = IsDebitTestUtils.getDocument(SpringContext.getBean(DocumentService.class), DisbursementVoucherDocument.class); AccountingLine accountingLine = IsDebitTestUtils.getAssetLine(accountingDocument, SourceAccountingLine.class, KualiDecimal.ZERO); assertTrue(IsDebitTestUtils.isDebitIllegalStateException(SpringContext.getBean(DataDictionaryService.class), SpringContext.getBean(DataDictionaryService.class), accountingDocument, accountingLine)); } /** * tests true is returned for a positive liability * * @throws Exception */ public void testIsDebit_liability_positveAmount() throws Exception { AccountingDocument accountingDocument = IsDebitTestUtils.getDocument(SpringContext.getBean(DocumentService.class), DisbursementVoucherDocument.class); AccountingLine accountingLine = IsDebitTestUtils.getLiabilityLine(accountingDocument, SourceAccountingLine.class, POSITIVE); assertTrue(IsDebitTestUtils.isDebit(SpringContext.getBean(DataDictionaryService.class), SpringContext.getBean(DataDictionaryService.class), accountingDocument, accountingLine)); } /** * tests an <code>IllegalStateException</code> is thrown for a negative liability * * @throws Exception */ public void testIsDebit_liability_negativeAmount() throws Exception { AccountingDocument accountingDocument = IsDebitTestUtils.getDocument(SpringContext.getBean(DocumentService.class), DisbursementVoucherDocument.class); AccountingLine accountingLine = IsDebitTestUtils.getLiabilityLine(accountingDocument, SourceAccountingLine.class, NEGATIVE); assertTrue(IsDebitTestUtils.isDebitIllegalStateException(SpringContext.getBean(DataDictionaryService.class), SpringContext.getBean(DataDictionaryService.class), accountingDocument, accountingLine)); } /** * tests an <code>IllegalStateException</code> is thrown for a zero liability * * @throws Exception */ public void testIsDebit_liability_zeroAmount() throws Exception { AccountingDocument accountingDocument = IsDebitTestUtils.getDocument(SpringContext.getBean(DocumentService.class), DisbursementVoucherDocument.class); AccountingLine accountingLine = IsDebitTestUtils.getLiabilityLine(accountingDocument, SourceAccountingLine.class, KualiDecimal.ZERO); assertTrue(IsDebitTestUtils.isDebitIllegalStateException(SpringContext.getBean(DataDictionaryService.class), SpringContext.getBean(DataDictionaryService.class), accountingDocument, accountingLine)); } // ///////////////////////////////////////////////////////////////////////// // Test Methods End Here // // ///////////////////////////////////////////////////////////////////////// }