1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.kuali.kfs.module.ld.businessobject.lookup;
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.kuali.kfs.gl.Constant;
28 import org.kuali.kfs.gl.web.TestDataGenerator;
29 import org.kuali.kfs.module.ld.LaborConstants;
30 import org.kuali.kfs.module.ld.businessobject.AccountStatusCurrentFunds;
31 import org.kuali.kfs.module.ld.businessobject.LedgerBalance;
32 import org.kuali.kfs.module.ld.service.LaborInquiryOptionsService;
33 import org.kuali.kfs.sys.ConfigureContext;
34 import org.kuali.kfs.sys.KFSPropertyConstants;
35 import org.kuali.kfs.sys.ObjectUtil;
36 import org.kuali.kfs.sys.businessobject.lookup.LookupableSpringContext;
37 import org.kuali.kfs.sys.context.KualiTestBase;
38 import org.kuali.kfs.sys.context.SpringContext;
39 import org.kuali.kfs.sys.context.TestUtils;
40 import org.kuali.rice.kns.lookup.LookupableHelperService;
41 import org.kuali.rice.krad.service.BusinessObjectService;
42 import org.kuali.rice.krad.service.PersistenceService;
43
44
45
46
47 @ConfigureContext
48 public class CurrentFundsLookupableHelperServiceTest extends KualiTestBase {
49 private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(CurrentFundsLookupableHelperServiceTest.class);
50 private BusinessObjectService businessObjectService;
51 private LookupableHelperService lookupableHelperService;
52 private PersistenceService persistenceService;
53
54 private Properties properties;
55 private String fieldNames, documentFieldNames;
56 private String deliminator;
57 private int currentFundsNumberOfTestData;
58 private int currentFundsExpectedInsertion;
59
60
61
62
63 @Override
64 protected void setUp() throws Exception {
65 super.setUp();
66
67 businessObjectService = SpringContext.getBean(BusinessObjectService.class);
68
69 lookupableHelperService = LookupableSpringContext.getLookupableHelperService(LaborConstants.CURRENT_FUNDS_LOOKUP_HELPER_SRVICE_NAME);
70 lookupableHelperService.setBusinessObjectClass(AccountStatusCurrentFunds.class);
71
72
73 Map keys = new HashMap();
74 keys.put(KFSPropertyConstants.ACCOUNT_NUMBER, "6044906");
75 keys.put(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, TestUtils.getFiscalYearForTesting().toString());
76 keys.put(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, "BA");
77 businessObjectService.deleteMatching(LedgerBalance.class, keys);
78 }
79
80
81
82
83
84
85
86 public void testGetSearchResults() throws Exception {
87 insertCurrentFundsRecords();
88 AccountStatusCurrentFunds accountStatusCurrentFunds = new AccountStatusCurrentFunds();
89 accountStatusCurrentFunds.setAccountNumber("6044906");
90 accountStatusCurrentFunds.setUniversityFiscalYear(TestUtils.getFiscalYearForTesting());
91 accountStatusCurrentFunds.setChartOfAccountsCode("BA");
92
93
94 Map fieldValues = buildFieldValues(accountStatusCurrentFunds, this.getLookupFields(false));
95
96
97 getInquiryOptionsService().getConsolidationField(lookupableHelperService.getRows()).setPropertyValue(Constant.DETAIL);
98 fieldValues.put(Constant.CONSOLIDATION_OPTION, Constant.DETAIL);
99
100 List<String> groupByList = new ArrayList<String>();
101 List<AccountStatusCurrentFunds> searchResults = (List<AccountStatusCurrentFunds>) lookupableHelperService.getSearchResults(fieldValues);
102
103
104 for (AccountStatusCurrentFunds accountStatusCurrentFundsReturn : searchResults) {
105 assertTrue((accountStatusCurrentFundsReturn.getAccountNumber().equals(accountStatusCurrentFunds.getAccountNumber()) &&
106 accountStatusCurrentFundsReturn.getUniversityFiscalYear().equals(accountStatusCurrentFunds.getUniversityFiscalYear()) &&
107 accountStatusCurrentFundsReturn.getChartOfAccountsCode().equals(accountStatusCurrentFunds.getChartOfAccountsCode())));
108 }
109
110 if (searchResults != null) {
111 System.out.println("Results Size:" + searchResults.size());
112 }
113
114
115 assertEquals(this.currentFundsExpectedInsertion,searchResults.size());
116 }
117
118
119
120
121
122
123
124 public void testGetSearchResultsConsolidated() throws Exception {
125 insertCurrentFundsRecords();
126 AccountStatusCurrentFunds accountStatusCurrentFunds = new AccountStatusCurrentFunds();
127 accountStatusCurrentFunds.setAccountNumber("6044906");
128 accountStatusCurrentFunds.setUniversityFiscalYear(TestUtils.getFiscalYearForTesting());
129 accountStatusCurrentFunds.setChartOfAccountsCode("BA");
130
131
132 Map fieldValues = buildFieldValues(accountStatusCurrentFunds, this.getLookupFields(false));
133
134
135 getInquiryOptionsService().getConsolidationField(lookupableHelperService.getRows()).setPropertyValue(Constant.CONSOLIDATION);
136 fieldValues.put(Constant.CONSOLIDATION_OPTION, Constant.CONSOLIDATION);
137
138 List<String> groupByList = new ArrayList<String>();
139 List<AccountStatusCurrentFunds> searchResults = (List<AccountStatusCurrentFunds>) lookupableHelperService.getSearchResults(fieldValues);
140
141
142 for (AccountStatusCurrentFunds accountStatusCurrentFundsReturn : searchResults) {
143 assertFalse(!(accountStatusCurrentFundsReturn.getAccountNumber().equals(accountStatusCurrentFunds.getAccountNumber()) &&
144 accountStatusCurrentFundsReturn.getUniversityFiscalYear().equals(accountStatusCurrentFunds.getUniversityFiscalYear()) &&
145 accountStatusCurrentFundsReturn.getChartOfAccountsCode().equals(accountStatusCurrentFunds.getChartOfAccountsCode())));
146 }
147
148 if (searchResults != null) {
149 LOG.debug("Results Size:" + searchResults.size());
150 }
151
152
153 assertEquals(this.currentFundsExpectedInsertion,searchResults.size());
154 }
155
156
157
158
159
160
161
162
163 private Map<String, String> buildFieldValues(AccountStatusCurrentFunds accountStatusCurrentFunds, List<String> lookupFields) {
164 Map<String, String> fieldValues = new HashMap<String, String>();
165
166 Map<String, Object> tempFieldValues = ObjectUtil.buildPropertyMap(accountStatusCurrentFunds, lookupFields);
167 for (String key : tempFieldValues.keySet()) {
168 fieldValues.put(key, tempFieldValues.get(key).toString());
169 }
170 return fieldValues;
171 }
172
173
174
175
176
177
178
179 private List<String> getLookupFields(boolean isExtended) {
180 List<String> lookupFields = new ArrayList<String>();
181
182 lookupFields.add(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR);
183 lookupFields.add(KFSPropertyConstants.ACCOUNT_NUMBER);
184 lookupFields.add(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
185
186 return lookupFields;
187 }
188
189
190
191
192 protected void insertCurrentFundsRecords() {
193 String messageFileName = "org/kuali/kfs/module/ld/testdata/message.properties";
194 String propertiesFileName = "org/kuali/kfs/module/ld/testdata/accountStatusCurrentFunds.properties";
195
196 properties = (new TestDataGenerator(propertiesFileName, messageFileName)).getProperties();
197 fieldNames = properties.getProperty("fieldNames");
198 documentFieldNames = properties.getProperty("fieldNames");
199 deliminator = properties.getProperty("deliminator");
200
201 TestDataGenerator testDataGenerator = new TestDataGenerator(propertiesFileName, messageFileName);
202
203 businessObjectService = SpringContext.getBean(BusinessObjectService.class);
204 persistenceService = SpringContext.getBean(PersistenceService.class);
205
206 int numberOfDocuments = Integer.valueOf(properties.getProperty("getAccountStatusCurrentFunds.numOfData"));
207 List<LedgerBalance> inputDataList = new ArrayList<LedgerBalance>();
208 for (int i = 1; i <= numberOfDocuments; i++) {
209 String propertyKey = "getAccountStatusCurrentFunds.testData" + i;
210 LedgerBalance inputData = new LedgerBalance();
211 ObjectUtil.populateBusinessObject(inputData, properties, propertyKey, documentFieldNames, deliminator);
212 inputData.setUniversityFiscalYear(TestUtils.getFiscalYearForTesting());
213 inputDataList.add(inputData);
214 }
215 String testTarget = "getAccountStatusCurrentFunds.";
216 this.currentFundsNumberOfTestData = Integer.valueOf(properties.getProperty(testTarget + "numOfData"));
217 this.currentFundsExpectedInsertion = Integer.valueOf(properties.getProperty(testTarget + "expectedInsertion"));
218 businessObjectService.save(inputDataList);
219
220 System.out.println("*** RECORDS INSERTED!!!!");
221 }
222
223 private LaborInquiryOptionsService getInquiryOptionsService() {
224 return SpringContext.getBean(LaborInquiryOptionsService.class);
225 }
226 }