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.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.test.ConfigureContext;
035: import org.kuali.test.DocumentTestUtils;
036: import org.kuali.test.fixtures.AccountingLineFixture;
037:
038: /**
039: * This class is used to test YearEndTransferOfFundsDocument. Note that structurally, there is no difference between a
040: * YearEndTransferOfFundsDocument and a regular TransferOfFundsDocument other than they have different document types and that this
041: * one posts to the year end accouting period.
042: */
043: @ConfigureContext(session=KHUNTLEY)
044: public class YearEndTransferOfFundsDocumentTest extends KualiTestBase {
045: public static final Class<YearEndTransferOfFundsDocument> DOCUMENT_CLASS = YearEndTransferOfFundsDocument.class;
046:
047: private Document getDocumentParameterFixture() throws Exception {
048: return DocumentTestUtils.createDocument(SpringContext
049: .getBean(DocumentService.class),
050: YearEndTransferOfFundsDocument.class);
051: }
052:
053: private List<AccountingLineFixture> getTargetAccountingLineParametersFromFixtures() {
054: List<AccountingLineFixture> list = new ArrayList<AccountingLineFixture>();
055: list.add(LINE1);
056: return list;
057: }
058:
059: private List<AccountingLineFixture> getSourceAccountingLineParametersFromFixtures() {
060: List<AccountingLineFixture> list = new ArrayList<AccountingLineFixture>();
061: list.add(LINE1);
062: return list;
063: }
064:
065: public final void testAddAccountingLine() throws Exception {
066: List<SourceAccountingLine> sourceLines = generateSouceAccountingLines();
067: List<TargetAccountingLine> targetLines = generateTargetAccountingLines();
068: int expectedSourceTotal = sourceLines.size();
069: int expectedTargetTotal = targetLines.size();
070: AccountingDocumentTestUtils.testAddAccountingLine(
071: DocumentTestUtils
072: .createDocument(SpringContext
073: .getBean(DocumentService.class),
074: DOCUMENT_CLASS), sourceLines,
075: targetLines, expectedSourceTotal, expectedTargetTotal);
076: }
077:
078: public final void testGetNewDocument() throws Exception {
079: testGetNewDocument_byDocumentClass(DOCUMENT_CLASS,
080: SpringContext.getBean(DocumentService.class));
081: }
082:
083: public final void testConvertIntoCopy_copyDisallowed()
084: throws Exception {
085: AccountingDocumentTestUtils.testConvertIntoCopy_copyDisallowed(
086: buildDocument(), SpringContext
087: .getBean(DataDictionaryService.class));
088:
089: }
090:
091: public final void testConvertIntoErrorCorrection_documentAlreadyCorrected()
092: throws Exception {
093: AccountingDocumentTestUtils
094: .testConvertIntoErrorCorrection_documentAlreadyCorrected(
095: buildDocument(),
096: SpringContext
097: .getBean(TransactionalDocumentDictionaryService.class));
098: }
099:
100: public final void testConvertIntoErrorCorrection_errorCorrectionDisallowed()
101: throws Exception {
102: AccountingDocumentTestUtils
103: .testConvertIntoErrorCorrection_errorCorrectionDisallowed(
104: buildDocument(), SpringContext
105: .getBean(DataDictionaryService.class));
106: }
107:
108: public final void testConvertIntoErrorCorrection_invalidYear()
109: throws Exception {
110: AccountingDocumentTestUtils
111: .testConvertIntoErrorCorrection_invalidYear(
112: buildDocument(),
113: SpringContext
114: .getBean(TransactionalDocumentDictionaryService.class),
115: SpringContext
116: .getBean(AccountingPeriodService.class));
117: }
118:
119: @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
120: public final void testConvertIntoErrorCorrection() throws Exception {
121: AccountingDocumentTestUtils
122: .testConvertIntoErrorCorrection(
123: buildDocument(),
124: getExpectedPrePeCount(),
125: SpringContext.getBean(DocumentService.class),
126: SpringContext
127: .getBean(TransactionalDocumentDictionaryService.class));
128: }
129:
130: @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
131: public final void testRouteDocument() throws Exception {
132: AccountingDocumentTestUtils.testRouteDocument(buildDocument(),
133: SpringContext.getBean(DocumentService.class));
134: }
135:
136: @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
137: public final void testSaveDocument() throws Exception {
138: AccountingDocumentTestUtils.testSaveDocument(buildDocument(),
139: SpringContext.getBean(DocumentService.class));
140: }
141:
142: @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
143: public final void testConvertIntoCopy() throws Exception {
144: AccountingDocumentTestUtils.testConvertIntoCopy(
145: buildDocument(), SpringContext
146: .getBean(DocumentService.class),
147: getExpectedPrePeCount());
148: }
149:
150: // test util methods
151: private List<SourceAccountingLine> generateSouceAccountingLines()
152: throws Exception {
153: List<SourceAccountingLine> sourceLines = new ArrayList<SourceAccountingLine>();
154: // set accountinglines to document
155: for (AccountingLineFixture sourceFixture : getSourceAccountingLineParametersFromFixtures()) {
156: sourceLines.add(sourceFixture.createSourceAccountingLine());
157: }
158:
159: return sourceLines;
160: }
161:
162: private List<TargetAccountingLine> generateTargetAccountingLines()
163: throws Exception {
164: List<TargetAccountingLine> targetLines = new ArrayList<TargetAccountingLine>();
165: for (AccountingLineFixture targetFixture : getTargetAccountingLineParametersFromFixtures()) {
166: targetLines.add(targetFixture.createTargetAccountingLine());
167: }
168:
169: return targetLines;
170: }
171:
172: private YearEndTransferOfFundsDocument buildDocument()
173: throws Exception {
174: // put accounting lines into document parameter for later
175: YearEndTransferOfFundsDocument document = (YearEndTransferOfFundsDocument) getDocumentParameterFixture();
176:
177: // set accountinglines to document
178: for (AccountingLineFixture sourceFixture : getSourceAccountingLineParametersFromFixtures()) {
179: sourceFixture.addAsSourceTo(document);
180: }
181:
182: for (AccountingLineFixture targetFixture : getTargetAccountingLineParametersFromFixtures()) {
183: targetFixture.addAsTargetTo(document);
184: }
185:
186: return document;
187: }
188:
189: private int getExpectedPrePeCount() {
190: return 4;
191: }
192: }
|