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.ld.batch.service.impl;
20  
21  import java.util.Arrays;
22  import java.util.Date;
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.gl.batch.service.PostTransaction;
29  import org.kuali.kfs.gl.businessobject.OriginEntryGroup;
30  import org.kuali.kfs.module.ld.businessobject.LaborGeneralLedgerEntry;
31  import org.kuali.kfs.module.ld.service.LaborGeneralLedgerEntryService;
32  import org.kuali.kfs.module.ld.service.LaborOriginEntryGroupService;
33  import org.kuali.kfs.module.ld.testdata.LaborTestDataPropertyConstants;
34  import org.kuali.kfs.sys.ConfigureContext;
35  import org.kuali.kfs.sys.ObjectUtil;
36  import org.kuali.kfs.sys.TestDataPreparator;
37  import org.kuali.kfs.sys.context.KualiTestBase;
38  import org.kuali.kfs.sys.context.SpringContext;
39  import org.kuali.rice.core.api.datetime.DateTimeService;
40  import org.kuali.rice.krad.service.BusinessObjectService;
41  
42  @ConfigureContext
43  public class LaborGLLedgerEntryPosterTest extends KualiTestBase {
44  
45      private Properties properties;
46      private String fieldNames;
47      private String deliminator;
48      private List<String> keyFieldList;
49      private Map fieldValues;
50      private OriginEntryGroup group1;
51      private Date today;
52  
53      private BusinessObjectService businessObjectService;
54      private PostTransaction laborGLLedgerEntryPoster;
55      private LaborOriginEntryGroupService originEntryGroupService;
56      private LaborGeneralLedgerEntryService laborGeneralLedgerEntryService;
57  
58      @Override
59      public void setUp() throws Exception {
60          super.setUp();
61          
62          String messageFileName = LaborTestDataPropertyConstants.TEST_DATA_PACKAGE_NAME + "/message.properties";
63          String propertiesFileName = LaborTestDataPropertyConstants.TEST_DATA_PACKAGE_NAME + "/laborGLLedgerEntryPoster.properties";
64          
65          properties = TestDataPreparator.loadPropertiesFromClassPath(propertiesFileName);
66          
67          fieldNames = properties.getProperty("fieldNames");
68          deliminator = properties.getProperty("deliminator");
69          keyFieldList = Arrays.asList(StringUtils.split(fieldNames, deliminator));
70  
71          laborGLLedgerEntryPoster = SpringContext.getBean(PostTransaction.class,"laborGLLedgerEntryPoster");
72          businessObjectService = SpringContext.getBean(BusinessObjectService.class);
73          originEntryGroupService = SpringContext.getBean(LaborOriginEntryGroupService.class);
74          laborGeneralLedgerEntryService = SpringContext.getBean(LaborGeneralLedgerEntryService.class);
75          DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class);
76  
77          // TODO:- commented out
78          //group1 = originEntryGroupService.createGroup(dateTimeService.getCurrentSqlDate(), LABOR_MAIN_POSTER_VALID, false, false, false);
79          today = dateTimeService.getCurrentDate();
80  
81          LaborGeneralLedgerEntry cleanup = new LaborGeneralLedgerEntry();
82          ObjectUtil.populateBusinessObject(cleanup, properties, "dataCleanup", fieldNames, deliminator);
83          fieldValues = ObjectUtil.buildPropertyMap(cleanup, Arrays.asList(StringUtils.split(fieldNames, deliminator)));
84          businessObjectService.deleteMatching(LaborGeneralLedgerEntry.class, fieldValues);
85      }
86  
87      public void testPost() throws Exception {
88          // TODO:- need to change using file
89  //        int numberOfTestData = Integer.valueOf(properties.getProperty("post.numOfData"));
90  //        int expectedMaxSequenceNumber = Integer.valueOf(properties.getProperty("post.expectedMaxSequenceNumber"));
91  //        int expectedInsertion = Integer.valueOf(properties.getProperty("post.expectedInsertion"));
92  //
93  //        List<LaborOriginEntry> transactionList = LaborTestDataPreparator.getLaborOriginEntryList(properties, "post.testData", numberOfTestData, group1);
94  //        Map<String, Integer> operationType = new HashMap<String, Integer>();
95  //
96  //        for (LaborOriginEntry transaction : transactionList) {
97  //            String operation = laborGLLedgerEntryPoster.post(transaction, 0, today);
98  //            Integer currentNumber = operationType.get(operation);
99  //            Integer numberOfOperation = currentNumber != null ? currentNumber + 1 : 1;
100 //            operationType.put(operation, numberOfOperation);
101 //        }
102 //
103 //        Collection returnValues = businessObjectService.findMatching(LaborGeneralLedgerEntry.class, fieldValues);
104 //        assertEquals(numberOfTestData, returnValues.size());
105 //
106 //        assertEquals(1, operationType.size());
107 //        assertEquals(expectedInsertion, operationType.get(KFSConstants.OperationType.INSERT).intValue());
108 //
109 //        LaborGeneralLedgerEntry expected1 = new LaborGeneralLedgerEntry();
110 //        ObjectUtil.populateBusinessObject(expected1, properties, "post.expected1", fieldNames, deliminator);
111 //        assertEquals(expectedMaxSequenceNumber, laborGeneralLedgerEntryService.getMaxSequenceNumber(expected1).intValue());
112 //
113 //        LaborGeneralLedgerEntry expected2 = new LaborGeneralLedgerEntry();
114 //        ObjectUtil.populateBusinessObject(expected2, properties, "post.expected2", fieldNames, deliminator);
115 //        assertEquals(expectedMaxSequenceNumber, laborGeneralLedgerEntryService.getMaxSequenceNumber(expected2).intValue());
116 //
117 //        LaborGeneralLedgerEntry expected3 = new LaborGeneralLedgerEntry();
118 //        ObjectUtil.populateBusinessObject(expected3, properties, "post.expected3", fieldNames, deliminator);
119 //        assertEquals(expectedMaxSequenceNumber, laborGeneralLedgerEntryService.getMaxSequenceNumber(expected3).intValue());
120     }
121 }