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.document;
017:
018: import static org.kuali.kfs.KFSConstants.GL_CREDIT_CODE;
019: import static org.kuali.kfs.KFSConstants.GL_DEBIT_CODE;
020: import static org.kuali.module.financial.document.AccountingDocumentTestUtils.testGetNewDocument_byDocumentClass;
021: import static org.kuali.test.fixtures.AccountingLineFixture.LINE15;
022: import static org.kuali.test.fixtures.UserNameFixture.KHUNTLEY;
023:
024: import java.util.ArrayList;
025: import java.util.List;
026:
027: import org.kuali.core.document.Document;
028: import org.kuali.core.service.DataDictionaryService;
029: import org.kuali.core.service.DocumentService;
030: import org.kuali.core.service.TransactionalDocumentDictionaryService;
031: import org.kuali.kfs.bo.SourceAccountingLine;
032: import org.kuali.kfs.bo.TargetAccountingLine;
033: import org.kuali.kfs.context.KualiTestBase;
034: import org.kuali.kfs.context.SpringContext;
035: import org.kuali.test.ConfigureContext;
036: import org.kuali.test.DocumentTestUtils;
037: import org.kuali.test.fixtures.AccountingLineFixture;
038:
039: /**
040: * This class is used to test NonCheckDisbursementDocumentTest.
041: */
042: @ConfigureContext(session=KHUNTLEY)
043: public class AuxiliaryVoucherDocumentTest extends KualiTestBase {
044:
045: public static final Class<AuxiliaryVoucherDocument> DOCUMENT_CLASS = AuxiliaryVoucherDocument.class;
046:
047: private Document getDocumentParameterFixture() throws Exception {
048: // AV document has a restriction on accounting period cannot be more than 2 periods behind current
049: return DocumentTestUtils.createDocument(SpringContext
050: .getBean(DocumentService.class),
051: AuxiliaryVoucherDocument.class);
052: }
053:
054: private List<AccountingLineFixture> getSourceAccountingLineParametersFromFixtures() {
055: List<AccountingLineFixture> list = new ArrayList<AccountingLineFixture>();
056: list.add(LINE15);
057: return list;
058: }
059:
060: private AuxiliaryVoucherDocument buildDocument() throws Exception {
061: // put accounting lines into document parameter for later
062: AuxiliaryVoucherDocument document = (AuxiliaryVoucherDocument) getDocumentParameterFixture();
063:
064: // set accountinglines to document
065: for (AccountingLineFixture sourceFixture : getSourceAccountingLineParametersFromFixtures()) {
066: SourceAccountingLine line = sourceFixture
067: .createAccountingLine(SourceAccountingLine.class,
068: document.getDocumentNumber(), document
069: .getPostingYear(), document
070: .getNextSourceLineNumber());
071: SourceAccountingLine balance = sourceFixture
072: .createAccountingLine(SourceAccountingLine.class,
073: document.getDocumentNumber(), document
074: .getPostingYear(), document
075: .getNextSourceLineNumber());
076: balance.setDebitCreditCode(GL_DEBIT_CODE.equals(line
077: .getDebitCreditCode()) ? GL_CREDIT_CODE
078: : GL_DEBIT_CODE);
079: document.addSourceAccountingLine(line);
080: document.addSourceAccountingLine(balance);
081:
082: }
083:
084: return document;
085: }
086:
087: private int getExpectedPrePeCount() {
088: return 2;
089: }
090:
091: public final void testAddAccountingLine() throws Exception {
092: List<SourceAccountingLine> sourceLines = generateSouceAccountingLines();
093: List<TargetAccountingLine> targetLines = new ArrayList<TargetAccountingLine>();
094: int expectedSourceTotal = sourceLines.size();
095: int expectedTargetTotal = targetLines.size();
096: AccountingDocumentTestUtils.testAddAccountingLine(
097: DocumentTestUtils
098: .createDocument(SpringContext
099: .getBean(DocumentService.class),
100: DOCUMENT_CLASS), sourceLines,
101: targetLines, expectedSourceTotal, expectedTargetTotal);
102: }
103:
104: public final void testGetNewDocument() throws Exception {
105: testGetNewDocument_byDocumentClass(DOCUMENT_CLASS,
106: SpringContext.getBean(DocumentService.class));
107: }
108:
109: public final void testConvertIntoErrorCorrection_documentAlreadyCorrected()
110: throws Exception {
111: AccountingDocumentTestUtils
112: .testConvertIntoErrorCorrection_documentAlreadyCorrected(
113: buildDocument(),
114: SpringContext
115: .getBean(TransactionalDocumentDictionaryService.class));
116: }
117:
118: public final void testConvertIntoErrorCorrection_errorCorrectionDisallowed()
119: throws Exception {
120: AccountingDocumentTestUtils
121: .testConvertIntoErrorCorrection_errorCorrectionDisallowed(
122: buildDocument(), SpringContext
123: .getBean(DataDictionaryService.class));
124: }
125:
126: @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
127: public final void testRouteDocument() throws Exception {
128: AccountingDocumentTestUtils.testRouteDocument(buildDocument(),
129: SpringContext.getBean(DocumentService.class));
130: }
131:
132: @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
133: public void testSaveDocument() throws Exception {
134: AccountingDocumentTestUtils.testSaveDocument(buildDocument(),
135: SpringContext.getBean(DocumentService.class));
136: }
137:
138: @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
139: public void testConvertIntoCopy() throws Exception {
140: AccountingDocumentTestUtils.testConvertIntoCopy(
141: buildDocument(), SpringContext
142: .getBean(DocumentService.class),
143: getExpectedPrePeCount());
144: }
145:
146: // test util mehtods
147: private List<SourceAccountingLine> generateSouceAccountingLines()
148: throws Exception {
149: List<SourceAccountingLine> sourceLines = new ArrayList<SourceAccountingLine>();
150: // set accountinglines to document
151: for (AccountingLineFixture sourceFixture : getSourceAccountingLineParametersFromFixtures()) {
152: sourceLines.add(sourceFixture.createSourceAccountingLine());
153: sourceLines
154: .add(sourceFixture
155: .createAccountingLine(
156: SourceAccountingLine.class,
157: GL_DEBIT_CODE
158: .equals(sourceFixture.debitCreditCode) ? GL_CREDIT_CODE
159: : GL_DEBIT_CODE));
160: }
161:
162: return sourceLines;
163: }
164:
165: }
|