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.core.service;
017:
018: import org.kuali.kfs.context.KualiTestBase;
019: import org.kuali.kfs.context.SpringContext;
020: import org.kuali.kfs.service.KualiCodeService;
021: import org.kuali.module.chart.bo.codes.BudgetAggregationCode;
022: import org.kuali.test.ConfigureContext;
023:
024: /**
025: * This class tests the BudgetAggregationCode service.
026: */
027: @ConfigureContext
028: public class BudgetAggregationCodeServiceTest extends KualiTestBase {
029:
030: /**
031: * Performs all tests for this service.
032: */
033: public void testLookupByCode_code_known() {
034: BudgetAggregationCode bac = (BudgetAggregationCode) SpringContext
035: .getBean(KualiCodeService.class).getByCode(
036: BudgetAggregationCode.class,
037: TestConstants.Data5.BUDGET_AGGREGATION_CODE1);
038: assertNotNull("Should be a valid object.", bac);
039: assertEquals(
040: "Known-good code results in expected returned Name.",
041: TestConstants.Data5.BUDGET_AGGREGATION_NAME1, bac
042: .getName());
043: }
044:
045: public void testLookupByCode_code_unknown() {
046: BudgetAggregationCode bac = (BudgetAggregationCode) SpringContext
047: .getBean(KualiCodeService.class).getByCode(
048: BudgetAggregationCode.class,
049: TestConstants.Data5.FEDERAL_FUNDED_CODE_BAD);
050: assertNull("Known-bad code should return null object.", bac);
051: }
052:
053: public void testLookupByCode_code_blank() {
054: BudgetAggregationCode bac = (BudgetAggregationCode) SpringContext
055: .getBean(KualiCodeService.class).getByCode(
056: BudgetAggregationCode.class, "");
057: assertNull("Known-empty code returns null object.", bac);
058: }
059:
060: public void testLookupByCode_code_null() {
061: BudgetAggregationCode bac = (BudgetAggregationCode) SpringContext
062: .getBean(KualiCodeService.class).getByCode(
063: BudgetAggregationCode.class, null);
064: assertNull("Known-null code returns null object.", bac);
065: }
066:
067: public void testLookupByName_name_known() {
068: BudgetAggregationCode bac = (BudgetAggregationCode) SpringContext
069: .getBean(KualiCodeService.class).getByName(
070: BudgetAggregationCode.class,
071: TestConstants.Data5.BUDGET_AGGREGATION_NAME1);
072: assertNotNull("Should be a valid object.", bac);
073: assertEquals(
074: "Known-good name results in expected returned code.",
075: TestConstants.Data5.BUDGET_AGGREGATION_CODE1, bac
076: .getCode());
077: }
078:
079: public void testLookupByName_name_unknown() {
080: BudgetAggregationCode bac = (BudgetAggregationCode) SpringContext
081: .getBean(KualiCodeService.class)
082: .getByName(BudgetAggregationCode.class,
083: "This is not a valid code description in this table.");
084: assertNull("Known-bad code returns null object.", bac);
085: }
086:
087: public void testLookupByCode_name_blank() {
088: BudgetAggregationCode bac = (BudgetAggregationCode) SpringContext
089: .getBean(KualiCodeService.class).getByName(
090: BudgetAggregationCode.class, "");
091: assertNull("Known-empty name returns null object.", bac);
092: }
093:
094: public void testLookupByCode_name_null() {
095: BudgetAggregationCode bac = (BudgetAggregationCode) SpringContext
096: .getBean(KualiCodeService.class).getByName(
097: BudgetAggregationCode.class, null);
098: assertNull("Known-null name returns null object.", bac);
099: }
100:
101: public void testActive() {
102: // test known-good active code
103: BudgetAggregationCode bac = (BudgetAggregationCode) SpringContext
104: .getBean(KualiCodeService.class).getByCode(
105: BudgetAggregationCode.class,
106: TestConstants.Data5.BUDGET_AGGREGATION_CODE1);
107: assertEquals(
108: "The active code associated with this field is incorrect",
109: true, bac.isActive());
110:
111: }
112:
113: /**
114: * This tests the caching mechanism by looping five times through some get calls. The first time through, the data should be
115: * retrieved from the DB. Every time after that, the object should be retrieved from the cache therefore time to retrieve should
116: * be less than or equal to.
117: */
118: public void testCache() {
119: long tsStart;
120: long tsStop;
121:
122: for (int i = 0; i < 5; i++) {
123: long firstTime = -1000;
124: tsStart = System.currentTimeMillis();
125: BudgetAggregationCode O = (BudgetAggregationCode) SpringContext
126: .getBean(KualiCodeService.class)
127: .getByCode(
128: BudgetAggregationCode.class,
129: TestConstants.Data5.BUDGET_AGGREGATION_CODE1);
130: BudgetAggregationCode C = (BudgetAggregationCode) SpringContext
131: .getBean(KualiCodeService.class)
132: .getByCode(
133: BudgetAggregationCode.class,
134: TestConstants.Data5.BUDGET_AGGREGATION_CODE2);
135: BudgetAggregationCode L = (BudgetAggregationCode) SpringContext
136: .getBean(KualiCodeService.class)
137: .getByCode(
138: BudgetAggregationCode.class,
139: TestConstants.Data5.BUDGET_AGGREGATION_CODE1);
140: tsStop = System.currentTimeMillis();
141: long diff = tsStop - tsStart;
142: if (firstTime == -1000) {
143: firstTime = diff;
144: }
145: assertTrue(diff <= firstTime);
146: }
147: }
148: }
|