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.kfs.document.AccountingDocument;
034: import org.kuali.module.chart.service.AccountingPeriodService;
035: import org.kuali.test.ConfigureContext;
036: import org.kuali.test.DocumentTestUtils;
037: import org.kuali.test.fixtures.AccountingLineFixture;
038: import org.kuali.test.fixtures.UserNameFixture;
039:
040: /**
041: * This class is used to test TransferOfFundsDocument.
042: */
043: @ConfigureContext(session=KHUNTLEY)
044: public class TransferOfFundsDocumentTest extends KualiTestBase {
045: public static final Class<TransferOfFundsDocument> DOCUMENT_CLASS = TransferOfFundsDocument.class;
046:
047: // The set of Route Nodes that the test document will progress through
048: private static final String ACCOUNT_REVIEW = "Account Review";
049: private static final String ORG_REVIEW = "Org Review";
050:
051: private Document getDocumentParameterFixture() throws Exception {
052: return DocumentTestUtils.createDocument(SpringContext
053: .getBean(DocumentService.class),
054: TransferOfFundsDocument.class);
055: }
056:
057: private List<AccountingLineFixture> getTargetAccountingLineParametersFromFixtures() {
058: List<AccountingLineFixture> list = new ArrayList<AccountingLineFixture>();
059: list.add(LINE1);
060: // list.add( LINE2 );
061: // list.add( LINE3 );
062: return list;
063: }
064:
065: private List<AccountingLineFixture> getSourceAccountingLineParametersFromFixtures() {
066: List<AccountingLineFixture> list = new ArrayList<AccountingLineFixture>();
067: list.add(LINE1);
068: // list.add( LINE2 );
069: // list.add( LINE3 );
070: return list;
071: }
072:
073: private void approve(String docHeaderId, UserNameFixture user,
074: String expectedNode) throws Exception {
075: changeCurrentUser(user);
076: AccountingDocumentTestUtils.approve(docHeaderId, user,
077: expectedNode, SpringContext
078: .getBean(DocumentService.class));
079: }
080:
081: private Document buildDocumentForWorkflowRoutingTest()
082: throws Exception {
083: AccountingDocument document = buildDocument();
084: AccountingLineFixture.LINE2_TOF.addAsSourceTo(document);
085: AccountingLineFixture.LINE2_TOF.addAsTargetTo(document);
086: return document;
087: }
088:
089: public final void testAddAccountingLine() throws Exception {
090: List<SourceAccountingLine> sourceLines = generateSouceAccountingLines();
091: List<TargetAccountingLine> targetLines = generateTargetAccountingLines();
092: int expectedSourceTotal = sourceLines.size();
093: int expectedTargetTotal = targetLines.size();
094: AccountingDocumentTestUtils.testAddAccountingLine(
095: DocumentTestUtils
096: .createDocument(SpringContext
097: .getBean(DocumentService.class),
098: DOCUMENT_CLASS), sourceLines,
099: targetLines, expectedSourceTotal, expectedTargetTotal);
100: }
101:
102: public final void testGetNewDocument() throws Exception {
103: testGetNewDocument_byDocumentClass(DOCUMENT_CLASS,
104: SpringContext.getBean(DocumentService.class));
105: }
106:
107: public final void testConvertIntoCopy_copyDisallowed()
108: throws Exception {
109: AccountingDocumentTestUtils.testConvertIntoCopy_copyDisallowed(
110: buildDocument(), SpringContext
111: .getBean(DataDictionaryService.class));
112:
113: }
114:
115: public final void testConvertIntoErrorCorrection_documentAlreadyCorrected()
116: throws Exception {
117: AccountingDocumentTestUtils
118: .testConvertIntoErrorCorrection_documentAlreadyCorrected(
119: buildDocument(),
120: SpringContext
121: .getBean(TransactionalDocumentDictionaryService.class));
122: }
123:
124: public final void testConvertIntoErrorCorrection_errorCorrectionDisallowed()
125: throws Exception {
126: AccountingDocumentTestUtils
127: .testConvertIntoErrorCorrection_errorCorrectionDisallowed(
128: buildDocument(), SpringContext
129: .getBean(DataDictionaryService.class));
130: }
131:
132: public final void testConvertIntoErrorCorrection_invalidYear()
133: throws Exception {
134: AccountingDocumentTestUtils
135: .testConvertIntoErrorCorrection_invalidYear(
136: buildDocument(),
137: SpringContext
138: .getBean(TransactionalDocumentDictionaryService.class),
139: SpringContext
140: .getBean(AccountingPeriodService.class));
141: }
142:
143: @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
144: public final void testConvertIntoErrorCorrection() throws Exception {
145: AccountingDocumentTestUtils
146: .testConvertIntoErrorCorrection(
147: buildDocument(),
148: getExpectedPrePeCount(),
149: SpringContext.getBean(DocumentService.class),
150: SpringContext
151: .getBean(TransactionalDocumentDictionaryService.class));
152: }
153:
154: @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
155: public final void testRouteDocument() throws Exception {
156: AccountingDocumentTestUtils.testRouteDocument(buildDocument(),
157: SpringContext.getBean(DocumentService.class));
158: }
159:
160: @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
161: public final void testSaveDocument() throws Exception {
162: AccountingDocumentTestUtils.testSaveDocument(buildDocument(),
163: SpringContext.getBean(DocumentService.class));
164: }
165:
166: @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
167: public final void testConvertIntoCopy() throws Exception {
168: AccountingDocumentTestUtils.testConvertIntoCopy(
169: buildDocument(), SpringContext
170: .getBean(DocumentService.class),
171: getExpectedPrePeCount());
172: }
173:
174: // test util methods
175: private List<SourceAccountingLine> generateSouceAccountingLines()
176: throws Exception {
177: List<SourceAccountingLine> sourceLines = new ArrayList<SourceAccountingLine>();
178: // set accountinglines to document
179: for (AccountingLineFixture sourceFixture : getSourceAccountingLineParametersFromFixtures()) {
180: sourceLines.add(sourceFixture.createSourceAccountingLine());
181: }
182:
183: return sourceLines;
184: }
185:
186: private List<TargetAccountingLine> generateTargetAccountingLines()
187: throws Exception {
188: List<TargetAccountingLine> targetLines = new ArrayList<TargetAccountingLine>();
189: for (AccountingLineFixture targetFixture : getTargetAccountingLineParametersFromFixtures()) {
190: targetLines.add(targetFixture.createTargetAccountingLine());
191: }
192:
193: return targetLines;
194: }
195:
196: private TransferOfFundsDocument buildDocument() throws Exception {
197: // put accounting lines into document parameter for later
198: TransferOfFundsDocument document = (TransferOfFundsDocument) getDocumentParameterFixture();
199:
200: // set accountinglines to document
201: for (AccountingLineFixture sourceFixture : getSourceAccountingLineParametersFromFixtures()) {
202: sourceFixture.addAsSourceTo(document);
203: }
204:
205: for (AccountingLineFixture targetFixture : getTargetAccountingLineParametersFromFixtures()) {
206: targetFixture.addAsTargetTo(document);
207: }
208:
209: return document;
210: }
211:
212: private int getExpectedPrePeCount() {
213: return 4;
214: }
215: }
|