gt:         catch (Exception e) {
context: /*
   * 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.document.validation.impl.AccountingDocumentRuleTestUtils.testAddAccountingLineRule_ProcessAddAccountingLineBusinessRules;
  import static org.kuali.kfs.sys.document.validation.impl.AccountingDocumentRuleTestUtils.testRouteDocumentRule_processRouteDocument;
  import static org.kuali.kfs.sys.document.validation.impl.AccountingDocumentRuleTestUtils.testSaveDocumentRule_ProcessSaveDocument;
  import static org.kuali.kfs.sys.fixture.AccountingLineFixture.ACCRUED_INCOME_LINE;
  import static org.kuali.kfs.sys.fixture.AccountingLineFixture.ACCRUED_SICK_PAY_LINE;
  import static org.kuali.kfs.sys.fixture.AccountingLineFixture.LINE10;
  import static org.kuali.kfs.sys.fixture.AccountingLineFixture.LINE8;
  import static org.kuali.kfs.sys.fixture.UserNameFixture.khuntley;
  import static org.kuali.kfs.sys.service.IsDebitTestUtils.Amount.NEGATIVE;
  import static org.kuali.kfs.sys.service.IsDebitTestUtils.Amount.POSITIVE;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import org.kuali.kfs.fp.document.NonCheckDisbursementDocument;
  import org.kuali.kfs.sys.ConfigureContext;
  import org.kuali.kfs.sys.DocumentTestUtils;
  import org.kuali.kfs.sys.KFSConstants;
  import org.kuali.kfs.sys.businessobject.AccountingLine;
  import org.kuali.kfs.sys.businessobject.SourceAccountingLine;
  import org.kuali.kfs.sys.businessobject.TargetAccountingLine;
  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;
  
  @ConfigureContext(session = khuntley)
  public class NonCheckDisbursementDocumentRuleTest extends KualiTestBase {
      public static final Class<NonCheckDisbursementDocument> DOCUMENT_CLASS = NonCheckDisbursementDocument.class;
  
  
      public void testIsDebit_income_positveAmount() throws Exception {
          AccountingDocument accountingDocument = IsDebitTestUtils.getDocument(SpringContext.getBean(DocumentService.class), NonCheckDisbursementDocument.class);
          AccountingLine accountingLine = IsDebitTestUtils.getIncomeLine(accountingDocument, SourceAccountingLine.class, POSITIVE);
  
          assertTrue(IsDebitTestUtils.isDebit(SpringContext.getBean(DataDictionaryService.class), SpringContext.getBean(DataDictionaryService.class), accountingDocument, accountingLine));
      }
  
      public void testIsDebit_income_negativeAmount() throws Exception {
          AccountingDocument accountingDocument = IsDebitTestUtils.getDocument(SpringContext.getBean(DocumentService.class), NonCheckDisbursementDocument.class);
          AccountingLine accountingLine = IsDebitTestUtils.getIncomeLine(accountingDocument, SourceAccountingLine.class, NEGATIVE);
  
          assertTrue(IsDebitTestUtils.isDebitIllegalStateException(SpringContext.getBean(DataDictionaryService.class), SpringContext.getBean(DataDictionaryService.class), accountingDocument, accountingLine));
      }
  
      public void testIsDebit_income_zeroAmount() throws Exception {
          AccountingDocument accountingDocument = IsDebitTestUtils.getDocument(SpringContext.getBean(DocumentService.class), NonCheckDisbursementDocument.class);
          AccountingLine accountingLine = IsDebitTestUtils.getIncomeLine(accountingDocument, SourceAccountingLine.class, KualiDecimal.ZERO);
  
          assertTrue(IsDebitTestUtils.isDebitIllegalStateException(SpringContext.getBean(DataDictionaryService.class), SpringContext.getBean(DataDictionaryService.class), accountingDocument, accountingLine));
      }
  
      public void testIsDebit_expense_positveAmount() throws Exception {
          AccountingDocument accountingDocument = IsDebitTestUtils.getDocument(SpringContext.getBean(DocumentService.class), NonCheckDisbursementDocument.class);
          AccountingLine accountingLine = IsDebitTestUtils.getExpenseLine(accountingDocument, SourceAccountingLine.class, POSITIVE);
  
          assertTrue(IsDebitTestUtils.isDebit(SpringContext.getBean(DataDictionaryService.class), SpringContext.getBean(DataDictionaryService.class), accountingDocument, accountingLine));
      }
  
      public void testIsDebit_expense_negativeAmount() throws Exception {
          AccountingDocument accountingDocument = IsDebitTestUtils.getDocument(SpringContext.getBean(DocumentService.class), NonCheckDisbursementDocument.class);
          AccountingLine accountingLine = IsDebitTestUtils.getExpenseLine(accountingDocument, SourceAccountingLine.class, NEGATIVE);
  
          assertTrue(IsDebitTestUtils.isDebitIllegalStateException(SpringContext.getBean(DataDictionaryService.class), SpringContext.getBean(DataDictionaryService.class), accountingDocument, accountingLine));
      }
  
      public void testIsDebit_expense_zeroAmount() throws Exception {
          AccountingDocument accountingDocument = IsDebitTestUtils.getDocument(SpringContext.getBean(DocumentService.class), NonCheckDisbursementDocument.class);
          AccountingLine accountingLine = IsDebitTestUtils.getExpenseLine(accountingDocument, SourceAccountingLine.class, KualiDecimal.ZERO);
  
          assertTrue(IsDebitTestUtils.isDebitIllegalStateException(SpringContext.getBean(DataDictionaryService.class), SpringContext.getBean(DataDictionaryService.class), accountingDocument, accountingLine));
      }
  
      public void testIsDebit_asset_positveAmount() throws Exception {
          AccountingDocument accountingDocument = IsDebitTestUtils.getDocument(SpringContext.getBean(DocumentService.class), NonCheckDisbursementDocument.class);
          AccountingLine accountingLine = IsDebitTestUtils.getAssetLine(accountingDocument, SourceAccountingLine.class, POSITIVE);
  
          assertTrue(IsDebitTestUtils.isDebit(SpringContext.getBean(DataDictionaryService.class), SpringContext.getBean(DataDictionaryService.class), accountingDocument, accountingLine));
      }
  
      public void testIsDebit_asset_negativeAmount() throws Exception {
          AccountingDocument accountingDocument = IsDebitTestUtils.getDocument(SpringContext.getBean(DocumentService.class), NonCheckDisbursementDocument.class);
          AccountingLine accountingLine = IsDebitTestUtils.getAssetLine(accountingDocument, SourceAccountingLine.class, NEGATIVE);
  
          assertTrue(IsDebitTestUtils.isDebitIllegalStateException(SpringContext.getBean(DataDictionaryService.class), SpringContext.getBean(DataDictionaryService.class), accountingDocument, accountingLine));
      }
  
      public void testIsDebit_asset_zeroAmount() throws Exception {
          AccountingDocument accountingDocument = IsDebitTestUtils.getDocument(SpringContext.getBean(DocumentService.class), NonCheckDisbursementDocument.class);
          AccountingLine accountingLine = IsDebitTestUtils.getAssetLine(accountingDocument, SourceAccountingLine.class, KualiDecimal.ZERO);
  
          assertTrue(IsDebitTestUtils.isDebitIllegalStateException(SpringContext.getBean(DataDictionaryService.class), SpringContext.getBean(DataDictionaryService.class), accountingDocument, accountingLine));
      }
  
      public void testIsDebit_liability_positveAmount() throws Exception {
          AccountingDocument accountingDocument = IsDebitTestUtils.getDocument(SpringContext.getBean(DocumentService.class), NonCheckDisbursementDocument.class);
          AccountingLine accountingLine = IsDebitTestUtils.getLiabilityLine(accountingDocument, SourceAccountingLine.class, POSITIVE);
  
          assertTrue(IsDebitTestUtils.isDebit(SpringContext.getBean(DataDictionaryService.class), SpringContext.getBean(DataDictionaryService.class), accountingDocument, accountingLine));
      }
  
      public void testIsDebit_liability_negativeAmount() throws Exception {
          AccountingDocument accountingDocument = IsDebitTestUtils.getDocument(SpringContext.getBean(DocumentService.class), NonCheckDisbursementDocument.class);
          AccountingLine accountingLine = IsDebitTestUtils.getLiabilityLine(accountingDocument, SourceAccountingLine.class, NEGATIVE);
  
          assertTrue(IsDebitTestUtils.isDebitIllegalStateException(SpringContext.getBean(DataDictionaryService.class), SpringContext.getBean(DataDictionaryService.class), accountingDocument, accountingLine));
      }
  
      public void testIsDebit_liability_zeroAmount() throws Exception {
          AccountingDocument accountingDocument = IsDebitTestUtils.getDocument(SpringContext.getBean(DocumentService.class), NonCheckDisbursementDocument.class);
          AccountingLine accountingLine = IsDebitTestUtils.getLiabilityLine(accountingDocument, SourceAccountingLine.class, KualiDecimal.ZERO);
  
          assertTrue(IsDebitTestUtils.isDebitIllegalStateException(SpringContext.getBean(DataDictionaryService.class), SpringContext.getBean(DataDictionaryService.class), accountingDocument, accountingLine));
      }
  
      public void testIsDebit_errorCorrection_income_negativeAmount() throws Exception {
          AccountingDocument accountingDocument = IsDebitTestUtils.getErrorCorrectionDocument(SpringContext.getBean(DocumentService.class), NonCheckDisbursementDocument.class);
          AccountingLine accountingLine = IsDebitTestUtils.getIncomeLine(accountingDocument, SourceAccountingLine.class, NEGATIVE);
  
          assertFalse(IsDebitTestUtils.isDebit(SpringContext.getBean(DataDictionaryService.class), SpringContext.getBean(DataDictionaryService.class), accountingDocument, accountingLine));
  
      }
  
      public void testIsDebit_errorCorrection_expense_negativeAmount() throws Exception {
          AccountingDocument accountingDocument = IsDebitTestUtils.getErrorCorrectionDocument(SpringContext.getBean(DocumentService.class), NonCheckDisbursementDocument.class);
          AccountingLine accountingLine = IsDebitTestUtils.getExpenseLine(accountingDocument, SourceAccountingLine.class, NEGATIVE);
  
          assertFalse(IsDebitTestUtils.isDebit(SpringContext.getBean(DataDictionaryService.class), SpringContext.getBean(DataDictionaryService.class), accountingDocument, accountingLine));
      }
  
      public void testIsDebit_errorCorrection_asset_negativeAmount() throws Exception {
          AccountingDocument accountingDocument = IsDebitTestUtils.getErrorCorrectionDocument(SpringContext.getBean(DocumentService.class), NonCheckDisbursementDocument.class);
          AccountingLine accountingLine = IsDebitTestUtils.getAssetLine(accountingDocument, SourceAccountingLine.class, NEGATIVE);
  
          assertFalse(IsDebitTestUtils.isDebit(SpringContext.getBean(DataDictionaryService.class), SpringContext.getBean(DataDictionaryService.class), accountingDocument, accountingLine));
      }
  
      public void testIsDebit_errorCorrection_liability_negativeAmount() throws Exception {
          AccountingDocument accountingDocument = IsDebitTestUtils.getErrorCorrectionDocument(SpringContext.getBean(DocumentService.class), NonCheckDisbursementDocument.class);
          AccountingLine accountingLine = IsDebitTestUtils.getLiabilityLine(accountingDocument, SourceAccountingLine.class, NEGATIVE);
  
          assertFalse(IsDebitTestUtils.isDebit(SpringContext.getBean(DataDictionaryService.class), SpringContext.getBean(DataDictionaryService.class), accountingDocument, accountingLine));
      }
  
  //    public void testIsObjectTypeAllowed_InvalidObjectType() throws Exception {
  //        testAddAccountingLineRule_IsObjectTypeAllowed(DOCUMENT_CLASS, getInvalidObjectTypeSourceLine(), false);
  //    }
  //
  //    public void testIsObjectTypeAllowed_Valid() throws Exception {
  //        testAddAccountingLineRule_IsObjectTypeAllowed(DOCUMENT_CLASS, getValidObjectTypeSourceLine(), true);
  //    }
  //
  //    public void testIsObjectCodeAllowed_Valid() throws Exception {
  //        testAddAccountingLineRule_IsObjectCodeAllowed(DOCUMENT_CLASS, getValidObjectCodeSourceLine(), true);
  //    }
  //
  //    public void testIsObjectCodeAllowed_InvalidObjectCode() throws Exception {
  //        testAddAccountingLineRule_IsObjectCodeAllowed(DOCUMENT_CLASS, getInvalidObjectCodeSourceLine(), false);
  //    }
  //
  //    public void testAddAccountingLine_InvalidObjectSubType() throws Exception {
  //        AccountingDocument doc = createDocumentWithInvalidObjectSubType();
  //        testAddAccountingLineRule_ProcessAddAccountingLineBusinessRules(doc, false);
  //    }
  
      public void testAddAccountingLine_Valid() throws Exception {
          AccountingDocument doc = createDocumentWithValidObjectSubType();
          testAddAccountingLineRule_ProcessAddAccountingLineBusinessRules(doc, true);
      }
  
  //    public void testIsObjectSubTypeAllowed_InvalidSubType() throws Exception {
  //        testAddAccountingLine_IsObjectSubTypeAllowed(DOCUMENT_CLASS, getInvalidObjectSubTypeTargetLine(), false);
  //    }
  //
  //    public void testIsObjectSubTypeAllowed_ValidSubType() throws Exception {
  //        testAddAccountingLine_IsObjectSubTypeAllowed(DOCUMENT_CLASS, getValidObjectSubTypeTargetLine(), true);
  //    }
  
      public void testProcessSaveDocument_Valid() throws Exception {
          testSaveDocumentRule_ProcessSaveDocument(createDocument(), true);
      }
  
      public void testProcessSaveDocument_Invalid() throws Exception {
          testSaveDocumentRule_ProcessSaveDocument(createDocumentInvalidForSave(), false);
      }
  
      public void testProcessSaveDocument_Invalid1() throws Exception {
          try {
              testSaveDocumentRule_ProcessSaveDocument(null, false);
              fail("validated null doc");
          }
  