001: /*
002: * Copyright 2006-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.financial.service;
017:
018: import static org.kuali.test.fixtures.OffsetAccountFixture.OFFSET_ACCOUNT1;
019: import static org.kuali.test.util.KualiTestAssertionUtils.assertSparselyEqualBean;
020:
021: import org.kuali.kfs.KFSConstants;
022: import org.kuali.kfs.context.KualiTestBase;
023: import org.kuali.kfs.context.SpringContext;
024: import org.kuali.kfs.context.TestUtils;
025: import org.kuali.kfs.service.ParameterService;
026: import org.kuali.module.chart.bo.OffsetDefinition;
027: import org.kuali.module.financial.bo.OffsetAccount;
028: import org.kuali.test.ConfigureContext;
029:
030: /**
031: * This class...
032: */
033: @ConfigureContext
034: public class FlexibleOffsetAccountServiceTest extends KualiTestBase {
035:
036: public void testGetByPrimaryId_valid() throws Exception {
037: boolean enabled = SpringContext
038: .getBean(ParameterService.class)
039: .getIndicatorParameter(
040: OffsetDefinition.class,
041: KFSConstants.SystemGroupParameterNames.FLEXIBLE_OFFSET_ENABLED_FLAG);
042:
043: TestUtils
044: .setSystemParameter(
045: OffsetDefinition.class,
046: KFSConstants.SystemGroupParameterNames.FLEXIBLE_OFFSET_ENABLED_FLAG,
047: "Y");
048: OffsetAccount offsetAccount = SpringContext.getBean(
049: FlexibleOffsetAccountService.class)
050: .getByPrimaryIdIfEnabled(
051: OFFSET_ACCOUNT1.chartOfAccountsCode,
052: OFFSET_ACCOUNT1.accountNumber,
053: OFFSET_ACCOUNT1.financialOffsetObjectCode);
054: if (offsetAccount == null) {
055: throw new RuntimeException(
056: "Offset Account came back null, cannot perform asserts.");
057: }
058:
059: assertSparselyEqualBean(OFFSET_ACCOUNT1.createOffsetAccount(),
060: offsetAccount);
061: assertEquals(OFFSET_ACCOUNT1.chartOfAccountsCode, offsetAccount
062: .getChart().getChartOfAccountsCode());
063: assertEquals(OFFSET_ACCOUNT1.accountNumber, offsetAccount
064: .getAccount().getAccountNumber());
065: assertEquals(OFFSET_ACCOUNT1.financialOffsetChartOfAccountCode,
066: offsetAccount.getFinancialOffsetChartOfAccount()
067: .getChartOfAccountsCode());
068: assertEquals(OFFSET_ACCOUNT1.financialOffsetAccountNumber,
069: offsetAccount.getFinancialOffsetAccount()
070: .getAccountNumber());
071: }
072:
073: public void testGetByPrimaryId_validDisabled() throws Exception {
074: TestUtils
075: .setSystemParameter(
076: OffsetDefinition.class,
077: KFSConstants.SystemGroupParameterNames.FLEXIBLE_OFFSET_ENABLED_FLAG,
078: "N");
079: assertNull(SpringContext.getBean(
080: FlexibleOffsetAccountService.class)
081: .getByPrimaryIdIfEnabled(
082: OFFSET_ACCOUNT1.chartOfAccountsCode,
083: OFFSET_ACCOUNT1.accountNumber,
084: OFFSET_ACCOUNT1.financialOffsetAccountNumber));
085: }
086:
087: public void testGetByPrimaryId_invalid() throws Exception {
088: TestUtils
089: .setSystemParameter(
090: OffsetDefinition.class,
091: KFSConstants.SystemGroupParameterNames.FLEXIBLE_OFFSET_ENABLED_FLAG,
092: "N");
093: assertNull(SpringContext.getBean(
094: FlexibleOffsetAccountService.class)
095: .getByPrimaryIdIfEnabled("XX", "XX", "XX"));
096: }
097:
098: /**
099: * Integration test to the database parameter table (not the mock configuration service).
100: */
101: public void testGetEnabled() {
102: // This tests that no RuntimeException is thrown because the parameter is missing from the database
103: // or contains a value other than Y or N.
104: SpringContext.getBean(FlexibleOffsetAccountService.class)
105: .getEnabled();
106: }
107: }
|