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.List;
019: import java.util.Properties;
020:
021: import org.kuali.kfs.context.KualiTestBase;
022: import org.kuali.kfs.context.SpringContext;
023: import org.kuali.module.gl.web.TestDataGenerator;
024: import org.kuali.module.labor.bo.LaborOriginEntry;
025: import org.kuali.module.labor.bo.LaborTransaction;
026: import org.kuali.module.labor.bo.LedgerBalance;
027: import org.kuali.module.labor.util.TestDataPreparator;
028: import org.kuali.test.ConfigureContext;
029:
030: @ConfigureContext
031: public class LaborLedgerBalanceServiceTest extends KualiTestBase {
032: private Properties properties;
033: private String fieldNames;
034: private String transactionFieldNames;
035: private String deliminator;
036: private LaborLedgerBalanceService laborLedgerBalanceService;
037:
038: @Override
039: public void setUp() throws Exception {
040: super .setUp();
041: String messageFileName = "test/src/org/kuali/module/labor/testdata/message.properties";
042: String propertiesFileName = "test/src/org/kuali/module/labor/testdata/laborLedgerBalanceService.properties";
043:
044: properties = (new TestDataGenerator(propertiesFileName,
045: messageFileName)).getProperties();
046: fieldNames = properties.getProperty("fieldNames");
047: transactionFieldNames = properties
048: .getProperty("transactionFieldNames");
049: deliminator = properties.getProperty("deliminator");
050: laborLedgerBalanceService = SpringContext
051: .getBean(LaborLedgerBalanceService.class);
052: }
053:
054: public void testFindLedgerBalance_Found() throws Exception {
055: String testTarget = "findLedgerBalance.";
056: int numberOfLedgerBalance = Integer.valueOf(properties
057: .getProperty(testTarget + "numOfLedgerBalance"));
058: int numberOfTransaction = Integer.valueOf(properties
059: .getProperty(testTarget + "numOfTransaction"));
060:
061: List ledgerBalanceList = TestDataPreparator.buildTestDataList(
062: LedgerBalance.class, properties, testTarget
063: + "ledgerBalance", numberOfLedgerBalance);
064: List<LaborTransaction> transactionList = TestDataPreparator
065: .buildTestDataList(LaborOriginEntry.class, properties,
066: testTarget + "transaction",
067: transactionFieldNames, deliminator,
068: numberOfTransaction);
069: for (LaborTransaction transaction : transactionList) {
070: assertNotNull(laborLedgerBalanceService.findLedgerBalance(
071: ledgerBalanceList, transaction));
072: }
073: }
074:
075: public void testFindLedgerBalance_NotFound() throws Exception {
076: String testTarget = "findLedgerBalance.";
077: int numberOfLedgerBalance = Integer.valueOf(properties
078: .getProperty(testTarget + "numOfLedgerBalance"));
079: int numberOfTransaction = Integer.valueOf(properties
080: .getProperty(testTarget + "numOfNotFoundTransaction"));
081:
082: List ledgerBalanceList = TestDataPreparator.buildTestDataList(
083: LedgerBalance.class, properties, testTarget
084: + "ledgerBalance", numberOfLedgerBalance);
085: List<LaborTransaction> transactionList = TestDataPreparator
086: .buildTestDataList(LaborOriginEntry.class, properties,
087: testTarget + "notFoundTransaction",
088: transactionFieldNames, deliminator,
089: numberOfTransaction);
090: for (LaborTransaction transaction : transactionList) {
091: assertNull(laborLedgerBalanceService.findLedgerBalance(
092: ledgerBalanceList, transaction));
093: }
094: }
095:
096: public void testAddLedgerBalance_New() throws Exception {
097: String testTarget = "addLedgerBalance.";
098: int numberOfLedgerBalance = Integer.valueOf(properties
099: .getProperty(testTarget + "numOfLedgerBalance"));
100: int numberOfTransaction = Integer.valueOf(properties
101: .getProperty(testTarget + "numOfNewTransaction"));
102:
103: List ledgerBalanceList = TestDataPreparator.buildTestDataList(
104: LedgerBalance.class, properties, testTarget
105: + "ledgerBalance", numberOfLedgerBalance);
106: List<LaborTransaction> transactionList = TestDataPreparator
107: .buildTestDataList(LaborOriginEntry.class, properties,
108: testTarget + "newTransaction",
109: transactionFieldNames, deliminator,
110: numberOfTransaction);
111: for (LaborTransaction transaction : transactionList) {
112: laborLedgerBalanceService.addLedgerBalance(
113: ledgerBalanceList, transaction);
114: }
115:
116: int expectedNumberOfBalances = numberOfLedgerBalance
117: + numberOfTransaction;
118: assertEquals(expectedNumberOfBalances, ledgerBalanceList.size());
119: }
120:
121: public void testAddLedgerBalance_Existing() throws Exception {
122: String testTarget = "addLedgerBalance.";
123: int numberOfLedgerBalance = Integer.valueOf(properties
124: .getProperty(testTarget + "numOfLedgerBalance"));
125: int numberOfTransaction = Integer.valueOf(properties
126: .getProperty(testTarget + "numOfExistingTransaction"));
127:
128: List ledgerBalanceList = TestDataPreparator.buildTestDataList(
129: LedgerBalance.class, properties, testTarget
130: + "ledgerBalance", numberOfLedgerBalance);
131: List<LaborTransaction> transactionList = TestDataPreparator
132: .buildTestDataList(LaborOriginEntry.class, properties,
133: testTarget + "existingTransaction",
134: transactionFieldNames, deliminator,
135: numberOfTransaction);
136: for (LaborTransaction transaction : transactionList) {
137: laborLedgerBalanceService.addLedgerBalance(
138: ledgerBalanceList, transaction);
139: }
140:
141: int expectedNumberOfBalances = numberOfLedgerBalance;
142: assertEquals(expectedNumberOfBalances, ledgerBalanceList.size());
143: }
144:
145: public void testUpdateLedgerBalance() throws Exception {
146: String testTarget = "updateLedgerBalance.";
147: int numberOfLedgerBalance = Integer.valueOf(properties
148: .getProperty(testTarget + "numOfLedgerBalance"));
149: int numberOfTransaction = Integer.valueOf(properties
150: .getProperty(testTarget + "numOfTransaction"));
151: int numberOfExpected = Integer.valueOf(properties
152: .getProperty(testTarget + "numOfExpected"));
153:
154: List ledgerBalanceList = TestDataPreparator.buildTestDataList(
155: LedgerBalance.class, properties, testTarget
156: + "ledgerBalance", numberOfLedgerBalance);
157: List<LaborTransaction> transactionList = TestDataPreparator
158: .buildTestDataList(LaborOriginEntry.class, properties,
159: testTarget + "transaction",
160: transactionFieldNames, deliminator,
161: numberOfTransaction);
162: for (LaborTransaction transaction : transactionList) {
163: LedgerBalance ledgerBalance = laborLedgerBalanceService
164: .findLedgerBalance(ledgerBalanceList, transaction);
165: if (ledgerBalance != null) {
166: laborLedgerBalanceService.updateLedgerBalance(
167: ledgerBalance, transaction);
168: }
169: }
170:
171: List<LaborOriginEntry> expectedList = TestDataPreparator
172: .buildTestDataList(LaborOriginEntry.class, properties,
173: testTarget + "expected", transactionFieldNames,
174: deliminator, numberOfExpected);
175: for (LaborOriginEntry expected : expectedList) {
176: LedgerBalance ledgerBalance = laborLedgerBalanceService
177: .findLedgerBalance(ledgerBalanceList, expected);
178: assertNotNull(ledgerBalance);
179: ledgerBalance.getMonth1Amount().equals(
180: expected.getTransactionLedgerEntryAmount());
181: }
182: }
183: }
|