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