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.sql.Date;
021: import java.util.ArrayList;
022: import java.util.List;
023: import java.util.Properties;
024:
025: import org.kuali.core.service.BusinessObjectService;
026: import org.kuali.core.service.DateTimeService;
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.batch.poster.VerifyTransaction;
031: import org.kuali.module.gl.bo.OriginEntryGroup;
032: import org.kuali.module.gl.service.OriginEntryGroupService;
033: import org.kuali.module.gl.util.Message;
034: import org.kuali.module.gl.web.TestDataGenerator;
035: import org.kuali.module.labor.bo.LaborOriginEntry;
036: import org.kuali.module.labor.service.LaborOriginEntryService;
037: import org.kuali.module.labor.util.TestDataPreparator;
038: import org.kuali.test.ConfigureContext;
039:
040: @ConfigureContext
041: public class LaborPosterTransactionValidatorTest extends KualiTestBase {
042:
043: private Properties properties;
044: private String fieldNames;
045: private String deliminator;
046: private OriginEntryGroup group1;
047:
048: private LaborOriginEntryService laborOriginEntryService;
049: private OriginEntryGroupService originEntryGroupService;
050: private BusinessObjectService businessObjectService;
051: private VerifyTransaction laborPosterTransactionValidator;
052: private PersistenceService persistenceService;
053:
054: @Override
055: public void setUp() throws Exception {
056: super .setUp();
057: String messageFileName = "test/src/org/kuali/module/labor/testdata/message.properties";
058: String propertiesFileName = "test/src/org/kuali/module/labor/testdata/laborPosterTransactionValidator.properties";
059:
060: properties = (new TestDataGenerator(propertiesFileName,
061: messageFileName)).getProperties();
062: fieldNames = properties.getProperty("fieldNames");
063: deliminator = properties.getProperty("deliminator");
064:
065: laborPosterTransactionValidator = SpringContext.getBeansOfType(
066: VerifyTransaction.class).get(
067: "laborPosterTransactionValidator");
068: laborOriginEntryService = SpringContext
069: .getBean(LaborOriginEntryService.class);
070: originEntryGroupService = SpringContext
071: .getBean(OriginEntryGroupService.class);
072: businessObjectService = SpringContext
073: .getBean(BusinessObjectService.class);
074: persistenceService = SpringContext
075: .getBean(PersistenceService.class);
076:
077: Date today = (SpringContext.getBean(DateTimeService.class))
078: .getCurrentSqlDate();
079: group1 = originEntryGroupService.createGroup(today,
080: LABOR_MAIN_POSTER_VALID, true, true, false);
081: }
082:
083: public void testVerifyTransactionWithForeignReference()
084: throws Exception {
085: int numberOfTestData = Integer.valueOf(properties
086: .getProperty("verifyTransaction.numOfData"));
087:
088: List<LaborOriginEntry> transactionList = TestDataPreparator
089: .getLaborOriginEntryList(properties,
090: "verifyTransaction.testData", numberOfTestData,
091: group1);
092: List<Integer> expectedNumOfErrors = getExpectedDataList(
093: "verifyTransaction.expectedNumOfErrors",
094: numberOfTestData);
095:
096: businessObjectService.save(transactionList);
097:
098: for (int i = 0; i < numberOfTestData; i++) {
099: LaborOriginEntry transaction = transactionList.get(i);
100: persistenceService.retrieveNonKeyFields(transaction);
101: List<Message> errorMessage = laborPosterTransactionValidator
102: .verifyTransaction(transaction);
103: assertEquals(expectedNumOfErrors.get(i).intValue(),
104: errorMessage.size());
105: }
106: }
107:
108: public void testVerifyTransactionWithoutForeignReference()
109: throws Exception {
110: int numberOfTestData = Integer.valueOf(properties
111: .getProperty("verifyTransaction.numOfData"));
112: List<LaborOriginEntry> transactionList = TestDataPreparator
113: .getLaborOriginEntryList(properties,
114: "verifyTransaction.testData", numberOfTestData,
115: group1);
116:
117: for (int i = 0; i < numberOfTestData - 1; i++) {
118: LaborOriginEntry transaction = transactionList.get(i);
119: List<Message> errorMessage = laborPosterTransactionValidator
120: .verifyTransaction(transaction);
121:
122: int numOfErrors = errorMessage.size();
123: boolean isTrue = (i < numberOfTestData - 1) ? numOfErrors > 0
124: : numOfErrors == 0;
125: assertTrue(isTrue);
126: }
127: }
128:
129: private List<Integer> getExpectedDataList(String propertyKeyPrefix,
130: int numberOfInputData) {
131: List expectedDataList = new ArrayList();
132: for (int i = 1; i <= numberOfInputData; i++) {
133: String propertyKey = propertyKeyPrefix + i;
134: expectedDataList.add(Integer.valueOf(properties
135: .getProperty(propertyKey)));
136: }
137: return expectedDataList;
138: }
139: }
|