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.KFSPropertyConstants;
026: import org.kuali.kfs.context.KualiTestBase;
027: import org.kuali.kfs.context.SpringContext;
028: import org.kuali.module.gl.web.TestDataGenerator;
029: import org.kuali.module.labor.bo.LaborGeneralLedgerEntry;
030: import org.kuali.module.labor.util.ObjectUtil;
031: import org.kuali.test.ConfigureContext;
032:
033: @ConfigureContext
034: public class LaborGeneralLedgerEntryServiceTest extends KualiTestBase {
035:
036: private Properties properties;
037: private String fieldNames;
038: private String deliminator;
039: private List<String> keyFieldList;
040:
041: private LaborGeneralLedgerEntryService laborGeneralLedgerEntryService;
042: private BusinessObjectService businessObjectService;
043:
044: @Override
045: public void setUp() throws Exception {
046: super .setUp();
047: String messageFileName = "test/src/org/kuali/module/labor/testdata/message.properties";
048: String propertiesFileName = "test/src/org/kuali/module/labor/testdata/laborGeneralLedgerEntryService.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: laborGeneralLedgerEntryService = SpringContext
058: .getBean(LaborGeneralLedgerEntryService.class);
059: businessObjectService = SpringContext
060: .getBean(BusinessObjectService.class);
061: }
062:
063: public void testSave() throws Exception {
064: LaborGeneralLedgerEntry input1 = new LaborGeneralLedgerEntry();
065: ObjectUtil.populateBusinessObject(input1, properties,
066: "save.testData1", fieldNames, deliminator);
067:
068: LaborGeneralLedgerEntry expected1 = new LaborGeneralLedgerEntry();
069: ObjectUtil.populateBusinessObject(expected1, properties,
070: "save.expected1", fieldNames, deliminator);
071: Map fieldValues = ObjectUtil.buildPropertyMap(expected1,
072: keyFieldList);
073:
074: businessObjectService.deleteMatching(
075: LaborGeneralLedgerEntry.class, fieldValues);
076: assertEquals(0, businessObjectService.countMatching(
077: LaborGeneralLedgerEntry.class, fieldValues));
078:
079: laborGeneralLedgerEntryService.save(input1);
080: assertEquals(1, businessObjectService.countMatching(
081: LaborGeneralLedgerEntry.class, fieldValues));
082:
083: LaborGeneralLedgerEntry input2 = new LaborGeneralLedgerEntry();
084: ObjectUtil.populateBusinessObject(input2, properties,
085: "save.testData2", fieldNames, deliminator);
086: try {
087: laborGeneralLedgerEntryService.save(input2);
088: fail();
089: } catch (Exception e) {
090: }
091: }
092:
093: public void testGetMaxSequenceNumber() throws Exception {
094: LaborGeneralLedgerEntry input1 = new LaborGeneralLedgerEntry();
095: ObjectUtil.populateBusinessObject(input1, properties,
096: "maxSeqNumber.testData1", fieldNames, deliminator);
097:
098: Map fieldValues = ObjectUtil.buildPropertyMap(input1,
099: keyFieldList);
100: fieldValues
101: .remove(KFSPropertyConstants.TRANSACTION_ENTRY_SEQUENCE_NUMBER);
102: businessObjectService.deleteMatching(
103: LaborGeneralLedgerEntry.class, fieldValues);
104:
105: Integer maxSeqNumber = laborGeneralLedgerEntryService
106: .getMaxSequenceNumber(input1);
107: assertEquals(Integer.valueOf(0), maxSeqNumber);
108:
109: LaborGeneralLedgerEntry LaborGeneralLedgerEntryExpected1 = new LaborGeneralLedgerEntry();
110: String expectedSeqNumber1 = properties
111: .getProperty("maxSeqNumber.expected1");
112:
113: laborGeneralLedgerEntryService.save(input1);
114: maxSeqNumber = laborGeneralLedgerEntryService
115: .getMaxSequenceNumber(input1);
116: assertEquals(Integer.valueOf(expectedSeqNumber1), maxSeqNumber);
117:
118: LaborGeneralLedgerEntry input2 = new LaborGeneralLedgerEntry();
119: ObjectUtil.populateBusinessObject(input2, properties,
120: "maxSeqNumber.testData2", fieldNames, deliminator);
121:
122: LaborGeneralLedgerEntry expected2 = new LaborGeneralLedgerEntry();
123: String expectedSeqNumber2 = properties
124: .getProperty("maxSeqNumber.expected2");
125:
126: laborGeneralLedgerEntryService.save(input2);
127: maxSeqNumber = laborGeneralLedgerEntryService
128: .getMaxSequenceNumber(input1);
129: assertEquals(Integer.valueOf(expectedSeqNumber2), maxSeqNumber);
130:
131: maxSeqNumber = laborGeneralLedgerEntryService
132: .getMaxSequenceNumber(input2);
133: assertEquals(Integer.valueOf(expectedSeqNumber2), maxSeqNumber);
134: }
135: }
|