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