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.LedgerEntry;
040: import org.kuali.module.labor.service.LaborLedgerEntryService;
041: import org.kuali.module.labor.util.ObjectUtil;
042: import org.kuali.module.labor.util.TestDataPreparator;
043: import org.kuali.test.ConfigureContext;
044:
045: @ConfigureContext
046: public class LaborLedgerEntryPosterTest extends KualiTestBase {
047:
048: private Properties properties;
049: private String fieldNames;
050: private String deliminator;
051: private List<String> keyFieldList;
052: private Map fieldValues;
053: private OriginEntryGroup group1;
054: private Date today;
055:
056: private BusinessObjectService businessObjectService;
057: private PostTransaction laborLedgerEntryPoster;
058: private OriginEntryGroupService originEntryGroupService;
059: private LaborLedgerEntryService laborLedgerEntryService;
060:
061: @Override
062: public void setUp() throws Exception {
063: super .setUp();
064: String messageFileName = "test/src/org/kuali/module/labor/testdata/message.properties";
065: String propertiesFileName = "test/src/org/kuali/module/labor/testdata/laborLedgerEntryPoster.properties";
066:
067: properties = (new TestDataGenerator(propertiesFileName,
068: messageFileName)).getProperties();
069: fieldNames = properties.getProperty("fieldNames");
070: deliminator = properties.getProperty("deliminator");
071: keyFieldList = Arrays.asList(StringUtils.split(fieldNames,
072: deliminator));
073:
074: laborLedgerEntryPoster = SpringContext.getBeansOfType(
075: PostTransaction.class).get("laborLedgerEntryPoster");
076: businessObjectService = SpringContext
077: .getBean(BusinessObjectService.class);
078: originEntryGroupService = SpringContext
079: .getBean(OriginEntryGroupService.class);
080: laborLedgerEntryService = SpringContext
081: .getBean(LaborLedgerEntryService.class);
082: DateTimeService dateTimeService = SpringContext
083: .getBean(DateTimeService.class);
084:
085: group1 = originEntryGroupService.createGroup(dateTimeService
086: .getCurrentSqlDate(), LABOR_MAIN_POSTER_VALID, false,
087: false, false);
088: today = dateTimeService.getCurrentDate();
089:
090: LedgerEntry cleanup = new LedgerEntry();
091: ObjectUtil.populateBusinessObject(cleanup, properties,
092: "dataCleanup", fieldNames, deliminator);
093: fieldValues = ObjectUtil.buildPropertyMap(cleanup, Arrays
094: .asList(StringUtils.split(fieldNames, deliminator)));
095: businessObjectService.deleteMatching(LedgerEntry.class,
096: fieldValues);
097: }
098:
099: public void testPost() throws Exception {
100: int numberOfTestData = Integer.valueOf(properties
101: .getProperty("post.numOfData"));
102: int expectedMaxSequenceNumber = Integer.valueOf(properties
103: .getProperty("post.expectedMaxSequenceNumber"));
104: int expectedInsertion = Integer.valueOf(properties
105: .getProperty("post.expectedInsertion"));
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 = laborLedgerEntryPoster.post(transaction,
114: 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: LedgerEntry.class, fieldValues);
123: assertEquals(numberOfTestData, returnValues.size());
124:
125: assertEquals(1, operationType.size());
126: assertEquals(expectedInsertion, operationType.get(
127: KFSConstants.OperationType.INSERT).intValue());
128:
129: LedgerEntry expected1 = new LedgerEntry();
130: ObjectUtil.populateBusinessObject(expected1, properties,
131: "post.expected1", fieldNames, deliminator);
132: assertEquals(expectedMaxSequenceNumber, laborLedgerEntryService
133: .getMaxSequenceNumber(expected1).intValue());
134:
135: LedgerEntry expected2 = new LedgerEntry();
136: ObjectUtil.populateBusinessObject(expected2, properties,
137: "post.expected2", fieldNames, deliminator);
138: assertEquals(expectedMaxSequenceNumber, laborLedgerEntryService
139: .getMaxSequenceNumber(expected2).intValue());
140:
141: LedgerEntry expected3 = new LedgerEntry();
142: ObjectUtil.populateBusinessObject(expected3, properties,
143: "post.expected3", fieldNames, deliminator);
144: assertEquals(expectedMaxSequenceNumber, laborLedgerEntryService
145: .getMaxSequenceNumber(expected3).intValue());
146: }
147: }
|