View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.fp.document;
20  
21  import static org.kuali.kfs.sys.document.AccountingDocumentTestUtils.testGetNewDocument_byDocumentClass;
22  import static org.kuali.kfs.sys.fixture.AccountingLineFixture.LINE1;
23  import static org.kuali.kfs.sys.fixture.UserNameFixture.khuntley;
24  
25  import java.util.ArrayList;
26  import java.util.List;
27  
28  import org.apache.log4j.Level;
29  import org.apache.log4j.Logger;
30  import org.kuali.kfs.coa.service.AccountingPeriodService;
31  import org.kuali.kfs.sys.ConfigureContext;
32  import org.kuali.kfs.sys.DocumentTestUtils;
33  import org.kuali.kfs.sys.businessobject.SourceAccountingLine;
34  import org.kuali.kfs.sys.businessobject.TargetAccountingLine;
35  import org.kuali.kfs.sys.context.KualiTestBase;
36  import org.kuali.kfs.sys.context.SpringContext;
37  import org.kuali.kfs.sys.document.AccountingDocument;
38  import org.kuali.kfs.sys.document.AccountingDocumentTestUtils;
39  import org.kuali.kfs.sys.fixture.AccountingLineFixture;
40  import org.kuali.kfs.sys.fixture.UserNameFixture;
41  import org.kuali.kfs.sys.monitor.ChangeMonitor;
42  import org.kuali.rice.kew.actions.BlanketApproveAction;
43  import org.kuali.rice.kns.service.DataDictionaryService;
44  import org.kuali.rice.kns.service.TransactionalDocumentDictionaryService;
45  import org.kuali.rice.krad.document.Document;
46  import org.kuali.rice.krad.service.DocumentService;
47  
48  /**
49   * This class is used to test TransferOfFundsDocument.
50   */
51  @ConfigureContext(session = khuntley)
52  public class TransferOfFundsDocumentTest extends KualiTestBase {
53      public static final Class<TransferOfFundsDocument> DOCUMENT_CLASS = TransferOfFundsDocument.class;
54  
55      // The set of Route Nodes that the test document will progress through
56      private static final String ACCOUNT_REVIEW = "Account Review";
57      private static final String ORG_REVIEW = "Org Review";
58  
59      @Override
60      protected void setUp() throws Exception {
61          super.setUp();
62          Logger.getLogger(ChangeMonitor.class).setLevel(Level.DEBUG);
63          Logger.getLogger(BlanketApproveAction.class).setLevel(Level.DEBUG);
64      }
65  
66  
67      private Document getDocumentParameterFixture() throws Exception {
68          return DocumentTestUtils.createDocument(SpringContext.getBean(DocumentService.class), TransferOfFundsDocument.class);
69      }
70  
71      private List<AccountingLineFixture> getTargetAccountingLineParametersFromFixtures() {
72          List<AccountingLineFixture> list = new ArrayList<AccountingLineFixture>();
73          list.add(LINE1);
74          // list.add( LINE2 );
75          // list.add( LINE3 );
76          return list;
77      }
78  
79      private List<AccountingLineFixture> getSourceAccountingLineParametersFromFixtures() {
80          List<AccountingLineFixture> list = new ArrayList<AccountingLineFixture>();
81          list.add(LINE1);
82          // list.add( LINE2 );
83          // list.add( LINE3 );
84          return list;
85      }
86  
87      private void approve(String docHeaderId, UserNameFixture user, String expectedNode) throws Exception {
88          changeCurrentUser(user);
89          AccountingDocumentTestUtils.approve(docHeaderId, user, expectedNode, SpringContext.getBean(DocumentService.class));
90      }
91  
92      private Document buildDocumentForWorkflowRoutingTest() throws Exception {
93          AccountingDocument document = buildDocument();
94          AccountingLineFixture.LINE2_TOF.addAsSourceTo(document);
95          AccountingLineFixture.LINE2_TOF.addAsTargetTo(document);
96          return document;
97      }
98  
99  
100     public final void testAddAccountingLine() throws Exception {
101         List<SourceAccountingLine> sourceLines = generateSouceAccountingLines();
102         List<TargetAccountingLine> targetLines = generateTargetAccountingLines();
103         int expectedSourceTotal = sourceLines.size();
104         int expectedTargetTotal = targetLines.size();
105         AccountingDocumentTestUtils.testAddAccountingLine(DocumentTestUtils.createDocument(SpringContext.getBean(DocumentService.class), DOCUMENT_CLASS), sourceLines, targetLines, expectedSourceTotal, expectedTargetTotal);
106     }
107 
108     public final void testGetNewDocument() throws Exception {
109         testGetNewDocument_byDocumentClass(DOCUMENT_CLASS, SpringContext.getBean(DocumentService.class));
110     }
111 
112     public final void testConvertIntoCopy_copyDisallowed() throws Exception {
113         AccountingDocumentTestUtils.testConvertIntoCopy_copyDisallowed(buildDocument(), SpringContext.getBean(DataDictionaryService.class));
114 
115     }
116 
117     public final void testConvertIntoErrorCorrection_documentAlreadyCorrected() throws Exception {
118         AccountingDocumentTestUtils.testConvertIntoErrorCorrection_documentAlreadyCorrected(buildDocument(), SpringContext.getBean(TransactionalDocumentDictionaryService.class));
119     }
120 
121     public final void testConvertIntoErrorCorrection_errorCorrectionDisallowed() throws Exception {
122         AccountingDocumentTestUtils.testConvertIntoErrorCorrection_errorCorrectionDisallowed(buildDocument(), SpringContext.getBean(DataDictionaryService.class));
123     }
124 
125     public final void testConvertIntoErrorCorrection_invalidYear() throws Exception {
126         AccountingDocumentTestUtils.testConvertIntoErrorCorrection_invalidYear(buildDocument(), SpringContext.getBean(TransactionalDocumentDictionaryService.class), SpringContext.getBean(AccountingPeriodService.class));
127     }
128 
129     @ConfigureContext(session = khuntley, shouldCommitTransactions = true)
130     public final void testConvertIntoErrorCorrection() throws Exception {
131         AccountingDocumentTestUtils.testConvertIntoErrorCorrection(buildDocument(), getExpectedPrePeCount(), SpringContext.getBean(DocumentService.class), SpringContext.getBean(TransactionalDocumentDictionaryService.class));
132     }
133 
134     @ConfigureContext(session = khuntley, shouldCommitTransactions = true)
135     public final void testRouteDocument() throws Exception {
136         AccountingDocumentTestUtils.testRouteDocument(buildDocument(), SpringContext.getBean(DocumentService.class));
137     }
138 
139     @ConfigureContext(session = khuntley, shouldCommitTransactions = true)
140     public final void testSaveDocument() throws Exception {
141         AccountingDocumentTestUtils.testSaveDocument(buildDocument(), SpringContext.getBean(DocumentService.class));
142     }
143 
144     @ConfigureContext(session = khuntley, shouldCommitTransactions = true)
145     public final void testConvertIntoCopy() throws Exception {
146         AccountingDocumentTestUtils.testConvertIntoCopy(buildDocument(), SpringContext.getBean(DocumentService.class), getExpectedPrePeCount());
147     }
148 
149     // test util methods
150     private List<SourceAccountingLine> generateSouceAccountingLines() throws Exception {
151         List<SourceAccountingLine> sourceLines = new ArrayList<SourceAccountingLine>();
152         // set accountinglines to document
153         for (AccountingLineFixture sourceFixture : getSourceAccountingLineParametersFromFixtures()) {
154             sourceLines.add(sourceFixture.createSourceAccountingLine());
155         }
156 
157         return sourceLines;
158     }
159 
160     private List<TargetAccountingLine> generateTargetAccountingLines() throws Exception {
161         List<TargetAccountingLine> targetLines = new ArrayList<TargetAccountingLine>();
162         for (AccountingLineFixture targetFixture : getTargetAccountingLineParametersFromFixtures()) {
163             targetLines.add(targetFixture.createTargetAccountingLine());
164         }
165 
166         return targetLines;
167     }
168 
169     private TransferOfFundsDocument buildDocument() throws Exception {
170         // put accounting lines into document parameter for later
171         TransferOfFundsDocument document = (TransferOfFundsDocument) getDocumentParameterFixture();
172 
173         // set accountinglines to document
174         for (AccountingLineFixture sourceFixture : getSourceAccountingLineParametersFromFixtures()) {
175             sourceFixture.addAsSourceTo(document);
176         }
177 
178         for (AccountingLineFixture targetFixture : getTargetAccountingLineParametersFromFixtures()) {
179             targetFixture.addAsTargetTo(document);
180         }
181 
182         return document;
183     }
184 
185     private int getExpectedPrePeCount() {
186         return 4;
187     }
188 }
189