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_MAIN_POSTER_ERROR;
019: import static org.kuali.module.gl.bo.OriginEntrySource.LABOR_MAIN_POSTER_VALID;
020:
021: import java.sql.Date;
022: import java.util.ArrayList;
023: import java.util.Arrays;
024: import java.util.HashMap;
025: import java.util.Iterator;
026: import java.util.List;
027: import java.util.Map;
028: import java.util.Properties;
029:
030: import org.apache.commons.lang.StringUtils;
031: import org.kuali.core.service.BusinessObjectService;
032: import org.kuali.core.service.DateTimeService;
033: import org.kuali.core.service.PersistenceService;
034: import org.kuali.kfs.context.KualiTestBase;
035: import org.kuali.kfs.context.SpringContext;
036: import org.kuali.module.gl.batch.poster.VerifyTransaction;
037: import org.kuali.module.gl.bo.OriginEntryGroup;
038: import org.kuali.module.gl.bo.Transaction;
039: import org.kuali.module.gl.service.OriginEntryGroupService;
040: import org.kuali.module.gl.util.Message;
041: import org.kuali.module.gl.util.Summary;
042: import org.kuali.module.gl.web.TestDataGenerator;
043: import org.kuali.module.labor.bo.LaborOriginEntry;
044: import org.kuali.module.labor.util.ObjectUtil;
045: import org.kuali.module.labor.util.ReportRegistry;
046: import org.kuali.module.labor.util.TestDataPreparator;
047: import org.kuali.test.ConfigureContext;
048:
049: /**
050: * This class...
051: */
052: @ConfigureContext
053: public class LaborReportServiceTest extends KualiTestBase {
054:
055: private Properties properties;
056: private String fieldNames;
057: private String deliminator;
058: private OriginEntryGroup group1, group2, invalidGroup;
059: private Map fieldValues;
060: private String reportsDirectory;
061: private Date today;
062:
063: private LaborOriginEntryService laborOriginEntryService;
064: private OriginEntryGroupService originEntryGroupService;
065: private LaborReportService laborReportService;
066: private BusinessObjectService businessObjectService;
067: private VerifyTransaction laborPosterTransactionValidator;
068: private PersistenceService persistenceService;
069:
070: @Override
071: public void setUp() throws Exception {
072: super .setUp();
073: String messageFileName = "test/src/org/kuali/module/labor/testdata/message.properties";
074: String propertiesFileName = "test/src/org/kuali/module/labor/testdata/laborReportService.properties";
075:
076: properties = (new TestDataGenerator(propertiesFileName,
077: messageFileName)).getProperties();
078: fieldNames = properties.getProperty("fieldNames");
079: deliminator = properties.getProperty("deliminator");
080:
081: laborOriginEntryService = SpringContext
082: .getBean(LaborOriginEntryService.class);
083: originEntryGroupService = SpringContext
084: .getBean(OriginEntryGroupService.class);
085: businessObjectService = SpringContext
086: .getBean(BusinessObjectService.class);
087: persistenceService = SpringContext
088: .getBean(PersistenceService.class);
089:
090: laborReportService = SpringContext
091: .getBean(LaborReportService.class);
092: laborPosterTransactionValidator = SpringContext.getBeansOfType(
093: VerifyTransaction.class).get(
094: "laborPosterTransactionValidator");
095: reportsDirectory = ReportRegistry.getReportsDirectory();
096:
097: today = (SpringContext.getBean(DateTimeService.class))
098: .getCurrentSqlDate();
099: group1 = originEntryGroupService.createGroup(today,
100: LABOR_MAIN_POSTER_VALID, true, true, false);
101: group2 = originEntryGroupService.createGroup(today,
102: LABOR_MAIN_POSTER_VALID, true, true, false);
103: invalidGroup = originEntryGroupService.createGroup(today,
104: LABOR_MAIN_POSTER_ERROR, false, true, false);
105:
106: LaborOriginEntry cleanup = new LaborOriginEntry();
107: ObjectUtil.populateBusinessObject(cleanup, properties,
108: "dataCleanup", fieldNames, deliminator);
109: fieldValues = ObjectUtil.buildPropertyMap(cleanup, Arrays
110: .asList(StringUtils.split(fieldNames, deliminator)));
111: businessObjectService.deleteMatching(LaborOriginEntry.class,
112: fieldValues);
113: }
114:
115: public void testGenerateInputSummaryReport() throws Exception {
116: String testTarget = "generateInputSummaryReport.";
117: int numberOfTestData = Integer.valueOf(properties
118: .getProperty(testTarget + "numOfData"));
119: List<OriginEntryGroup> groups = new ArrayList<OriginEntryGroup>();
120:
121: laborReportService.generateInputSummaryReport(groups,
122: ReportRegistry.LABOR_POSTER_INPUT, reportsDirectory,
123: today);
124:
125: groups.add(group1);
126: businessObjectService.save(getInputDataList(testTarget
127: + "testData", numberOfTestData, group1));
128: groups.add(group2);
129: businessObjectService.save(getInputDataList(testTarget
130: + "testData", numberOfTestData, group2));
131: laborReportService.generateInputSummaryReport(groups,
132: ReportRegistry.LABOR_POSTER_INPUT, reportsDirectory,
133: today);
134: }
135:
136: public void testGenerateErrorTransactionListing() throws Exception {
137: String testTarget = "generateErrorTransactionListing.";
138: int numberOfTestData = Integer.valueOf(properties
139: .getProperty(testTarget + "numOfData"));
140:
141: laborReportService.generateErrorTransactionListing(
142: invalidGroup, ReportRegistry.LABOR_POSTER_ERROR,
143: reportsDirectory, today);
144:
145: businessObjectService.save(getInputDataList(testTarget
146: + "testData", numberOfTestData, invalidGroup));
147: businessObjectService.save(getInputDataList(testTarget
148: + "testData", numberOfTestData, invalidGroup));
149: laborReportService.generateErrorTransactionListing(
150: invalidGroup, ReportRegistry.LABOR_POSTER_ERROR,
151: reportsDirectory, today);
152: }
153:
154: public void testGenerateOutputSummaryReportByGroups()
155: throws Exception {
156: String testTarget = "generateOutputSummaryReport.";
157: int numberOfTestData = Integer.valueOf(properties
158: .getProperty(testTarget + "numOfData"));
159: List<OriginEntryGroup> groups = new ArrayList<OriginEntryGroup>();
160:
161: laborReportService.generateOutputSummaryReport(groups,
162: ReportRegistry.LABOR_POSTER_OUTPUT, reportsDirectory,
163: today);
164:
165: groups.add(group1);
166: businessObjectService.save(getInputDataList(testTarget
167: + "testData", numberOfTestData, group1));
168: groups.add(group2);
169: businessObjectService.save(getInputDataList(testTarget
170: + "testData", numberOfTestData, group2));
171: laborReportService.generateOutputSummaryReport(groups,
172: ReportRegistry.LABOR_POSTER_OUTPUT, reportsDirectory,
173: today);
174: }
175:
176: public void testGenerateOutputSummaryReportBySingleGroup()
177: throws Exception {
178: String testTarget = "generateOutputSummaryReport.";
179: int numberOfTestData = Integer.valueOf(properties
180: .getProperty(testTarget + "numOfData"));
181:
182: laborReportService.generateOutputSummaryReport(group1,
183: ReportRegistry.LABOR_POSTER_OUTPUT_BY_SINGLE_GROUP,
184: reportsDirectory, today);
185:
186: businessObjectService.save(getInputDataList(testTarget
187: + "testData", numberOfTestData, group1));
188: laborReportService.generateOutputSummaryReport(group1,
189: ReportRegistry.LABOR_POSTER_OUTPUT_BY_SINGLE_GROUP,
190: reportsDirectory, today);
191: }
192:
193: public void testGenerateStatisticsReport() throws Exception {
194: String testTarget = "generateStatisticsReport.";
195: int numberOfTestData = Integer.valueOf(properties
196: .getProperty(testTarget + "numOfData"));
197: List<OriginEntryGroup> groups = new ArrayList<OriginEntryGroup>();
198:
199: List<Summary> reportSummary = this .getReportSummary();
200: laborReportService.generateStatisticsReport(reportSummary,
201: null, ReportRegistry.LABOR_POSTER_STATISTICS,
202: reportsDirectory, today);
203:
204: groups.add(group1);
205: businessObjectService.save(getInputDataList(testTarget
206: + "testData", numberOfTestData, group1));
207: groups.add(group2);
208: businessObjectService.save(getInputDataList(testTarget
209: + "testData", numberOfTestData, group2));
210:
211: persistenceService.clearCache();
212:
213: Map<Transaction, List<Message>> errorMap = this
214: .getErrorMap(groups);
215: laborReportService.generateStatisticsReport(reportSummary,
216: errorMap, ReportRegistry.LABOR_POSTER_STATISTICS,
217: reportsDirectory, today);
218: }
219:
220: private List<Summary> getReportSummary() {
221: List<Summary> reportSummary = new ArrayList<Summary>();
222: for (int i = 0; i < 10; i++) {
223: String destination = "Table " + i;
224: reportSummary.add(new Summary(reportSummary.size() + 2,
225: destination, 100 * i));
226: reportSummary.add(new Summary(reportSummary.size() + 2, "",
227: 0));
228: }
229: return reportSummary;
230: }
231:
232: private Map<Transaction, List<Message>> getErrorMap(
233: List<OriginEntryGroup> groups) {
234: Map<Transaction, List<Message>> errorMap = new HashMap<Transaction, List<Message>>();
235: for (Iterator<LaborOriginEntry> entry = laborOriginEntryService
236: .getEntriesByGroups(groups); entry.hasNext();) {
237: LaborOriginEntry originEntry = entry.next();
238:
239: List<Message> errors = laborPosterTransactionValidator
240: .verifyTransaction(originEntry);
241: if (!errors.isEmpty()) {
242: errorMap.put(originEntry, errors);
243: }
244: }
245: return errorMap;
246: }
247:
248: private List getInputDataList(String propertyKeyPrefix,
249: int numberOfInputData, OriginEntryGroup group) {
250: return TestDataPreparator.getLaborOriginEntryList(properties,
251: propertyKeyPrefix, numberOfInputData, group);
252: }
253: }
|