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.gl.util;
017:
018: import java.util.HashMap;
019: import java.util.Map;
020:
021: import org.apache.ojb.broker.query.Criteria;
022: import org.kuali.core.service.BusinessObjectService;
023: import org.kuali.core.util.KualiDecimal;
024: import org.kuali.kfs.KFSConstants;
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.GLConstants;
029: import org.kuali.module.gl.bo.AccountBalance;
030: import org.kuali.module.gl.bo.TransientBalanceInquiryAttributes;
031: import org.kuali.module.gl.web.Constant;
032: import org.kuali.test.ConfigureContext;
033:
034: /**
035: * Test coverage of OJBUtility
036: * @see org.kuali.module.gl.util.OJBUtility
037: */
038: @ConfigureContext
039: public class OJBUtilityTest extends KualiTestBase {
040:
041: /**
042: * test cases for OJBUtility.buildPropertyMap method
043: * @throws Exception thrown if any exception is encountered for any reason
044: */
045: public void testBuildPropertyMap() throws Exception {
046: TransientBalanceInquiryAttributes dummyBusinessObject = new TransientBalanceInquiryAttributes();
047:
048: dummyBusinessObject.setAmountViewOption(Constant.ACCUMULATE);
049: Map propertyMap = OJBUtility
050: .buildPropertyMap(dummyBusinessObject);
051:
052: String amountViewOption = (String) propertyMap
053: .get("amountViewOption");
054: assertEquals(amountViewOption, Constant.ACCUMULATE);
055: }
056:
057: /**
058: * test cases for OJBUtility.buildCriteriaFromMap method
059: * @throws Exception thrown if any exception is encountered for any reason
060: */
061: public void testBuildCriteriaFromMap() throws Exception {
062: AccountBalance accountBalance = new AccountBalance();
063:
064: Map propertyMap1 = new HashMap();
065: propertyMap1.put("accountNumber", "2004");
066: propertyMap1.put("chartOfAccountsCode", "");
067: propertyMap1.put("objectCode", null);
068: Criteria criteria1 = OJBUtility.buildCriteriaFromMap(
069: propertyMap1, accountBalance);
070:
071: String criteria1Value = criteria1.toString();
072: assertTrue(criteria1Value.indexOf("accountNumber") >= 0);
073: assertTrue(criteria1Value.indexOf("chartOfAccountsCode") < 0);
074: assertTrue(criteria1Value.indexOf("objectCode") < 0);
075:
076: accountBalance.setAccountNumber("2004");
077: accountBalance.setChartOfAccountsCode("");
078: accountBalance.setObjectCode(null);
079: // Map propertyMap2 = BusinessObjectHandler.buildPropertyMap(accountBalance);
080: // Criteria criteria2 = BusinessObjectHandler.buildCriteriaFromMap(propertyMap1, accountBalance);
081:
082: String criteria2Value = criteria1.toString();
083: assertTrue(criteria2Value.indexOf("accountNumber") >= 0);
084: assertTrue(criteria2Value.indexOf("chartOfAccountsCode") < 0);
085: assertTrue(criteria2Value.indexOf("objectCode") < 0);
086: assertTrue(criteria2Value.indexOf("subObjectCode") < 0);
087: }
088:
089: /**
090: * Tests the OJBUtility.getResultSizeFromMap method
091: *
092: * @throws Exception thrown if any exception is encountered for any reason
093: */
094: public void testGetResultSizeFromMap() throws Exception {
095: SpringContext.getBean(BusinessObjectService.class).save(
096: buildAccountBalanceFixture());
097:
098: Map propertyMap = new HashMap();
099: propertyMap.put(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR,
100: "2007");
101:
102: Long resultSize = OJBUtility.getResultSizeFromMap(propertyMap,
103: new AccountBalance());
104: assertTrue(
105: "Should be greater than 0 if there are account balance records",
106: resultSize.intValue() > 0);
107: }
108:
109: /**
110: * Builds a simple AccountBalance record, so the test doesn't fail
111: * @return a fake AccountBalance record
112: */
113: private AccountBalance buildAccountBalanceFixture() {
114: AccountBalance accountBalance = new AccountBalance();
115: accountBalance.setUniversityFiscalYear(new Integer(2007));
116: accountBalance.setChartOfAccountsCode("BL");
117: accountBalance.setAccountNumber("1031400");
118: accountBalance.setSubAccountNumber(KFSConstants
119: .getDashSubAccountNumber());
120: accountBalance.setObjectCode("5000");
121: accountBalance.setSubObjectCode(KFSConstants
122: .getDashFinancialSubObjectCode());
123: accountBalance
124: .setAccountLineActualsBalanceAmount(KualiDecimal.ZERO);
125: accountBalance
126: .setCurrentBudgetLineBalanceAmount(KualiDecimal.ZERO);
127: accountBalance
128: .setAccountLineEncumbranceBalanceAmount(KualiDecimal.ZERO);
129: return accountBalance;
130: }
131:
132: /**
133: * Tests the OJBUtility.getResultLimit method
134: */
135: public void testGetResultLimit() {
136: Integer limit = OJBUtility.getResultLimit();
137: assertTrue("Should be greater than 0", limit.intValue() == 200);
138: }
139: }
|