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.batch.poster;
017:
018: import static org.kuali.module.gl.bo.OriginEntrySource.LABOR_MAIN_POSTER_VALID;
019:
020: import java.util.Arrays;
021: import java.util.Collection;
022: import java.util.Date;
023: import java.util.HashMap;
024: import java.util.List;
025: import java.util.Map;
026: import java.util.Properties;
027:
028: import org.apache.commons.lang.StringUtils;
029: import org.kuali.core.service.BusinessObjectService;
030: import org.kuali.core.service.DateTimeService;
031: import org.kuali.kfs.KFSConstants;
032: import org.kuali.kfs.context.KualiTestBase;
033: import org.kuali.kfs.context.SpringContext;
034: import org.kuali.module.gl.batch.poster.PostTransaction;
035: import org.kuali.module.gl.bo.OriginEntryGroup;
036: import org.kuali.module.gl.service.OriginEntryGroupService;
037: import org.kuali.module.gl.web.TestDataGenerator;
038: import org.kuali.module.labor.bo.LaborOriginEntry;
039: import org.kuali.module.labor.bo.LedgerBalance;
040: import org.kuali.module.labor.util.ObjectUtil;
041: import org.kuali.module.labor.util.TestDataPreparator;
042: import org.kuali.test.ConfigureContext;
043:
044: @ConfigureContext
045: public class LaborLedgerBalancePosterTest extends KualiTestBase {
046:
047: private Properties properties;
048: private String fieldNames;
049: private String deliminator;
050: private List<String> keyFieldList;
051: private Map fieldValues;
052: private OriginEntryGroup group1;
053: private Date today;
054:
055: private BusinessObjectService businessObjectService;
056: private PostTransaction laborLedgerBalancePoster;
057: private OriginEntryGroupService originEntryGroupService;
058:
059: @Override
060: public void setUp() throws Exception {
061: super .setUp();
062: String messageFileName = "test/src/org/kuali/module/labor/testdata/message.properties";
063: String propertiesFileName = "test/src/org/kuali/module/labor/testdata/laborLedgerBalancePoster.properties";
064:
065: properties = (new TestDataGenerator(propertiesFileName,
066: messageFileName)).getProperties();
067: fieldNames = properties.getProperty("fieldNames");
068: deliminator = properties.getProperty("deliminator");
069: keyFieldList = Arrays.asList(StringUtils.split(fieldNames,
070: deliminator));
071:
072: laborLedgerBalancePoster = SpringContext.getBeansOfType(
073: PostTransaction.class).get("laborLedgerBalancePoster");
074: businessObjectService = SpringContext
075: .getBean(BusinessObjectService.class);
076: originEntryGroupService = SpringContext
077: .getBean(OriginEntryGroupService.class);
078: DateTimeService dateTimeService = SpringContext
079: .getBean(DateTimeService.class);
080:
081: group1 = originEntryGroupService.createGroup(dateTimeService
082: .getCurrentSqlDate(), LABOR_MAIN_POSTER_VALID, false,
083: false, false);
084: today = dateTimeService.getCurrentDate();
085:
086: LedgerBalance cleanup = new LedgerBalance();
087: ObjectUtil.populateBusinessObject(cleanup, properties,
088: "dataCleanup", fieldNames, deliminator);
089: fieldValues = ObjectUtil.buildPropertyMap(cleanup, Arrays
090: .asList(StringUtils.split(fieldNames, deliminator)));
091: businessObjectService.deleteMatching(LedgerBalance.class,
092: fieldValues);
093: }
094:
095: public void testPost() throws Exception {
096: int numberOfTestData = Integer.valueOf(properties
097: .getProperty("post.numOfData"));
098: int expectedInsertion = Integer.valueOf(properties
099: .getProperty("post.expectedInsertion"));
100: int expectedUpdate = Integer.valueOf(properties
101: .getProperty("post.expectedUpdate"));
102: int expectedNumberOfRecords = Integer.valueOf(properties
103: .getProperty("post.expectedNumberOfRecords"));
104: int expectedNumberOfOperation = Integer.valueOf(properties
105: .getProperty("post.expectedNumberOfOperation"));
106:
107: List<LaborOriginEntry> transactionList = TestDataPreparator
108: .getLaborOriginEntryList(properties, "post.testData",
109: numberOfTestData, group1);
110: Map<String, Integer> operationType = new HashMap<String, Integer>();
111:
112: for (LaborOriginEntry transaction : transactionList) {
113: String operation = laborLedgerBalancePoster.post(
114: transaction, 0, today);
115: Integer currentNumber = operationType.get(operation);
116: Integer numberOfOperation = currentNumber != null ? currentNumber + 1
117: : 1;
118: operationType.put(operation, numberOfOperation);
119: }
120:
121: Collection returnValues = businessObjectService.findMatching(
122: LedgerBalance.class, fieldValues);
123: assertEquals(expectedNumberOfRecords, returnValues.size());
124:
125: assertEquals(expectedNumberOfOperation, operationType.size());
126: assertEquals(expectedInsertion, operationType.get(
127: KFSConstants.OperationType.INSERT).intValue());
128: assertEquals(expectedUpdate, operationType.get(
129: KFSConstants.OperationType.UPDATE).intValue());
130:
131: LedgerBalance expected1 = new LedgerBalance();
132: ObjectUtil.populateBusinessObject(expected1, properties,
133: "post.expected1", fieldNames, deliminator);
134: }
135: }
|