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_YEAR_END_BALANCE_FORWARD;
019:
020: import java.util.Arrays;
021: import java.util.Collection;
022: import java.util.HashMap;
023: import java.util.List;
024: import java.util.Map;
025: import java.util.Properties;
026:
027: import org.apache.commons.lang.StringUtils;
028: import org.kuali.core.service.BusinessObjectService;
029: import org.kuali.core.service.PersistenceService;
030: import org.kuali.kfs.KFSPropertyConstants;
031: import org.kuali.kfs.context.KualiTestBase;
032: import org.kuali.kfs.context.SpringContext;
033: import org.kuali.module.gl.bo.OriginEntryGroup;
034: import org.kuali.module.gl.service.OriginEntryGroupService;
035: import org.kuali.module.gl.web.TestDataGenerator;
036: import org.kuali.module.labor.bo.LaborOriginEntry;
037: import org.kuali.module.labor.bo.LedgerBalance;
038: import org.kuali.module.labor.util.ObjectUtil;
039: import org.kuali.module.labor.util.TestDataPreparator;
040: import org.kuali.module.labor.util.testobject.LaborOriginEntryForTesting;
041: import org.kuali.test.ConfigureContext;
042:
043: @ConfigureContext
044: public class LaborYearEndBalanceForwardServiceTest extends
045: KualiTestBase {
046: private Properties properties;
047: private String fieldNames, transactionFieldNames;
048: private String deliminator;
049: private Integer fiscalYear;
050:
051: private Map fieldValues, groupFieldValues;
052: private OriginEntryGroupService originEntryGroupService;
053: private BusinessObjectService businessObjectService;
054: private LaborYearEndBalanceForwardService laborYearEndBalanceForwardService;
055: private PersistenceService persistenceService;
056:
057: @Override
058: public void setUp() throws Exception {
059: super .setUp();
060: String messageFileName = "test/src/org/kuali/module/labor/testdata/message.properties";
061: String propertiesFileName = "test/src/org/kuali/module/labor/testdata/laborYearEndBalanceForwardService.properties";
062:
063: properties = (new TestDataGenerator(propertiesFileName,
064: messageFileName)).getProperties();
065: fieldNames = properties.getProperty("fieldNames");
066: transactionFieldNames = properties
067: .getProperty("transactionFieldNames");
068: deliminator = properties.getProperty("deliminator");
069: fiscalYear = Integer.valueOf(properties
070: .getProperty("oldFiscalYear"));
071:
072: originEntryGroupService = SpringContext
073: .getBean(OriginEntryGroupService.class);
074: businessObjectService = SpringContext
075: .getBean(BusinessObjectService.class);
076: laborYearEndBalanceForwardService = SpringContext
077: .getBean(LaborYearEndBalanceForwardService.class);
078: persistenceService = SpringContext
079: .getBean(PersistenceService.class);
080:
081: groupFieldValues = new HashMap();
082: groupFieldValues.put(KFSPropertyConstants.SOURCE_CODE,
083: LABOR_YEAR_END_BALANCE_FORWARD);
084: originEntryGroupService.deleteOlderGroups(0);
085: businessObjectService.deleteMatching(OriginEntryGroup.class,
086: groupFieldValues);
087:
088: LaborOriginEntry cleanup = new LaborOriginEntry();
089: ObjectUtil.populateBusinessObject(cleanup, properties,
090: "dataCleanup", fieldNames, deliminator);
091: fieldValues = ObjectUtil.buildPropertyMap(cleanup, Arrays
092: .asList(StringUtils.split(fieldNames, deliminator)));
093: businessObjectService.deleteMatching(LaborOriginEntry.class,
094: fieldValues);
095: businessObjectService.deleteMatching(LedgerBalance.class,
096: fieldValues);
097: }
098:
099: public void testPostIntoOriginEntry() throws Exception {
100: String testTarget = "postIntoOriginEntry.";
101: int numberOfTestData = Integer.valueOf(properties
102: .getProperty(testTarget + "numOfData"));
103: int expectedNumOfData = Integer.valueOf(properties
104: .getProperty(testTarget + "expectedNumOfOriginEntry"));
105:
106: List inputDataList = TestDataPreparator.buildTestDataList(
107: LedgerBalance.class, properties, testTarget
108: + "testData", numberOfTestData);
109: businessObjectService.save(inputDataList);
110:
111: for (Object entry : inputDataList) {
112: persistenceService.retrieveNonKeyFields(entry);
113: }
114:
115: laborYearEndBalanceForwardService.forwardBalance(fiscalYear,
116: fiscalYear);
117:
118: List expectedDataList = TestDataPreparator
119: .buildExpectedValueList(
120: LaborOriginEntryForTesting.class, properties,
121: testTarget + "expected", transactionFieldNames,
122: deliminator, expectedNumOfData);
123: Collection originEntries = businessObjectService.findMatching(
124: LaborOriginEntry.class, fieldValues);
125: for (Object entry : originEntries) {
126: LaborOriginEntryForTesting originEntryForTesting = new LaborOriginEntryForTesting();
127: ObjectUtil.buildObject(originEntryForTesting, entry);
128: assertTrue("Cannot find the expected entry",
129: expectedDataList.contains(originEntryForTesting));
130: }
131: assertEquals(expectedNumOfData, originEntries.size());
132: }
133:
134: public void testNotPostableBalance() throws Exception {
135: String testTarget = "notPostableBalance.";
136: int numberOfTestData = Integer.valueOf(properties
137: .getProperty(testTarget + "numOfData"));
138: int expectedNumOfData = Integer.valueOf(properties
139: .getProperty(testTarget + "expectedNumOfOriginEntry"));
140:
141: List inputDataList = TestDataPreparator.buildTestDataList(
142: LedgerBalance.class, properties, testTarget
143: + "testData", numberOfTestData);
144: businessObjectService.save(inputDataList);
145:
146: for (Object entry : inputDataList) {
147: persistenceService.retrieveNonKeyFields(entry);
148: }
149:
150: laborYearEndBalanceForwardService.forwardBalance(fiscalYear,
151: fiscalYear);
152:
153: assertEquals(expectedNumOfData, businessObjectService
154: .countMatching(LaborOriginEntry.class, fieldValues));
155: }
156: }
|