001: /*
002: * Copyright 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.labor.service;
017:
018: import static org.kuali.module.gl.bo.OriginEntrySource.LABOR_SCRUBBER_VALID;
019:
020: import java.sql.Date;
021: import java.util.ArrayList;
022: import java.util.Arrays;
023: import java.util.Collection;
024: import java.util.HashMap;
025: import java.util.List;
026: import java.util.Map;
027: import java.util.Properties;
028:
029: import org.apache.commons.lang.StringUtils;
030: import org.kuali.core.service.BusinessObjectService;
031: import org.kuali.core.service.DateTimeService;
032: import org.kuali.core.service.PersistenceService;
033: import org.kuali.core.util.KualiDecimal;
034: import org.kuali.kfs.KFSPropertyConstants;
035: import org.kuali.kfs.context.KualiTestBase;
036: import org.kuali.kfs.context.SpringContext;
037: import org.kuali.module.gl.bo.OriginEntryGroup;
038: import org.kuali.module.gl.service.OriginEntryGroupService;
039: import org.kuali.module.gl.web.TestDataGenerator;
040: import org.kuali.module.labor.bo.LaborGeneralLedgerEntry;
041: import org.kuali.module.labor.bo.LaborOriginEntry;
042: import org.kuali.module.labor.bo.LedgerBalance;
043: import org.kuali.module.labor.bo.LedgerEntry;
044: import org.kuali.module.labor.util.ObjectUtil;
045: import org.kuali.module.labor.util.TestDataPreparator;
046: import org.kuali.module.labor.util.testobject.LaborGeneralLedgerEntryForTesting;
047: import org.kuali.module.labor.util.testobject.LedgerBalanceForTesting;
048: import org.kuali.module.labor.util.testobject.LedgerEntryForTesting;
049: import org.kuali.module.labor.util.testobject.OriginEntryGroupForTesting;
050: import org.kuali.test.ConfigureContext;
051:
052: @ConfigureContext
053: public class LaborPosterServiceTest extends KualiTestBase {
054:
055: private Properties properties;
056: private String fieldNames;
057: private String deliminator;
058: private OriginEntryGroup groupToPost;
059: private Map fieldValues, groupFieldValues;
060:
061: private LaborOriginEntryService laborOriginEntryService;
062: private OriginEntryGroupService originEntryGroupService;
063: private BusinessObjectService businessObjectService;
064: private LaborPosterService laborPosterService;
065: private PersistenceService persistenceService;
066:
067: @Override
068: public void setUp() throws Exception {
069: super .setUp();
070: String messageFileName = "test/src/org/kuali/module/labor/testdata/message.properties";
071: String propertiesFileName = "test/src/org/kuali/module/labor/testdata/laborPosterService.properties";
072:
073: properties = (new TestDataGenerator(propertiesFileName,
074: messageFileName)).getProperties();
075: fieldNames = properties.getProperty("fieldNames");
076: deliminator = properties.getProperty("deliminator");
077:
078: laborOriginEntryService = SpringContext
079: .getBean(LaborOriginEntryService.class);
080: originEntryGroupService = SpringContext
081: .getBean(OriginEntryGroupService.class);
082: businessObjectService = SpringContext
083: .getBean(BusinessObjectService.class);
084: laborPosterService = SpringContext
085: .getBean(LaborPosterService.class);
086: persistenceService = SpringContext
087: .getBean(PersistenceService.class);
088:
089: groupFieldValues = new HashMap();
090: groupFieldValues.put(KFSPropertyConstants.SOURCE_CODE,
091: LABOR_SCRUBBER_VALID);
092: originEntryGroupService.deleteOlderGroups(0);
093: businessObjectService.deleteMatching(OriginEntryGroup.class,
094: groupFieldValues);
095:
096: Date today = (SpringContext.getBean(DateTimeService.class))
097: .getCurrentSqlDate();
098: groupToPost = originEntryGroupService.createGroup(today,
099: LABOR_SCRUBBER_VALID, true, true, false);
100:
101: LaborOriginEntry cleanup = new LaborOriginEntry();
102: ObjectUtil.populateBusinessObject(cleanup, properties,
103: "dataCleanup", fieldNames, deliminator);
104: fieldValues = ObjectUtil.buildPropertyMap(cleanup, Arrays
105: .asList(StringUtils.split(fieldNames, deliminator)));
106: businessObjectService.deleteMatching(LaborOriginEntry.class,
107: fieldValues);
108: businessObjectService.deleteMatching(LedgerEntry.class,
109: fieldValues);
110: businessObjectService.deleteMatching(
111: LaborGeneralLedgerEntry.class, fieldValues);
112: businessObjectService.deleteMatching(LedgerBalance.class,
113: fieldValues);
114: }
115:
116: public void testPostAsLedgerEntry() throws Exception {
117: String testTarget = "postAsLedgerEntry.";
118: int numberOfTestData = Integer.valueOf(properties
119: .getProperty(testTarget + "numOfData"));
120: int expectedNumOfData = Integer.valueOf(properties
121: .getProperty(testTarget + "expectedNumOfData"));
122:
123: List<LaborOriginEntry> inputDataList = getInputDataList(
124: testTarget + "testData", numberOfTestData, groupToPost);
125: businessObjectService.save(inputDataList);
126:
127: for (LaborOriginEntry entry : inputDataList) {
128: persistenceService.retrieveNonKeyFields(entry);
129: }
130:
131: laborPosterService.postMainEntries();
132:
133: Collection ledgerEntries = businessObjectService.findMatching(
134: LedgerEntry.class, fieldValues);
135: List expectedDataList = TestDataPreparator
136: .buildExpectedValueList(LedgerEntryForTesting.class,
137: properties, testTarget + "expected",
138: fieldNames, deliminator, expectedNumOfData);
139: for (Object entry : ledgerEntries) {
140: LedgerEntryForTesting ledgerEntryForTesting = new LedgerEntryForTesting();
141: ObjectUtil.buildObject(ledgerEntryForTesting, entry);
142: assertTrue(expectedDataList.contains(ledgerEntryForTesting));
143: }
144: assertEquals(expectedNumOfData, ledgerEntries.size());
145: }
146:
147: public void testPostAsLedgerBalance() throws Exception {
148: String testTarget = "postAsLedgerBalance.";
149: int numberOfTestData = Integer.valueOf(properties
150: .getProperty(testTarget + "numOfData"));
151: int expectedNumOfData = Integer.valueOf(properties
152: .getProperty(testTarget + "expectedNumOfData"));
153: KualiDecimal expectedMonth7Amount = new KualiDecimal(properties
154: .getProperty(testTarget + "expectedMonth7Amount"));
155: KualiDecimal expectedMonth8Amount = new KualiDecimal(properties
156: .getProperty(testTarget + "expectedMonth8Amount"));
157: KualiDecimal expectedAnnualBalanceAmount = new KualiDecimal(
158: properties.getProperty(testTarget
159: + "expectedAnnualBalanceAmount"));
160:
161: List<LaborOriginEntry> inputDataList = getInputDataList(
162: testTarget + "testData", numberOfTestData, groupToPost);
163: businessObjectService.save(inputDataList);
164:
165: for (LaborOriginEntry entry : inputDataList) {
166: persistenceService.retrieveNonKeyFields(entry);
167: }
168:
169: laborPosterService.postMainEntries();
170:
171: Collection ledgerEntries = businessObjectService.findMatching(
172: LedgerBalance.class, fieldValues);
173: List expectedDataList = TestDataPreparator
174: .buildExpectedValueList(LedgerBalanceForTesting.class,
175: properties, testTarget + "expected",
176: expectedNumOfData);
177: for (Object entry : ledgerEntries) {
178: LedgerBalanceForTesting ledgerBalanceForTesting = new LedgerBalanceForTesting();
179: ObjectUtil.buildObject(ledgerBalanceForTesting, entry);
180:
181: assertTrue(expectedDataList
182: .contains(ledgerBalanceForTesting));
183: assertEquals(expectedMonth7Amount, ledgerBalanceForTesting
184: .getMonth7Amount());
185: assertEquals(expectedMonth8Amount, ledgerBalanceForTesting
186: .getMonth8Amount());
187: assertEquals(expectedAnnualBalanceAmount,
188: ledgerBalanceForTesting
189: .getAccountLineAnnualBalanceAmount());
190: }
191: assertEquals(expectedNumOfData, ledgerEntries.size());
192: }
193:
194: public void testPostLaborGLEntries() throws Exception {
195: String testTarget = "postLaborGLEntries.";
196: int numberOfTestData = Integer.valueOf(properties
197: .getProperty(testTarget + "numOfData"));
198: int expectedNumOfData = Integer.valueOf(properties
199: .getProperty(testTarget + "expectedNumOfData"));
200:
201: List<LaborOriginEntry> inputDataList = getInputDataList(
202: testTarget + "testData", numberOfTestData, groupToPost);
203: businessObjectService.save(inputDataList);
204:
205: for (LaborOriginEntry entry : inputDataList) {
206: persistenceService.retrieveNonKeyFields(entry);
207: }
208:
209: laborPosterService.postMainEntries();
210:
211: Collection GLEntry = businessObjectService.findMatching(
212: LaborGeneralLedgerEntry.class, fieldValues);
213: List expectedDataList = TestDataPreparator
214: .buildExpectedValueList(
215: LaborGeneralLedgerEntryForTesting.class,
216: properties, testTarget + "expected",
217: expectedNumOfData);
218: for (Object entry : GLEntry) {
219: LaborGeneralLedgerEntryForTesting GLEntryForTesting = new LaborGeneralLedgerEntryForTesting();
220: ObjectUtil.buildObject(GLEntryForTesting, entry);
221:
222: assertTrue(expectedDataList.contains(GLEntryForTesting));
223: }
224: assertEquals(expectedNumOfData, GLEntry.size());
225: }
226:
227: public void testUpdateOriginEntryGroup() throws Exception {
228: String testTarget = "updateOriginEntryGroup.";
229: int numberOfTestData = Integer.valueOf(properties
230: .getProperty(testTarget + "numOfData"));
231: int expectedNumOfData = Integer.valueOf(properties
232: .getProperty(testTarget + "expectedNumOfData"));
233: String groupFieldNames = properties.getProperty(testTarget
234: + "fieldNames");
235:
236: List<LaborOriginEntry> inputDataList = getInputDataList(
237: testTarget + "testData", numberOfTestData, groupToPost);
238: businessObjectService.save(inputDataList);
239:
240: for (LaborOriginEntry entry : inputDataList) {
241: persistenceService.retrieveNonKeyFields(entry);
242: }
243:
244: laborPosterService.postMainEntries();
245:
246: Collection originEntryGroups = businessObjectService
247: .findAll(OriginEntryGroup.class);
248: List expectedDataList = TestDataPreparator
249: .buildExpectedValueList(
250: OriginEntryGroupForTesting.class, properties,
251: testTarget + "expected", groupFieldNames,
252: deliminator, expectedNumOfData);
253: for (Object group : originEntryGroups) {
254: OriginEntryGroupForTesting originEntryGroupForTesting = new OriginEntryGroupForTesting();
255: ObjectUtil.buildObject(originEntryGroupForTesting, group);
256:
257: assertTrue(expectedDataList
258: .contains(originEntryGroupForTesting));
259: }
260: assertEquals(expectedNumOfData, originEntryGroups.size());
261: }
262:
263: public void testNotPostableEntries() throws Exception {
264: String testTarget = "notPostableEntries.";
265: int numberOfTestData = Integer.valueOf(properties
266: .getProperty(testTarget + "numOfData"));
267: int expectedNumOfGLEntry = Integer.valueOf(properties
268: .getProperty(testTarget + "expectedNumOfGLEntry"));
269: int expectedNumOfLedgerEntry = Integer.valueOf(properties
270: .getProperty(testTarget + "expectedNumOfLedgerEntry"));
271: int expectedNumOfLedgerBalance = Integer
272: .valueOf(properties.getProperty(testTarget
273: + "expectedNumOfLedgerBalance"));
274: int expectedNumOfOriginEntry = Integer.valueOf(properties
275: .getProperty(testTarget + "expectedNumOfOriginEntry"));
276:
277: List<LaborOriginEntry> inputDataList = getInputDataList(
278: testTarget + "testData", numberOfTestData, groupToPost);
279: businessObjectService.save(inputDataList);
280:
281: for (LaborOriginEntry entry : inputDataList) {
282: persistenceService.retrieveNonKeyFields(entry);
283: }
284:
285: laborPosterService.postMainEntries();
286:
287: Collection originEntries = businessObjectService.findMatching(
288: LaborOriginEntry.class, fieldValues);
289: assertEquals(expectedNumOfOriginEntry, originEntries.size());
290:
291: Collection ledgerEntries = businessObjectService.findMatching(
292: LedgerEntry.class, fieldValues);
293: assertEquals(expectedNumOfLedgerEntry, ledgerEntries.size());
294:
295: Collection ledgerBalances = businessObjectService.findMatching(
296: LedgerBalance.class, fieldValues);
297: assertEquals(expectedNumOfLedgerBalance, ledgerBalances.size());
298:
299: Collection GLEntries = businessObjectService.findMatching(
300: LaborGeneralLedgerEntry.class, fieldValues);
301: assertEquals(expectedNumOfGLEntry, GLEntries.size());
302: }
303:
304: public void testNotPostableEntriesToLaborGL() throws Exception {
305: String testTarget = "notPostableEntriesToLaborGL.";
306: int numberOfTestData = Integer.valueOf(properties
307: .getProperty(testTarget + "numOfData"));
308: int expectedNumOfGLEntry = Integer.valueOf(properties
309: .getProperty(testTarget + "expectedNumOfGLEntry"));
310: int expectedNumOfLedgerEntry = Integer.valueOf(properties
311: .getProperty(testTarget + "expectedNumOfLedgerEntry"));
312: int expectedNumOfOriginEntry = Integer.valueOf(properties
313: .getProperty(testTarget + "expectedNumOfOriginEntry"));
314:
315: List<LaborOriginEntry> inputDataList = getInputDataList(
316: testTarget + "testData", numberOfTestData, groupToPost);
317: businessObjectService.save(inputDataList);
318:
319: for (LaborOriginEntry entry : inputDataList) {
320: persistenceService.retrieveNonKeyFields(entry);
321: }
322:
323: laborPosterService.postMainEntries();
324:
325: Collection originEntries = businessObjectService.findMatching(
326: LaborOriginEntry.class, fieldValues);
327: assertEquals(expectedNumOfOriginEntry, originEntries.size());
328:
329: Collection ledgerEntries = businessObjectService.findMatching(
330: LedgerEntry.class, fieldValues);
331: assertEquals(expectedNumOfLedgerEntry, ledgerEntries.size());
332:
333: Collection<LaborGeneralLedgerEntry> GLEntries = businessObjectService
334: .findMatching(LaborGeneralLedgerEntry.class,
335: fieldValues);
336: assertEquals(expectedNumOfGLEntry, GLEntries.size());
337: }
338:
339: public void testPosterPerformance() throws Exception {
340: String testTarget = "posterPerformance.";
341: int numberOfTestData = Integer.valueOf(properties
342: .getProperty(testTarget + "numOfData"));
343: int numOfCopy = Integer.valueOf(properties
344: .getProperty(testTarget + "numOfCopy"));
345: long expectedMaxExcutionTime = Long.valueOf(properties
346: .getProperty(testTarget + "expectedMaxExcutionTime"));
347:
348: long startTime = System.currentTimeMillis();
349: List<LaborOriginEntry> inputDataList = new ArrayList<LaborOriginEntry>();
350: for (int i = 0; i < numOfCopy; i++) {
351: inputDataList.addAll(getInputDataList(testTarget
352: + "testData", numberOfTestData, groupToPost));
353: }
354: businessObjectService.save(inputDataList);
355:
356: for (LaborOriginEntry entry : inputDataList) {
357: persistenceService.retrieveNonKeyFields(entry);
358: }
359: long elapsedTime = System.currentTimeMillis() - startTime;
360:
361: startTime = System.currentTimeMillis();
362: laborPosterService.postMainEntries();
363: elapsedTime = System.currentTimeMillis() - startTime;
364:
365: assertTrue(
366: "It takes too much time to run poster against test data",
367: elapsedTime <= expectedMaxExcutionTime);
368: }
369:
370: private List<LaborOriginEntry> getInputDataList(
371: String propertyKeyPrefix, int numberOfInputData,
372: OriginEntryGroup group) {
373: return TestDataPreparator.getLaborOriginEntryList(properties,
374: propertyKeyPrefix, numberOfInputData, group);
375: }
376: }
|