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.module.ec.batch.service;
20  
21  import java.util.ArrayList;
22  import java.util.HashMap;
23  import java.util.List;
24  import java.util.Map;
25  import java.util.Properties;
26  
27  import org.apache.commons.lang.StringUtils;
28  import org.kuali.kfs.integration.ld.LaborLedgerBalance;
29  import org.kuali.kfs.integration.ld.LaborLedgerEntry;
30  import org.kuali.kfs.integration.ld.LaborModuleService;
31  import org.kuali.kfs.module.ec.batch.EffortCertificationExtractStep;
32  import org.kuali.kfs.module.ec.businessobject.EffortCertificationDetailBuild;
33  import org.kuali.kfs.module.ec.businessobject.EffortCertificationDocumentBuild;
34  import org.kuali.kfs.module.ec.businessobject.EffortCertificationReportDefinition;
35  import org.kuali.kfs.module.ec.document.EffortCertificationDocument;
36  import org.kuali.kfs.module.ec.service.EffortCertificationDetailBuildService;
37  import org.kuali.kfs.module.ec.testdata.EffortTestDataPropertyConstants;
38  import org.kuali.kfs.module.ld.businessobject.LedgerBalance;
39  import org.kuali.kfs.sys.ConfigureContext;
40  import org.kuali.kfs.sys.KFSConstants;
41  import org.kuali.kfs.sys.KFSPropertyConstants;
42  import org.kuali.kfs.sys.ObjectUtil;
43  import org.kuali.kfs.sys.TestDataPreparator;
44  import org.kuali.kfs.sys.businessobject.FinancialSystemDocumentHeader;
45  import org.kuali.kfs.sys.context.KualiTestBase;
46  import org.kuali.kfs.sys.context.SpringContext;
47  import org.kuali.kfs.sys.context.TestUtils;
48  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
49  import org.kuali.rice.coreservice.impl.parameter.ParameterBo;
50  import org.kuali.rice.krad.service.BusinessObjectService;
51  import org.kuali.rice.krad.service.KualiModuleService;
52  import org.kuali.rice.krad.service.PersistenceService;
53  
54  @ConfigureContext
55  public class EffortCertificationExtractServiceTest extends KualiTestBase {
56  
57      private final Properties properties, message;
58      private final String balanceFieldNames, entryFieldNames;
59      private final String detailFieldNames, documentFieldNames, documentHeaderFieldNames, reportDefinitionFieldNames;
60      private final String deliminator;
61  
62      private BusinessObjectService businessObjectService;
63      private PersistenceService persistenceService;
64      private ParameterService parameterService;
65  
66      private EffortCertificationDetailBuildService effortCertificationDetailBuildService;
67      private EffortCertificationExtractService effortCertificationExtractService;
68      private LaborModuleService laborModuleService;
69  
70      private Class<? extends LaborLedgerBalance> ledgerBalanceClass;
71      private Class<? extends LaborLedgerEntry> ledgerEntryClass;
72  
73      /**
74       * Constructs a EffortCertificationDetailBuildServiceTest.java.
75       */
76      public EffortCertificationExtractServiceTest() {
77          super();
78          String messageFileName = EffortTestDataPropertyConstants.TEST_DATA_PACKAGE_NAME + "/message.properties";
79          String propertiesFileName = EffortTestDataPropertyConstants.TEST_DATA_PACKAGE_NAME + "/effortCertificationExtractService.properties";
80  
81          properties = TestDataPreparator.loadPropertiesFromClassPath(propertiesFileName);
82          message = TestDataPreparator.loadPropertiesFromClassPath(messageFileName);
83  
84          deliminator = properties.getProperty(EffortTestDataPropertyConstants.DELIMINATOR);
85  
86          balanceFieldNames = properties.getProperty(EffortTestDataPropertyConstants.BALANCE_FIELD_NAMES);
87          entryFieldNames = properties.getProperty(EffortTestDataPropertyConstants.ENTRY_FIELD_NAMES);
88  
89          detailFieldNames = properties.getProperty(EffortTestDataPropertyConstants.DETAIL_FIELD_NAMES);
90          documentFieldNames = properties.getProperty(EffortTestDataPropertyConstants.DOCUMENT_FIELD_NAMES);
91          reportDefinitionFieldNames = properties.getProperty(EffortTestDataPropertyConstants.REPORT_DEFINITION_FIELD_NAMES);
92          documentHeaderFieldNames = properties.getProperty(EffortTestDataPropertyConstants.DOCUMENT_HEADER_FIELD_NAMES);
93      }
94  
95      @Override
96      public void setUp() throws Exception {
97          super.setUp();
98  
99          businessObjectService = SpringContext.getBean(BusinessObjectService.class);
100         persistenceService = SpringContext.getBean(PersistenceService.class);
101         parameterService = SpringContext.getBean(ParameterService.class);
102 
103         effortCertificationDetailBuildService = SpringContext.getBean(EffortCertificationDetailBuildService.class);
104         effortCertificationExtractService = SpringContext.getBean(EffortCertificationExtractService.class);
105         laborModuleService = SpringContext.getBean(LaborModuleService.class);
106 
107         KualiModuleService kualiModuleService = SpringContext.getBean(KualiModuleService.class);
108         ledgerBalanceClass = LedgerBalance.class;
109         ledgerEntryClass = kualiModuleService.getResponsibleModuleService(LaborLedgerEntry.class).createNewObjectFromExternalizableClass(LaborLedgerEntry.class).getClass();
110     }
111 
112     /**
113      * check if the service can approperiately handle the input parameters
114      *
115      * @see EffortCertificationExtractService.extract(Integer, String)
116      */
117     public void testInputParameters_ValidParameters() throws Exception {
118         String testTarget = "inputParameters.validParameters.";
119         Integer fiscalYear = Integer.valueOf(StringUtils.trim(properties.getProperty(testTarget + EffortTestDataPropertyConstants.FISCAL_YEAR)));
120         String reportNumber = properties.getProperty(testTarget + EffortTestDataPropertyConstants.REPORT_NUMBER);
121 
122         EffortCertificationReportDefinition reportDefinition = this.buildReportDefinition("");
123         reportDefinition = TestDataPreparator.persistDataObject(reportDefinition);
124 
125         TestDataPreparator.doCleanUpWithoutReference(ledgerEntryClass, properties, testTarget + EffortTestDataPropertyConstants.DATA_CLEANUP, entryFieldNames, deliminator);
126         TestDataPreparator.doCleanUpWithReference(EffortCertificationDocument.class, properties, testTarget + EffortTestDataPropertyConstants.DOCUMENT_CLEANUP, documentFieldNames, deliminator);
127 
128         try {
129             effortCertificationExtractService.extract(fiscalYear, reportNumber);
130         }
131         catch (Exception e) {
132             e.printStackTrace();
133             fail(message.getProperty("error.validParameters"));
134         }
135     }
136 
137     /**
138      * check if the service can approperiately handle the input parameters
139      *
140      * @see EffortCertificationExtractService.extract(Integer, String)
141      */
142     public void testInputParameters_EmptyFiscalYear() throws Exception {
143         String testTarget = "inputParameters.emptyFiscalYear.";
144         String reportNumber = properties.getProperty(testTarget + EffortTestDataPropertyConstants.REPORT_NUMBER);
145 
146         try {
147             effortCertificationExtractService.extract(null, reportNumber);
148             fail(message.getProperty("error.emptyFiscalYear"));
149         }
150         catch (Exception e) {
151         }
152     }
153 
154     /**
155      * check if the service can approperiately handle the input parameters
156      *
157      * @see EffortCertificationExtractService.extract(Integer, String)
158      */
159     public void testInputParameters_EmptyReportNumber() throws Exception {
160         String testTarget = "inputParameters.emptyReportNumber.";
161         Integer fiscalYear = Integer.valueOf(StringUtils.trim(properties.getProperty(testTarget + EffortTestDataPropertyConstants.FISCAL_YEAR)));
162         String reportNumber = properties.getProperty(testTarget + EffortTestDataPropertyConstants.REPORT_NUMBER);
163 
164         try {
165             effortCertificationExtractService.extract(fiscalYear, reportNumber);
166             fail(message.getProperty("error.emptyReportNumber"));
167         }
168         catch (Exception e) {
169         }
170     }
171 
172     /**
173      * check if the service can approperiately handle the input parameters
174      *
175      * @see EffortCertificationExtractService.extract(Integer, String)
176      */
177     public void testInputParameters_UndefinedReportDefinition() throws Exception {
178         String testTarget = "inputParameters.undefinedReportDefinition.";
179         Integer fiscalYear = Integer.valueOf(StringUtils.trim(properties.getProperty(testTarget + EffortTestDataPropertyConstants.FISCAL_YEAR)));
180         String reportNumber = properties.getProperty(testTarget + EffortTestDataPropertyConstants.REPORT_NUMBER);
181 
182         try {
183             effortCertificationExtractService.extract(fiscalYear, reportNumber);
184             fail(message.getProperty("error.undefinedReportDefinition"));
185         }
186         catch (Exception e) {
187         }
188     }
189 
190     /**
191      * check if the service can approperiately handle the input parameters
192      *
193      * @see EffortCertificationExtractService.extract(Integer, String)
194      */
195     public void testInputParameters_InactiveReportDefinition() throws Exception {
196         String testTarget = "inputParameters.inactiveReportDefinition.";
197         Integer fiscalYear = Integer.valueOf(StringUtils.trim(properties.getProperty(testTarget + EffortTestDataPropertyConstants.FISCAL_YEAR)));
198         String reportNumber = properties.getProperty(testTarget + EffortTestDataPropertyConstants.REPORT_NUMBER);
199 
200         EffortCertificationReportDefinition reportDefinition = this.buildReportDefinition("");
201         reportDefinition = TestDataPreparator.persistDataObject(reportDefinition);
202         reportDefinition.setActive(false);
203 
204         try {
205             effortCertificationExtractService.extract(fiscalYear, reportNumber);
206             fail(message.getProperty("error.inactiveReportDefinition"));
207         }
208         catch (Exception e) {
209         }
210     }
211 
212     /**
213      * check if the service can approperiately handle the input parameters
214      *
215      * @see EffortCertificationExtractService.extract(Integer, String)
216      */
217     public void testInputParameters_DocumentExist() throws Exception {
218         String testTarget = "inputParameters.documentExist.";
219         Integer fiscalYear = Integer.valueOf(StringUtils.trim(properties.getProperty(testTarget + EffortTestDataPropertyConstants.FISCAL_YEAR)));
220         String reportNumber = properties.getProperty(testTarget + EffortTestDataPropertyConstants.REPORT_NUMBER);
221 
222         EffortCertificationReportDefinition reportDefinition = this.buildReportDefinition("");
223         reportDefinition = TestDataPreparator.persistDataObject(reportDefinition);
224 
225         FinancialSystemDocumentHeader documentHeader = TestDataPreparator.buildTestDataObject(FinancialSystemDocumentHeader.class, properties, testTarget + EffortTestDataPropertyConstants.DOCUMENT_HEADER, documentHeaderFieldNames, deliminator);
226         documentHeader = TestDataPreparator.persistDataObject(documentHeader);
227 
228         EffortCertificationDocument document = this.buildDocument(testTarget);
229         document.setDocumentHeader(documentHeader);
230         document = TestDataPreparator.persistDataObject(document);
231 
232         try {
233             effortCertificationExtractService.extract(fiscalYear, reportNumber);
234             fail(message.getProperty("error.documentExist"));
235         }
236         catch (Exception e) {
237         }
238     }
239 
240     /**
241      * employees that meet certain criteria can be selected
242      */
243     public void testEmployeeSelection_Selected() throws Exception {
244         String testTarget = "employeeSelection.selected.";
245         Integer fiscalYear = Integer.valueOf(StringUtils.trim(properties.getProperty(testTarget + EffortTestDataPropertyConstants.FISCAL_YEAR)));
246         String reportNumber = properties.getProperty(testTarget + EffortTestDataPropertyConstants.REPORT_NUMBER);
247         this.loadTestData(testTarget);
248         this.updateSystemParameters("");
249 
250         effortCertificationExtractService.extract(fiscalYear, reportNumber);
251 
252         List<EffortCertificationDocumentBuild> documentBuildList = TestDataPreparator.findMatching(EffortCertificationDocumentBuild.class, properties, testTarget + EffortTestDataPropertyConstants.DOCUMENT_CLEANUP, documentFieldNames, deliminator);
253 
254         int numberOfExpectedDocuments = Integer.valueOf(properties.getProperty(testTarget + EffortTestDataPropertyConstants.NUM_OF_EXPECTED_DOCUMENTS));
255         List<EffortCertificationDocumentBuild> expectedDocumentBuildList = TestDataPreparator.buildExpectedValueList(EffortCertificationDocumentBuild.class, properties, testTarget + EffortTestDataPropertyConstants.EXPECTED_DOCUMENT, documentFieldNames, deliminator, numberOfExpectedDocuments);
256 
257         assertEquals(numberOfExpectedDocuments, documentBuildList.size());
258     }
259 
260     /**
261      * employees that meet certain criteria can be selected
262      */
263     public void testEmployeeSelection_NotSelected() throws Exception {
264         String testTarget = "employeeSelection.notSelected.";
265         Integer fiscalYear = Integer.valueOf(StringUtils.trim(properties.getProperty(testTarget + EffortTestDataPropertyConstants.FISCAL_YEAR)));
266         String reportNumber = properties.getProperty(testTarget + EffortTestDataPropertyConstants.REPORT_NUMBER);
267         this.loadTestData(testTarget);
268         this.updateSystemParameters("");
269 
270         effortCertificationExtractService.extract(fiscalYear, reportNumber);
271 
272         List<EffortCertificationDocumentBuild> documentBuildList = TestDataPreparator.findMatching(EffortCertificationDocumentBuild.class, properties, testTarget + EffortTestDataPropertyConstants.DOCUMENT_CLEANUP, documentFieldNames, deliminator);
273         int numberOfExpectedDocuments = Integer.valueOf(properties.getProperty(testTarget + EffortTestDataPropertyConstants.NUM_OF_EXPECTED_DOCUMENTS));
274 
275         assertEquals(numberOfExpectedDocuments, documentBuildList.size());
276     }
277 
278     /**
279      * check if the qualified balances for effort reporting can be selected
280      */
281     public void testBalanceSelection_Selected() throws Exception {
282         String testTarget = "balanceSelection.selected.";
283         Integer fiscalYear = Integer.valueOf(StringUtils.trim(properties.getProperty(testTarget + EffortTestDataPropertyConstants.FISCAL_YEAR)));
284         String reportNumber = properties.getProperty(testTarget + EffortTestDataPropertyConstants.REPORT_NUMBER);
285         this.loadTestData(testTarget);
286         this.updateSystemParameters("");
287 
288         effortCertificationExtractService.extract(fiscalYear, reportNumber);
289 
290         List<EffortCertificationDocumentBuild> documentBuildList = TestDataPreparator.findMatching(EffortCertificationDocumentBuild.class, properties, testTarget + EffortTestDataPropertyConstants.DOCUMENT_CLEANUP, documentFieldNames, deliminator);
291 
292         int numberOfExpectedDocuments = Integer.valueOf(properties.getProperty(testTarget + EffortTestDataPropertyConstants.NUM_OF_EXPECTED_DOCUMENTS));
293         List<EffortCertificationDocumentBuild> expectedDocumentBuildList = TestDataPreparator.buildExpectedValueList(EffortCertificationDocumentBuild.class, properties, testTarget + EffortTestDataPropertyConstants.EXPECTED_DOCUMENT, documentFieldNames, deliminator, numberOfExpectedDocuments);
294 
295         assertEquals(numberOfExpectedDocuments, documentBuildList.size());
296 
297         List<String> documentKeyFields = ObjectUtil.split(documentFieldNames, deliminator);
298         documentKeyFields.remove(KFSPropertyConstants.DOCUMENT_NUMBER);
299         assertTrue(TestDataPreparator.hasSameElements(documentBuildList, expectedDocumentBuildList, documentKeyFields));
300 
301         List<EffortCertificationDetailBuild> detailLinesBuild = new ArrayList<EffortCertificationDetailBuild>();
302         for (EffortCertificationDocumentBuild document : documentBuildList) {
303             detailLinesBuild.addAll(document.getEffortCertificationDetailLinesBuild());
304         }
305 
306         int numberOfExpectedDetailLines = Integer.valueOf(properties.getProperty(testTarget + EffortTestDataPropertyConstants.NUM_OF_EXPECTED_DETAILS));
307         List<EffortCertificationDetailBuild> expectedDetailLines = TestDataPreparator.buildExpectedValueList(EffortCertificationDetailBuild.class, properties, testTarget + EffortTestDataPropertyConstants.EXPECTED_DETAIL, detailFieldNames, deliminator, numberOfExpectedDetailLines);
308 
309         assertEquals(expectedDetailLines.size(), detailLinesBuild.size());
310 
311         List<String> detailLineKeyFields = ObjectUtil.split(detailFieldNames, deliminator);
312         detailLineKeyFields.remove(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR);
313         assertTrue(TestDataPreparator.hasSameElements(detailLinesBuild, expectedDetailLines, detailLineKeyFields));
314     }
315 
316     /**
317      * check if the balances without qualified balance type codes cannot be selected
318      */
319     public void testBalanceSelection_UnqualifiedBalanceType() throws Exception {
320         String testTarget = "balanceSelection.unqualifiedBalanceType.";
321         Integer fiscalYear = Integer.valueOf(StringUtils.trim(properties.getProperty(testTarget + EffortTestDataPropertyConstants.FISCAL_YEAR)));
322         String reportNumber = properties.getProperty(testTarget + EffortTestDataPropertyConstants.REPORT_NUMBER);
323         this.loadTestData(testTarget);
324         this.updateSystemParameters("");
325 
326         effortCertificationExtractService.extract(fiscalYear, reportNumber);
327 
328         List<EffortCertificationDocumentBuild> documentBuildList = TestDataPreparator.findMatching(EffortCertificationDocumentBuild.class, properties, testTarget + EffortTestDataPropertyConstants.DOCUMENT_CLEANUP, documentFieldNames, deliminator);
329         int numberOfExpectedDocuments = Integer.valueOf(properties.getProperty(testTarget + EffortTestDataPropertyConstants.NUM_OF_EXPECTED_DOCUMENTS));
330 
331         assertEquals(numberOfExpectedDocuments, documentBuildList.size());
332     }
333 
334     /**
335      * check if the balances without the qualified object type codes cannot be selected
336      */
337     public void testBalanceSelection_UnqualifiedObjectType() throws Exception {
338         String testTarget = "balanceSelection.unqualifiedObjectType.";
339         Integer fiscalYear = Integer.valueOf(StringUtils.trim(properties.getProperty(testTarget + EffortTestDataPropertyConstants.FISCAL_YEAR)));
340         String reportNumber = properties.getProperty(testTarget + EffortTestDataPropertyConstants.REPORT_NUMBER);
341         this.loadTestData(testTarget);
342         this.updateSystemParameters("");
343 
344         effortCertificationExtractService.extract(fiscalYear, reportNumber);
345 
346         List<EffortCertificationDocumentBuild> documentBuildList = TestDataPreparator.findMatching(EffortCertificationDocumentBuild.class, properties, testTarget + EffortTestDataPropertyConstants.DOCUMENT_CLEANUP, documentFieldNames, deliminator);
347         int numberOfExpectedDocuments = Integer.valueOf(properties.getProperty(testTarget + EffortTestDataPropertyConstants.NUM_OF_EXPECTED_DOCUMENTS));
348 
349         assertEquals(numberOfExpectedDocuments, documentBuildList.size());
350     }
351 
352     /**
353      * check if the non-salary balances cannot be selected
354      */
355     public void testBalanceSelection_NotSalary() throws Exception {
356         String testTarget = "balanceSelection.notSalary.";
357         Integer fiscalYear = Integer.valueOf(StringUtils.trim(properties.getProperty(testTarget + EffortTestDataPropertyConstants.FISCAL_YEAR)));
358         String reportNumber = properties.getProperty(testTarget + EffortTestDataPropertyConstants.REPORT_NUMBER);
359         this.loadTestData(testTarget);
360         this.updateSystemParameters("");
361 
362         effortCertificationExtractService.extract(fiscalYear, reportNumber);
363 
364         List<EffortCertificationDocumentBuild> documentBuildList = TestDataPreparator.findMatching(EffortCertificationDocumentBuild.class, properties, testTarget + EffortTestDataPropertyConstants.DOCUMENT_CLEANUP, documentFieldNames, deliminator);
365         int numberOfExpectedDocuments = Integer.valueOf(properties.getProperty(testTarget + EffortTestDataPropertyConstants.NUM_OF_EXPECTED_DOCUMENTS));
366 
367         assertEquals(numberOfExpectedDocuments, documentBuildList.size());
368     }
369 
370     /**
371      * check if the employees not paid by grants cannot be selected
372      */
373     public void testBalanceSelection_NotGrantAccount() throws Exception {
374         String testTarget = "balanceSelection.notGrantAccount.";
375         Integer fiscalYear = Integer.valueOf(StringUtils.trim(properties.getProperty(testTarget + EffortTestDataPropertyConstants.FISCAL_YEAR)));
376         String reportNumber = properties.getProperty(testTarget + EffortTestDataPropertyConstants.REPORT_NUMBER);
377         this.loadTestData(testTarget);
378         this.updateSystemParameters("");
379 
380         effortCertificationExtractService.extract(fiscalYear, reportNumber);
381 
382         List<EffortCertificationDocumentBuild> documentBuildList = TestDataPreparator.findMatching(EffortCertificationDocumentBuild.class, properties, testTarget + EffortTestDataPropertyConstants.DOCUMENT_CLEANUP, documentFieldNames, deliminator);
383         int numberOfExpectedDocuments = Integer.valueOf(properties.getProperty(testTarget + EffortTestDataPropertyConstants.NUM_OF_EXPECTED_DOCUMENTS));
384 
385         assertEquals(numberOfExpectedDocuments, documentBuildList.size());
386     }
387 
388     /**
389      * check if the balances with Zero total amount cannot be selected
390      */
391     public void testBalanceSelection_ZeroAmountBalance() throws Exception {
392         String testTarget = "balanceSelection.zeroAmountBalance.";
393         Integer fiscalYear = Integer.valueOf(StringUtils.trim(properties.getProperty(testTarget + EffortTestDataPropertyConstants.FISCAL_YEAR)));
394         String reportNumber = properties.getProperty(testTarget + EffortTestDataPropertyConstants.REPORT_NUMBER);
395         this.loadTestData(testTarget);
396         this.updateSystemParameters("");
397 
398         effortCertificationExtractService.extract(fiscalYear, reportNumber);
399 
400         List<EffortCertificationDocumentBuild> documentBuildList = TestDataPreparator.findMatching(EffortCertificationDocumentBuild.class, properties, testTarget + EffortTestDataPropertyConstants.DOCUMENT_CLEANUP, documentFieldNames, deliminator);
401         int numberOfExpectedDocuments = Integer.valueOf(properties.getProperty(testTarget + EffortTestDataPropertyConstants.NUM_OF_EXPECTED_DOCUMENTS));
402 
403         assertEquals(numberOfExpectedDocuments, documentBuildList.size());
404     }
405 
406     /**
407      * check if the employees without positive payments cannot be selected
408      */
409     public void testBalanceSelection_NonpositiveTotalAmount() throws Exception {
410         String testTarget = "balanceSelection.nonpositiveTotalAmount.";
411         Integer fiscalYear = Integer.valueOf(StringUtils.trim(properties.getProperty(testTarget + EffortTestDataPropertyConstants.FISCAL_YEAR)));
412         String reportNumber = properties.getProperty(testTarget + EffortTestDataPropertyConstants.REPORT_NUMBER);
413         this.loadTestData(testTarget);
414         this.updateSystemParameters("");
415 
416         effortCertificationExtractService.extract(fiscalYear, reportNumber);
417 
418         List<EffortCertificationDocumentBuild> documentBuildList = TestDataPreparator.findMatching(EffortCertificationDocumentBuild.class, properties, testTarget + EffortTestDataPropertyConstants.DOCUMENT_CLEANUP, documentFieldNames, deliminator);
419         int numberOfExpectedDocuments = Integer.valueOf(properties.getProperty(testTarget + EffortTestDataPropertyConstants.NUM_OF_EXPECTED_DOCUMENTS));
420 
421         assertEquals(numberOfExpectedDocuments, documentBuildList.size());
422     }
423 
424     /**
425      * check if the documents are generated correctly
426      */
427     public void testDocumentGeneration() throws Exception {
428         String testTarget = "documentGeneration.";
429         Integer fiscalYear = Integer.valueOf(StringUtils.trim(properties.getProperty(testTarget + EffortTestDataPropertyConstants.FISCAL_YEAR)));
430         String reportNumber = properties.getProperty(testTarget + EffortTestDataPropertyConstants.REPORT_NUMBER);
431         this.loadTestData(testTarget);
432         this.updateSystemParameters(testTarget);
433 
434         effortCertificationExtractService.extract(fiscalYear, reportNumber);
435 
436         List<EffortCertificationDocumentBuild> documentBuildList = TestDataPreparator.findMatching(EffortCertificationDocumentBuild.class, properties, testTarget + EffortTestDataPropertyConstants.DOCUMENT_CLEANUP, documentFieldNames, deliminator);
437 
438         int numberOfExpectedDocuments = Integer.valueOf(properties.getProperty(testTarget + EffortTestDataPropertyConstants.NUM_OF_EXPECTED_DOCUMENTS));
439         List<EffortCertificationDocumentBuild> expectedDocumentBuildList = TestDataPreparator.buildExpectedValueList(EffortCertificationDocumentBuild.class, properties, testTarget + EffortTestDataPropertyConstants.EXPECTED_DOCUMENT, documentFieldNames, deliminator, numberOfExpectedDocuments);
440 
441         assertEquals(numberOfExpectedDocuments, documentBuildList.size());
442 
443         List<String> documentKeyFields = ObjectUtil.split(documentFieldNames, deliminator);
444         documentKeyFields.remove(KFSPropertyConstants.DOCUMENT_NUMBER);
445         assertTrue(TestDataPreparator.hasSameElements(documentBuildList, expectedDocumentBuildList, documentKeyFields));
446 
447         List<EffortCertificationDetailBuild> detailLinesBuild = new ArrayList<EffortCertificationDetailBuild>();
448         for (EffortCertificationDocumentBuild document : documentBuildList) {
449             detailLinesBuild.addAll(document.getEffortCertificationDetailLinesBuild());
450         }
451 
452         int numberOfExpectedDetailLines = Integer.valueOf(properties.getProperty(testTarget + EffortTestDataPropertyConstants.NUM_OF_EXPECTED_DETAILS));
453         List<EffortCertificationDetailBuild> expectedDetailLines = TestDataPreparator.buildExpectedValueList(EffortCertificationDetailBuild.class, properties, testTarget + EffortTestDataPropertyConstants.EXPECTED_DETAIL, detailFieldNames, deliminator, numberOfExpectedDetailLines);
454 
455         List<String> detailLineKeyFields = ObjectUtil.split(detailFieldNames, deliminator);
456         detailLineKeyFields.remove(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR);
457         assertTrue(TestDataPreparator.hasSameElements(detailLinesBuild, expectedDetailLines, detailLineKeyFields));
458     }
459 
460     /**
461      * check if the employees paid by federal fundings can be selected when federal fund only indicator is enabled
462      */
463     public void testFederalGrantOnly_HasFederalGrant() throws Exception {
464         String testTarget = "federalGrantOnly.hasFederalGrant.";
465         Integer fiscalYear = Integer.valueOf(StringUtils.trim(properties.getProperty(testTarget + EffortTestDataPropertyConstants.FISCAL_YEAR)));
466         String reportNumber = properties.getProperty(testTarget + EffortTestDataPropertyConstants.REPORT_NUMBER);
467         this.loadTestData(testTarget);
468         this.updateSystemParameters(testTarget);
469 
470         effortCertificationExtractService.extract(fiscalYear, reportNumber);
471 
472         List<EffortCertificationDocumentBuild> documentBuildList = TestDataPreparator.findMatching(EffortCertificationDocumentBuild.class, properties, testTarget + EffortTestDataPropertyConstants.DOCUMENT_CLEANUP, documentFieldNames, deliminator);
473 
474         int numberOfExpectedDocuments = Integer.valueOf(properties.getProperty(testTarget + EffortTestDataPropertyConstants.NUM_OF_EXPECTED_DOCUMENTS));
475         List<EffortCertificationDocumentBuild> expectedDocumentBuildList = TestDataPreparator.buildExpectedValueList(EffortCertificationDocumentBuild.class, properties, testTarget + EffortTestDataPropertyConstants.EXPECTED_DOCUMENT, documentFieldNames, deliminator, numberOfExpectedDocuments);
476 
477         assertEquals(numberOfExpectedDocuments, documentBuildList.size());
478 
479         List<String> documentKeyFields = ObjectUtil.split(documentFieldNames, deliminator);
480         documentKeyFields.remove(KFSPropertyConstants.DOCUMENT_NUMBER);
481         assertTrue(TestDataPreparator.hasSameElements(documentBuildList, expectedDocumentBuildList, documentKeyFields));
482 
483         List<EffortCertificationDetailBuild> detailLinesBuild = new ArrayList<EffortCertificationDetailBuild>();
484         for (EffortCertificationDocumentBuild document : documentBuildList) {
485             detailLinesBuild.addAll(document.getEffortCertificationDetailLinesBuild());
486         }
487 
488         int numberOfExpectedDetailLines = Integer.valueOf(properties.getProperty(testTarget + EffortTestDataPropertyConstants.NUM_OF_EXPECTED_DETAILS));
489         List<EffortCertificationDetailBuild> expectedDetailLines = TestDataPreparator.buildExpectedValueList(EffortCertificationDetailBuild.class, properties, testTarget + EffortTestDataPropertyConstants.EXPECTED_DETAIL, detailFieldNames, deliminator, numberOfExpectedDetailLines);
490 
491         assertEquals(expectedDetailLines.size(), detailLinesBuild.size());
492 
493         List<String> detailLineKeyFields = ObjectUtil.split(detailFieldNames, deliminator);
494         detailLineKeyFields.remove(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR);
495         assertTrue(TestDataPreparator.hasSameElements(detailLinesBuild, expectedDetailLines, detailLineKeyFields));
496     }
497 
498     /**
499      * check if the employees not paid by federal fundings cannot be selected when federal fund only indicator is enabled
500      */
501     public void testFederalGrantOnly_NoFederalGrant() throws Exception {
502         String testTarget = "federalGrantOnly.noFederalGrant.";
503         Integer fiscalYear = Integer.valueOf(StringUtils.trim(properties.getProperty(testTarget + EffortTestDataPropertyConstants.FISCAL_YEAR)));
504         String reportNumber = properties.getProperty(testTarget + EffortTestDataPropertyConstants.REPORT_NUMBER);
505         this.loadTestData(testTarget);
506         this.updateSystemParameters(testTarget);
507 
508         effortCertificationExtractService.extract(fiscalYear, reportNumber);
509 
510         List<EffortCertificationDocumentBuild> documentBuildList = TestDataPreparator.findMatching(EffortCertificationDocumentBuild.class, properties, testTarget + EffortTestDataPropertyConstants.DOCUMENT_CLEANUP, documentFieldNames, deliminator);
511 
512         int numberOfExpectedDocuments = Integer.valueOf(properties.getProperty(testTarget + EffortTestDataPropertyConstants.NUM_OF_EXPECTED_DOCUMENTS));
513         assertEquals(numberOfExpectedDocuments, documentBuildList.size());
514     }
515 
516     /**
517      * load test data into database before a test case starts
518      *
519      * @param testTarget the target test case
520      */
521     private void loadTestData(String testTarget) throws Exception {
522         TestDataPreparator.doCleanUpWithoutReference(ledgerEntryClass, properties, testTarget + EffortTestDataPropertyConstants.DATA_CLEANUP, entryFieldNames, deliminator);
523         TestDataPreparator.doCleanUpWithoutReference(ledgerBalanceClass, properties, testTarget + EffortTestDataPropertyConstants.DATA_CLEANUP, balanceFieldNames, deliminator);
524         TestDataPreparator.doCleanUpWithReference(EffortCertificationDocument.class, properties, testTarget + EffortTestDataPropertyConstants.DOCUMENT_CLEANUP, documentFieldNames, deliminator);
525 
526         int numberOfEntries = Integer.valueOf(properties.getProperty(testTarget + EffortTestDataPropertyConstants.NUM_OF_ENTRIES));
527         List<LaborLedgerEntry> ledgerEntries = TestDataPreparator.buildTestDataList(ledgerEntryClass, properties, testTarget + EffortTestDataPropertyConstants.INPUT_ENTRY, entryFieldNames, deliminator, numberOfEntries);
528         TestDataPreparator.persistDataObject(ledgerEntries);
529 
530         int numberOfBalances = Integer.valueOf(properties.getProperty(testTarget + EffortTestDataPropertyConstants.NUM_OF_BALANCES));
531         List<LaborLedgerBalance> ledgerBalances = TestDataPreparator.buildTestDataList(ledgerBalanceClass, properties, testTarget + EffortTestDataPropertyConstants.INPUT_BALANCE, balanceFieldNames, deliminator, numberOfBalances);
532         TestDataPreparator.persistDataObject(ledgerBalances);
533 
534         EffortCertificationReportDefinition reportDefinition = this.buildReportDefinition("");
535         reportDefinition = TestDataPreparator.persistDataObject(reportDefinition);
536     }
537 
538     /**
539      * construct a ledger balance and persist it
540      *
541      * @param testTarget the given test target that specifies the test data being used
542      * @return a ledger balance
543      */
544     private LaborLedgerBalance buildLedgerBalance(String testTarget) {
545         return TestDataPreparator.buildTestDataObject(ledgerBalanceClass, properties, testTarget + EffortTestDataPropertyConstants.INPUT_BALANCE, balanceFieldNames, deliminator);
546     }
547 
548     /**
549      * build a report defintion object from the given test target
550      *
551      * @param testTarget the given test target that specifies the test data being used
552      * @return a report defintion object
553      */
554     private EffortCertificationReportDefinition buildReportDefinition(String testTarget) {
555         return TestDataPreparator.buildTestDataObject(EffortCertificationReportDefinition.class, properties, testTarget + EffortTestDataPropertyConstants.REPORT_DEFINITION_FIELD_VALUES, reportDefinitionFieldNames, deliminator);
556     }
557 
558     /**
559      * build an Effort Certification Document object from the given test target
560      *
561      * @param testTarget the given test target that specifies the test data being used
562      * @return an Effort Certification Document object
563      */
564     private EffortCertificationDocument buildDocument(String testTarget) {
565         return TestDataPreparator.buildTestDataObject(EffortCertificationDocument.class, properties, testTarget + EffortTestDataPropertyConstants.DOCUMENT, documentFieldNames, deliminator);
566     }
567 
568     /**
569      * update the system parameters
570      *
571      * @param testTarget the given test target that specifies the test data being used
572      */
573     private void updateSystemParameters(String testTarget) {
574         Map<String, String> fieldValues = new HashMap<String, String>();
575         fieldValues.put("namespaceCode", KFSConstants.OptionalModuleNamespaces.EFFORT_COMMITTMENT);
576         fieldValues.put("componentCode", EffortCertificationExtractStep.class.getSimpleName());
577         fieldValues.put("applicationId", KFSConstants.APPLICATION_NAMESPACE_CODE);
578 
579 
580         List<ParameterBo> parameters = (List<ParameterBo>) businessObjectService.findMatching(ParameterBo.class, fieldValues);
581         for (ParameterBo param : parameters) {
582             String name = param.getName();
583 
584             String propertyKey = testTarget + "systemParameter." + name;
585             String propertyValue = StringUtils.trim(properties.getProperty(propertyKey));
586 
587             if (propertyValue != null) {
588                 // NOTE: parameter service is caching the searching results that may cause the tests unstable.
589                 TestUtils.setSystemParameter(EffortCertificationExtractStep.class, name, propertyValue);
590             }
591         }
592     }
593 }