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.LINE2;
020: import static org.kuali.test.fixtures.UserNameFixture.KHUNTLEY;
021:
022: import java.util.ArrayList;
023: import java.util.List;
024:
025: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
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: import org.kuali.test.suite.AnnotationTestSuite;
039:
040: /**
041: * This class is used to test DistributionOfIncomeAndExpenseDocument.
042: */
043: @ConfigureContext(session=KHUNTLEY)
044: public class DistributionOfIncomeAndExpenseDocumentTest extends
045: KualiTestBase {
046: private static final Log LOG = LogFactory
047: .getLog(DistributionOfIncomeAndExpenseDocumentTest.class);
048: public static final Class<DistributionOfIncomeAndExpenseDocument> DOCUMENT_CLASS = DistributionOfIncomeAndExpenseDocument.class;
049:
050: private Document getDocumentParameterFixture() throws Exception {
051: return DocumentTestUtils.createDocument(SpringContext
052: .getBean(DocumentService.class),
053: DistributionOfIncomeAndExpenseDocument.class);
054: }
055:
056: private List<AccountingLineFixture> getTargetAccountingLineParametersFromFixtures() {
057: List<AccountingLineFixture> list = new ArrayList<AccountingLineFixture>();
058: list.add(LINE2);
059: return list;
060: }
061:
062: private List<AccountingLineFixture> getSourceAccountingLineParametersFromFixtures() {
063: List<AccountingLineFixture> list = new ArrayList<AccountingLineFixture>();
064: list.add(LINE2);
065: return list;
066: }
067:
068: /*
069: * This test fails related to KULEDOCS-1662
070: */
071: // @RelatesTo(KULRNE1612)
072: @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
073: public final void testKULEDOCS_1401() throws Exception {
074: String testDocId = null;
075:
076: try {
077: {
078: // create a DIE doc
079: DistributionOfIncomeAndExpenseDocument createdDoc = (DistributionOfIncomeAndExpenseDocument) SpringContext
080: .getBean(DocumentService.class)
081: .getNewDocument(
082: DistributionOfIncomeAndExpenseDocument.class);
083: testDocId = createdDoc.getDocumentNumber();
084:
085: // populate and save it
086: createdDoc.getDocumentHeader()
087: .setFinancialDocumentDescription(
088: "created by testKULEDOCS_1401");
089: createdDoc.getDocumentHeader().setExplanation(
090: "reproducing KULEDOCS_1401");
091:
092: createdDoc
093: .addSourceAccountingLine(getSourceAccountingLineAccessibleAccount());
094: createdDoc
095: .addTargetAccountingLine(getTargetAccountingLineAccessibleAccount());
096:
097: SpringContext.getBean(DocumentService.class)
098: .saveDocument(createdDoc);
099: }
100:
101: {
102: // change the accountingLine totals (by adding new lines)
103: DistributionOfIncomeAndExpenseDocument savedDoc = (DistributionOfIncomeAndExpenseDocument) SpringContext
104: .getBean(DocumentService.class)
105: .getByDocumentHeaderId(testDocId);
106: savedDoc
107: .addSourceAccountingLine(getSourceAccountingLineAccessibleAccount());
108: savedDoc
109: .addTargetAccountingLine(getTargetAccountingLineAccessibleAccount());
110:
111: // blanketapprove updated doc
112: SpringContext.getBean(DocumentService.class)
113: .blanketApproveDocument(savedDoc,
114: "blanketapproving updated doc", null);
115: }
116: } finally {
117: // clean things up, if possible
118: if (testDocId != null) {
119: DistributionOfIncomeAndExpenseDocument cancelingDoc = (DistributionOfIncomeAndExpenseDocument) SpringContext
120: .getBean(DocumentService.class)
121: .getByDocumentHeaderId(testDocId);
122: if (cancelingDoc != null) {
123: try {
124: SpringContext.getBean(DocumentService.class)
125: .cancelDocument(cancelingDoc,
126: "cleaning up after test");
127: } catch (RuntimeException e) {
128: LOG
129: .error("caught RuntimeException canceling document: "
130: + e.getMessage());
131: }
132: }
133: }
134: }
135: }
136:
137: public final void testAddAccountingLine() throws Exception {
138: List<SourceAccountingLine> sourceLines = generateSouceAccountingLines();
139: List<TargetAccountingLine> targetLines = generateTargetAccountingLines();
140: int expectedSourceTotal = sourceLines.size();
141: int expectedTargetTotal = targetLines.size();
142: AccountingDocumentTestUtils.testAddAccountingLine(
143: DocumentTestUtils
144: .createDocument(SpringContext
145: .getBean(DocumentService.class),
146: DOCUMENT_CLASS), sourceLines,
147: targetLines, expectedSourceTotal, expectedTargetTotal);
148: }
149:
150: public final void testGetNewDocument() throws Exception {
151: testGetNewDocument_byDocumentClass(DOCUMENT_CLASS,
152: SpringContext.getBean(DocumentService.class));
153: }
154:
155: public final void testConvertIntoCopy_copyDisallowed()
156: throws Exception {
157: AccountingDocumentTestUtils.testConvertIntoCopy_copyDisallowed(
158: buildDocument(), SpringContext
159: .getBean(DataDictionaryService.class));
160:
161: }
162:
163: public final void testConvertIntoErrorCorrection_documentAlreadyCorrected()
164: throws Exception {
165: AccountingDocumentTestUtils
166: .testConvertIntoErrorCorrection_documentAlreadyCorrected(
167: buildDocument(),
168: SpringContext
169: .getBean(TransactionalDocumentDictionaryService.class));
170: }
171:
172: public final void testConvertIntoErrorCorrection_errorCorrectionDisallowed()
173: throws Exception {
174: AccountingDocumentTestUtils
175: .testConvertIntoErrorCorrection_errorCorrectionDisallowed(
176: buildDocument(), SpringContext
177: .getBean(DataDictionaryService.class));
178: }
179:
180: @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
181: public final void testConvertIntoErrorCorrection() throws Exception {
182: AccountingDocumentTestUtils
183: .testConvertIntoErrorCorrection(
184: buildDocument(),
185: getExpectedPrePeCount(),
186: SpringContext.getBean(DocumentService.class),
187: SpringContext
188: .getBean(TransactionalDocumentDictionaryService.class));
189: }
190:
191: @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
192: public final void testRouteDocument() throws Exception {
193: AccountingDocumentTestUtils.testRouteDocument(buildDocument(),
194: SpringContext.getBean(DocumentService.class));
195: }
196:
197: @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
198: public final void testSaveDocument() throws Exception {
199: AccountingDocumentTestUtils.testSaveDocument(buildDocument(),
200: SpringContext.getBean(DocumentService.class));
201: }
202:
203: @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
204: public void testConvertIntoCopy() throws Exception {
205: AccountingDocumentTestUtils.testConvertIntoCopy(
206: buildDocument(), SpringContext
207: .getBean(DocumentService.class),
208: getExpectedPrePeCount());
209: }
210:
211: // test util methods
212: private List<SourceAccountingLine> generateSouceAccountingLines()
213: throws Exception {
214: List<SourceAccountingLine> sourceLines = new ArrayList<SourceAccountingLine>();
215: // set accountinglines to document
216: for (AccountingLineFixture sourceFixture : getSourceAccountingLineParametersFromFixtures()) {
217: sourceLines.add(sourceFixture.createSourceAccountingLine());
218: }
219:
220: return sourceLines;
221: }
222:
223: private List<TargetAccountingLine> generateTargetAccountingLines()
224: throws Exception {
225: List<TargetAccountingLine> targetLines = new ArrayList<TargetAccountingLine>();
226: for (AccountingLineFixture targetFixture : getTargetAccountingLineParametersFromFixtures()) {
227: targetLines.add(targetFixture.createTargetAccountingLine());
228: }
229:
230: return targetLines;
231: }
232:
233: private DistributionOfIncomeAndExpenseDocument buildDocument()
234: throws Exception {
235: // put accounting lines into document parameter for later
236: DistributionOfIncomeAndExpenseDocument document = (DistributionOfIncomeAndExpenseDocument) getDocumentParameterFixture();
237:
238: // set accountinglines to document
239: for (AccountingLineFixture sourceFixture : getSourceAccountingLineParametersFromFixtures()) {
240: sourceFixture.addAsSourceTo(document);
241: }
242:
243: for (AccountingLineFixture targetFixture : getTargetAccountingLineParametersFromFixtures()) {
244: targetFixture.addAsTargetTo(document);
245: }
246:
247: return document;
248: }
249:
250: private int getExpectedPrePeCount() {
251: return 4;
252: }
253:
254: private SourceAccountingLine getSourceAccountingLineAccessibleAccount()
255: throws Exception {
256: return LINE2.createSourceAccountingLine();
257: }
258:
259: private TargetAccountingLine getTargetAccountingLineAccessibleAccount()
260: throws Exception {
261: return LINE2.createTargetAccountingLine();
262: }
263:
264: }
|