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 java.util.Arrays;
019: import java.util.Collection;
020: import java.util.List;
021: import java.util.Map;
022: import java.util.Properties;
023:
024: import org.apache.commons.lang.StringUtils;
025: import org.kuali.core.bo.DocumentHeader;
026: import org.kuali.core.service.BusinessObjectService;
027: import org.kuali.core.service.PersistenceService;
028: import org.kuali.kfs.context.KualiTestBase;
029: import org.kuali.kfs.context.SpringContext;
030: import org.kuali.module.gl.web.TestDataGenerator;
031: import org.kuali.module.labor.bo.LaborLedgerPendingEntry;
032: import org.kuali.module.labor.bo.LaborOriginEntry;
033: import org.kuali.module.labor.util.ObjectUtil;
034: import org.kuali.module.labor.util.TestDataPreparator;
035: import org.kuali.module.labor.util.testobject.LaborOriginEntryForTesting;
036: import org.kuali.module.labor.util.testobject.PendingLedgerEntryForTesting;
037: import org.kuali.test.ConfigureContext;
038:
039: @ConfigureContext
040: public class LaborNightlyOutServiceTest extends KualiTestBase {
041: private Properties properties;
042: private String fieldNames, documentFieldNames;
043: private String deliminator;
044:
045: private Map fieldValues;
046:
047: private BusinessObjectService businessObjectService;
048: private LaborNightlyOutService laborNightlyOutService;
049: private PersistenceService persistenceService;
050:
051: @Override
052: public void setUp() throws Exception {
053: super .setUp();
054: String messageFileName = "test/src/org/kuali/module/labor/testdata/message.properties";
055: String propertiesFileName = "test/src/org/kuali/module/labor/testdata/laborNightlyOutService.properties";
056:
057: properties = (new TestDataGenerator(propertiesFileName,
058: messageFileName)).getProperties();
059: fieldNames = properties.getProperty("fieldNames");
060: documentFieldNames = properties
061: .getProperty("documentFieldNames");
062: deliminator = properties.getProperty("deliminator");
063:
064: businessObjectService = SpringContext
065: .getBean(BusinessObjectService.class);
066: laborNightlyOutService = SpringContext
067: .getBean(LaborNightlyOutService.class);
068: persistenceService = SpringContext
069: .getBean(PersistenceService.class);
070:
071: int numberOfDocuments = Integer.valueOf(properties
072: .getProperty("document.numOfData"));
073: List inputDataList = TestDataPreparator.buildTestDataList(
074: DocumentHeader.class, properties, "document.testData",
075: documentFieldNames, deliminator, numberOfDocuments);
076: businessObjectService.save(inputDataList);
077:
078: LaborOriginEntry cleanup = new LaborOriginEntry();
079: ObjectUtil.populateBusinessObject(cleanup, properties,
080: "dataCleanup", fieldNames, deliminator);
081: fieldValues = ObjectUtil.buildPropertyMap(cleanup, Arrays
082: .asList(StringUtils.split(fieldNames, deliminator)));
083: businessObjectService.deleteMatching(LaborOriginEntry.class,
084: fieldValues);
085: businessObjectService.deleteMatching(
086: LaborLedgerPendingEntry.class, fieldValues);
087: }
088:
089: public void testCopyApprovedPendingLedgerEntries() throws Exception {
090: String testTarget = "copyApprovedPendingLedgerEntries.";
091: int numberOfTestData = Integer.valueOf(properties
092: .getProperty(testTarget + "numOfData"));
093: int expectedNumOfData = Integer.valueOf(properties
094: .getProperty(testTarget + "expectedNumOfData"));
095:
096: List inputDataList = TestDataPreparator.buildTestDataList(
097: LaborLedgerPendingEntry.class, properties, testTarget
098: + "testData", numberOfTestData);
099: businessObjectService.save(inputDataList);
100:
101: laborNightlyOutService.copyApprovedPendingLedgerEntries();
102:
103: List expectedDataList = TestDataPreparator
104: .buildExpectedValueList(
105: LaborOriginEntryForTesting.class, properties,
106: testTarget + "expected", expectedNumOfData);
107: Collection originEntries = businessObjectService.findMatching(
108: LaborOriginEntry.class, fieldValues);
109: for (Object entry : originEntries) {
110: LaborOriginEntryForTesting originEntryForTesting = new LaborOriginEntryForTesting();
111: ObjectUtil.buildObject(originEntryForTesting, entry);
112: assertTrue("Cannot find the expected entry",
113: expectedDataList.contains(originEntryForTesting));
114: }
115: assertEquals(expectedNumOfData, originEntries.size());
116: }
117:
118: public void testCopyPendingLedgerEntries() throws Exception {
119: String testTarget = "copyPendingLedgerEntries.";
120: int numberOfTestData = Integer.valueOf(properties
121: .getProperty(testTarget + "numOfData"));
122: int expectedNumOfData = Integer.valueOf(properties
123: .getProperty(testTarget + "expectedNumOfData"));
124:
125: List inputDataList = TestDataPreparator.buildTestDataList(
126: LaborLedgerPendingEntry.class, properties, testTarget
127: + "testData", numberOfTestData);
128: businessObjectService.save(inputDataList);
129:
130: laborNightlyOutService.copyApprovedPendingLedgerEntries();
131:
132: List expectedDataList = TestDataPreparator
133: .buildExpectedValueList(
134: LaborOriginEntryForTesting.class, properties,
135: testTarget + "expected", expectedNumOfData);
136: Collection originEntries = businessObjectService.findMatching(
137: LaborOriginEntry.class, fieldValues);
138: for (Object entry : originEntries) {
139: LaborOriginEntryForTesting originEntryForTesting = new LaborOriginEntryForTesting();
140: ObjectUtil.buildObject(originEntryForTesting, entry);
141: assertTrue("Cannot find the expected entry",
142: expectedDataList.contains(originEntryForTesting));
143: }
144: assertEquals(expectedNumOfData, originEntries.size());
145: }
146:
147: public void testDeleteCopiedPendingLedgerEntries() throws Exception {
148: String testTarget = "deleteCopiedPendingLedgerEntries.";
149: int numberOfTestData = Integer.valueOf(properties
150: .getProperty(testTarget + "numOfData"));
151: int expectedNumOfData = Integer.valueOf(properties
152: .getProperty(testTarget + "expectedNumOfData"));
153:
154: List inputDataList = TestDataPreparator.buildTestDataList(
155: LaborLedgerPendingEntry.class, properties, testTarget
156: + "testData", numberOfTestData);
157: businessObjectService.save(inputDataList);
158:
159: laborNightlyOutService.deleteCopiedPendingLedgerEntries();
160:
161: Collection originEntries = businessObjectService.findMatching(
162: LaborOriginEntry.class, fieldValues);
163:
164: assertEquals(expectedNumOfData, originEntries.size());
165: }
166:
167: public void testDeletePendingLedgerEntries() throws Exception {
168: String testTarget = "deletePendingLedgerEntries.";
169: int numberOfTestData = Integer.valueOf(properties
170: .getProperty(testTarget + "numOfData"));
171: int expectedNumOfData = Integer.valueOf(properties
172: .getProperty(testTarget + "expectedNumOfData"));
173:
174: List inputDataList = TestDataPreparator.buildTestDataList(
175: LaborLedgerPendingEntry.class, properties, testTarget
176: + "testData", numberOfTestData);
177: businessObjectService.save(inputDataList);
178:
179: laborNightlyOutService.deleteCopiedPendingLedgerEntries();
180:
181: List expectedDataList = TestDataPreparator
182: .buildExpectedValueList(
183: LaborOriginEntryForTesting.class, properties,
184: testTarget + "expected", expectedNumOfData);
185: Collection originEntries = businessObjectService.findMatching(
186: LaborLedgerPendingEntry.class, fieldValues);
187: for (Object entry : originEntries) {
188: PendingLedgerEntryForTesting pendingEntryForTesting = new PendingLedgerEntryForTesting();
189: ObjectUtil.buildObject(pendingEntryForTesting, entry);
190: assertTrue("Cannot find the expected entry",
191: expectedDataList.contains(pendingEntryForTesting));
192: }
193: assertEquals(expectedNumOfData, originEntries.size());
194: }
195: }
|