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