001: /*
002: * Copyright 2005-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.module.financial.document.AccountingDocumentTestUtils.testGetNewDocument_byDocumentClass;
019: import static org.kuali.test.fixtures.AccountingLineFixture.GEC_LINE1;
020: import static org.kuali.test.fixtures.UserNameFixture.KHUNTLEY;
021:
022: import java.util.ArrayList;
023: import java.util.List;
024:
025: import org.kuali.core.document.Document;
026: import org.kuali.core.service.DataDictionaryService;
027: import org.kuali.core.service.DocumentService;
028: import org.kuali.core.service.TransactionalDocumentDictionaryService;
029: import org.kuali.kfs.bo.SourceAccountingLine;
030: import org.kuali.kfs.bo.TargetAccountingLine;
031: import org.kuali.kfs.context.KualiTestBase;
032: import org.kuali.kfs.context.SpringContext;
033: import org.kuali.module.chart.service.AccountingPeriodService;
034: import org.kuali.module.financial.bo.GECSourceAccountingLine;
035: import org.kuali.module.financial.bo.GECTargetAccountingLine;
036: import org.kuali.test.ConfigureContext;
037: import org.kuali.test.DocumentTestUtils;
038: import org.kuali.test.fixtures.AccountingLineFixture;
039:
040: /**
041: * This class is used to test GeneralErrorCorrectionDocument.
042: */
043: @ConfigureContext(session=KHUNTLEY)
044: public class GeneralErrorCorrectionDocumentTest extends KualiTestBase {
045:
046: public static final Class<GeneralErrorCorrectionDocument> DOCUMENT_CLASS = GeneralErrorCorrectionDocument.class;
047:
048: private Document getDocumentParameterFixture() throws Exception {
049: return DocumentTestUtils.createDocument(SpringContext
050: .getBean(DocumentService.class),
051: GeneralErrorCorrectionDocument.class);
052: }
053:
054: private List<AccountingLineFixture> getTargetAccountingLineParametersFromFixtures() {
055: List<AccountingLineFixture> list = new ArrayList<AccountingLineFixture>();
056: list.add(GEC_LINE1);
057: return list;
058: }
059:
060: private List<AccountingLineFixture> getSourceAccountingLineParametersFromFixtures() {
061: List<AccountingLineFixture> list = new ArrayList<AccountingLineFixture>();
062: list.add(GEC_LINE1);
063: return list;
064: }
065:
066: private GeneralErrorCorrectionDocument buildDocument()
067: throws Exception {
068: // put accounting lines into document parameter for later
069: GeneralErrorCorrectionDocument document = (GeneralErrorCorrectionDocument) getDocumentParameterFixture();
070:
071: // set accountinglines to document
072: for (AccountingLineFixture sourceFixture : getSourceAccountingLineParametersFromFixtures()) {
073:
074: document.addSourceAccountingLine(sourceFixture
075: .createAccountingLine(
076: GECSourceAccountingLine.class, document
077: .getDocumentNumber(), document
078: .getPostingYear(), document
079: .getNextSourceLineNumber()));
080: }
081:
082: for (AccountingLineFixture targetFixture : getTargetAccountingLineParametersFromFixtures()) {
083: document.addTargetAccountingLine(targetFixture
084: .createAccountingLine(
085: GECTargetAccountingLine.class, document
086: .getDocumentNumber(), document
087: .getPostingYear(), document
088: .getNextTargetLineNumber()));
089: }
090:
091: return document;
092: }
093:
094: public final void testAddAccountingLine() throws Exception {
095: List<SourceAccountingLine> sourceLines = generateSouceAccountingLines();
096: List<TargetAccountingLine> targetLines = generateTargetAccountingLines();
097: int expectedSourceTotal = sourceLines.size();
098: int expectedTargetTotal = targetLines.size();
099: AccountingDocumentTestUtils.testAddAccountingLine(
100: DocumentTestUtils
101: .createDocument(SpringContext
102: .getBean(DocumentService.class),
103: DOCUMENT_CLASS), sourceLines,
104: targetLines, expectedSourceTotal, expectedTargetTotal);
105: }
106:
107: public final void testGetNewDocument() throws Exception {
108: testGetNewDocument_byDocumentClass(DOCUMENT_CLASS,
109: SpringContext.getBean(DocumentService.class));
110: }
111:
112: public final void testConvertIntoCopy_copyDisallowed()
113: throws Exception {
114: AccountingDocumentTestUtils.testConvertIntoCopy_copyDisallowed(
115: buildDocument(), SpringContext
116: .getBean(DataDictionaryService.class));
117:
118: }
119:
120: public final void testConvertIntoErrorCorrection_documentAlreadyCorrected()
121: throws Exception {
122: AccountingDocumentTestUtils
123: .testConvertIntoErrorCorrection_documentAlreadyCorrected(
124: buildDocument(),
125: SpringContext
126: .getBean(TransactionalDocumentDictionaryService.class));
127: }
128:
129: public final void testConvertIntoErrorCorrection_errorCorrectionDisallowed()
130: throws Exception {
131: AccountingDocumentTestUtils
132: .testConvertIntoErrorCorrection_errorCorrectionDisallowed(
133: buildDocument(), SpringContext
134: .getBean(DataDictionaryService.class));
135: }
136:
137: public final void testConvertIntoErrorCorrection_invalidYear()
138: throws Exception {
139: AccountingDocumentTestUtils
140: .testConvertIntoErrorCorrection_invalidYear(
141: buildDocument(),
142: SpringContext
143: .getBean(TransactionalDocumentDictionaryService.class),
144: SpringContext
145: .getBean(AccountingPeriodService.class));
146: }
147:
148: @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
149: public final void testConvertIntoErrorCorrection() throws Exception {
150: AccountingDocumentTestUtils
151: .testConvertIntoErrorCorrection(
152: buildDocument(),
153: getExpectedPrePeCount(),
154: SpringContext.getBean(DocumentService.class),
155: SpringContext
156: .getBean(TransactionalDocumentDictionaryService.class));
157: }
158:
159: @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
160: public final void testRouteDocument() throws Exception {
161: AccountingDocumentTestUtils.testRouteDocument(buildDocument(),
162: SpringContext.getBean(DocumentService.class));
163: }
164:
165: @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
166: public final void testSaveDocument() throws Exception {
167: AccountingDocumentTestUtils.testSaveDocument(buildDocument(),
168: SpringContext.getBean(DocumentService.class));
169: }
170:
171: @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
172: public final void testConvertIntoCopy() throws Exception {
173: AccountingDocumentTestUtils.testConvertIntoCopy(
174: buildDocument(), SpringContext
175: .getBean(DocumentService.class),
176: getExpectedPrePeCount());
177: }
178:
179: // test util methods
180: private List<SourceAccountingLine> generateSouceAccountingLines()
181: throws Exception {
182: List<SourceAccountingLine> sourceLines = new ArrayList<SourceAccountingLine>();
183: // set accountinglines to document
184: for (AccountingLineFixture sourceFixture : getSourceAccountingLineParametersFromFixtures()) {
185: sourceLines.add(sourceFixture.createAccountingLine(
186: GECSourceAccountingLine.class,
187: sourceFixture.debitCreditCode));
188: }
189:
190: return sourceLines;
191: }
192:
193: private List<TargetAccountingLine> generateTargetAccountingLines()
194: throws Exception {
195: List<TargetAccountingLine> targetLines = new ArrayList<TargetAccountingLine>();
196: for (AccountingLineFixture targetFixture : getTargetAccountingLineParametersFromFixtures()) {
197: targetLines.add(targetFixture.createAccountingLine(
198: GECTargetAccountingLine.class,
199: targetFixture.debitCreditCode));
200: }
201:
202: return targetLines;
203: }
204:
205: private int getExpectedPrePeCount() {
206: return 4;
207: }
208:
209: }
|