001: /*
002: * Copyright 2005-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.chart.service;
017:
018: import java.sql.Date;
019: import java.util.HashMap;
020: import java.util.List;
021: import java.util.Map;
022:
023: import org.kuali.core.service.BusinessObjectService;
024: import org.kuali.core.service.DateTimeService;
025: import org.kuali.kfs.KFSConstants;
026: import org.kuali.kfs.context.KualiTestBase;
027: import org.kuali.kfs.context.SpringContext;
028: import org.kuali.module.chart.bo.AccountingPeriod;
029: import org.kuali.test.ConfigureContext;
030:
031: /**
032: * This class tests the AccountingPeriod business object from a persistence standpoint using the BusinessObjectService.
033: */
034: @ConfigureContext
035: public class AccountingPeriodServiceTest extends KualiTestBase {
036:
037: protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
038: .getLogger(AccountingPeriodServiceTest.class);
039:
040: public void testPersistence() {
041: Date date = SpringContext.getBean(DateTimeService.class)
042: .getCurrentSqlDate();
043: AccountingPeriod period = SpringContext.getBean(
044: AccountingPeriodService.class).getByDate(date);
045: assertNotNull(period);
046:
047: Integer year = period.getUniversityFiscalYear();
048: String universityFiscalPeriodCode = "UT";
049: String periodName = "unitTest";
050:
051: period
052: .setUniversityFiscalPeriodCode(universityFiscalPeriodCode);
053: period.setUniversityFiscalPeriodName(periodName);
054:
055: SpringContext.getBean(BusinessObjectService.class).save(period);
056:
057: AccountingPeriod result = getAccountingPeriodByPrimaryKeys(
058: year, universityFiscalPeriodCode);
059: assertNotNull(result);
060: assertEquals(periodName, result.getUniversityFiscalPeriodName());
061:
062: SpringContext.getBean(BusinessObjectService.class).delete(
063: result);
064:
065: result = getAccountingPeriodByPrimaryKeys(year,
066: universityFiscalPeriodCode);
067: assertNull(result);
068: }
069:
070: private AccountingPeriod getAccountingPeriodByPrimaryKeys(
071: Integer fiscalYear, String fiscalPeriodcode) {
072: Map<String, Object> h = new HashMap<String, Object>();
073: h.put("universityFiscalYear", fiscalYear);
074: h.put("universityFiscalPeriodCode", fiscalPeriodcode);
075: AccountingPeriod ap2 = (AccountingPeriod) SpringContext
076: .getBean(BusinessObjectService.class).findByPrimaryKey(
077: AccountingPeriod.class, h);
078: return ap2;
079: }
080:
081: public void testGetAllAccountingPeriods() {
082: List<AccountingPeriod> accountingPeriods = (List<AccountingPeriod>) SpringContext
083: .getBean(AccountingPeriodService.class)
084: .getAllAccountingPeriods();
085: assertNotNull(accountingPeriods);
086: assertFalse(accountingPeriods.isEmpty());
087: }
088:
089: public void testGetOpenAccountingPeriods() {
090: List<AccountingPeriod> accountingPeriods = (List<AccountingPeriod>) SpringContext
091: .getBean(AccountingPeriodService.class)
092: .getOpenAccountingPeriods();
093: LOG.info("Number of OpenAccountingPeriods found: "
094: + accountingPeriods.size());
095:
096: assertNotNull(accountingPeriods);
097: assertFalse(accountingPeriods.isEmpty());
098: // all returned AccountingPeriod instances should be marked as OPEN
099: for (AccountingPeriod accountingPeriod : accountingPeriods) {
100: String statusCode = accountingPeriod
101: .getUniversityFiscalPeriodStatusCode();
102: assertTrue(statusCode
103: .equals(KFSConstants.ACCOUNTING_PERIOD_STATUS_OPEN));
104: }
105: }
106: }
|