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.List;
020: import java.util.Map;
021: import java.util.Properties;
022:
023: import org.apache.commons.lang.StringUtils;
024: import org.kuali.core.service.BusinessObjectService;
025: import org.kuali.kfs.context.KualiTestBase;
026: import org.kuali.kfs.context.SpringContext;
027: import org.kuali.module.chart.bo.Account;
028: import org.kuali.module.gl.web.TestDataGenerator;
029: import org.kuali.module.labor.bo.LaborLedgerPendingEntry;
030: import org.kuali.module.labor.util.TestDataPreparator;
031: import org.kuali.test.ConfigureContext;
032:
033: @ConfigureContext
034: public class LaborLedgerPendingEntryServiceTest extends KualiTestBase {
035:
036: private Properties properties;
037: private String fieldNames;
038: private String deliminator;
039: private List<String> keyFieldList;
040: private Map<String, Object> fieldValues;
041:
042: private LaborLedgerPendingEntryService laborLedgerPendingEntryService;
043: private BusinessObjectService businessObjectService;
044:
045: public LaborLedgerPendingEntryServiceTest() {
046: super ();
047: String messageFileName = "test/src/org/kuali/module/labor/testdata/message.properties";
048: String propertiesFileName = "test/src/org/kuali/module/labor/testdata/laborLedgerPendingEntryService.properties";
049:
050: properties = (new TestDataGenerator(propertiesFileName,
051: messageFileName)).getProperties();
052: fieldNames = properties.getProperty("fieldNames");
053: deliminator = properties.getProperty("deliminator");
054: keyFieldList = Arrays.asList(StringUtils.split(fieldNames,
055: deliminator));
056: }
057:
058: @Override
059: public void setUp() throws Exception {
060: super .setUp();
061:
062: laborLedgerPendingEntryService = SpringContext
063: .getBean(LaborLedgerPendingEntryService.class);
064: businessObjectService = SpringContext
065: .getBean(BusinessObjectService.class);
066:
067: fieldValues = TestDataPreparator.buildCleanupCriteria(
068: LaborLedgerPendingEntry.class, properties,
069: "dataCleanup");
070: businessObjectService.deleteMatching(
071: LaborLedgerPendingEntry.class, fieldValues);
072: }
073:
074: public void testHasPendingLaborLedgerEntryWithAccount()
075: throws Exception {
076: String testTarget = "hasPendingLaborLedgerEntryWithAccount";
077: int numberOfTestData = Integer.valueOf(properties
078: .getProperty(testTarget + ".numOfData"));
079: String accountFieldNames = properties.getProperty(testTarget
080: + ".accountFieldNames");
081:
082: // prepare test data -- put the test data into data store
083: String prefixForInput = testTarget + ".testData";
084: List<LaborLedgerPendingEntry> inputDataList = TestDataPreparator
085: .buildTestDataList(LaborLedgerPendingEntry.class,
086: properties, prefixForInput, numberOfTestData);
087: businessObjectService.save(inputDataList);
088:
089: // test primary scenarios -- everything is correct and the expected results can be retrieved
090: String prefixForValidAccount = testTarget
091: + ".accountWithResults";
092: int numOfValidAccounts = Integer.valueOf(properties
093: .getProperty(prefixForValidAccount + ".numOfData"));
094: List<Account> validAccounts = TestDataPreparator
095: .buildTestDataList(Account.class, properties,
096: prefixForValidAccount, accountFieldNames,
097: deliminator, numOfValidAccounts);
098: for (Account account : validAccounts) {
099: assertTrue("At least one record can be found.",
100: laborLedgerPendingEntryService
101: .hasPendingLaborLedgerEntry(account));
102: }
103:
104: // test secondary scenarios -- the input is not correct and nothing can be returned
105: String prefixForInvalidAccount = testTarget
106: + ".accountWithoutResults";
107: int numOfInvalidAccounts = Integer.valueOf(properties
108: .getProperty(prefixForInvalidAccount + ".numOfData"));
109: List<Account> invalidAccounts = TestDataPreparator
110: .buildTestDataList(Account.class, properties,
111: prefixForInvalidAccount, accountFieldNames,
112: deliminator, numOfInvalidAccounts);
113: for (Account account : invalidAccounts) {
114: assertFalse("Must not find anything.",
115: laborLedgerPendingEntryService
116: .hasPendingLaborLedgerEntry(account));
117: }
118: }
119: }
|