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.LaborGeneralLedgerEntry;
039: import org.kuali.module.labor.bo.LaborOriginEntry;
040: import org.kuali.module.labor.service.LaborGeneralLedgerEntryService;
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 LaborGLLedgerEntryPosterTest 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 laborGLLedgerEntryPoster;
058: private OriginEntryGroupService originEntryGroupService;
059: private LaborGeneralLedgerEntryService laborGeneralLedgerEntryService;
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/laborGLLedgerEntryPoster.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: laborGLLedgerEntryPoster = SpringContext.getBeansOfType(
075: PostTransaction.class).get("laborGLLedgerEntryPoster");
076: businessObjectService = SpringContext
077: .getBean(BusinessObjectService.class);
078: originEntryGroupService = SpringContext
079: .getBean(OriginEntryGroupService.class);
080: laborGeneralLedgerEntryService = SpringContext
081: .getBean(LaborGeneralLedgerEntryService.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: LaborGeneralLedgerEntry cleanup = new LaborGeneralLedgerEntry();
091: ObjectUtil.populateBusinessObject(cleanup, properties,
092: "dataCleanup", fieldNames, deliminator);
093: fieldValues = ObjectUtil.buildPropertyMap(cleanup, Arrays
094: .asList(StringUtils.split(fieldNames, deliminator)));
095: businessObjectService.deleteMatching(
096: LaborGeneralLedgerEntry.class, 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 = laborGLLedgerEntryPoster.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: LaborGeneralLedgerEntry.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: LaborGeneralLedgerEntry expected1 = new LaborGeneralLedgerEntry();
130: ObjectUtil.populateBusinessObject(expected1, properties,
131: "post.expected1", fieldNames, deliminator);
132: assertEquals(expectedMaxSequenceNumber,
133: laborGeneralLedgerEntryService.getMaxSequenceNumber(
134: expected1).intValue());
135:
136: LaborGeneralLedgerEntry expected2 = new LaborGeneralLedgerEntry();
137: ObjectUtil.populateBusinessObject(expected2, properties,
138: "post.expected2", fieldNames, deliminator);
139: assertEquals(expectedMaxSequenceNumber,
140: laborGeneralLedgerEntryService.getMaxSequenceNumber(
141: expected2).intValue());
142:
143: LaborGeneralLedgerEntry expected3 = new LaborGeneralLedgerEntry();
144: ObjectUtil.populateBusinessObject(expected3, properties,
145: "post.expected3", fieldNames, deliminator);
146: assertEquals(expectedMaxSequenceNumber,
147: laborGeneralLedgerEntryService.getMaxSequenceNumber(
148: expected3).intValue());
149: }
150: }
|