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.FederalFundedCode;
022: import org.kuali.test.ConfigureContext;
023:
024: /**
025: * This class tests the FederalFundedCode service.
026: */
027:
028: @ConfigureContext
029: public class FederalFundedCodeServiceTest extends KualiTestBase {
030:
031: private FederalFundedCode ffc;
032:
033: /**
034: * Performs all tests for this service.
035: */
036: public void testGetByCode_valid_code() {
037: ffc = null;
038: ffc = (FederalFundedCode) SpringContext.getBean(
039: KualiCodeService.class).getByCode(
040: FederalFundedCode.class,
041: TestConstants.Data5.FEDERAL_FUNDED_CODE1);
042: assertNotNull(ffc);
043: assertEquals(
044: "Known-good code results in expected returned Name.",
045: TestConstants.Data5.FEDERAL_FUNDED_NAME1, ffc.getName());
046: }
047:
048: public void testGetByName_valid_name() {
049: ffc = null;
050: ffc = (FederalFundedCode) SpringContext.getBean(
051: KualiCodeService.class).getByName(
052: FederalFundedCode.class,
053: TestConstants.Data5.FEDERAL_FUNDED_NAME1);
054: assertEquals(
055: "Known-good name results in expected returned code.",
056: TestConstants.Data5.FEDERAL_FUNDED_CODE1, ffc.getCode());
057: }
058:
059: public void testGetByCode_invalid_code() {
060: ffc = null;
061: ffc = (FederalFundedCode) SpringContext.getBean(
062: KualiCodeService.class).getByCode(
063: FederalFundedCode.class,
064: TestConstants.Data5.FEDERAL_FUNDED_CODE_BAD);
065: assertNull("Known-bad code returns null object.", ffc);
066: }
067:
068: public void testGetByName_invalid_name() {
069: ffc = null;
070: ffc = (FederalFundedCode) SpringContext.getBean(
071: KualiCodeService.class).getByName(
072: FederalFundedCode.class,
073: TestConstants.Data5.FEDERAL_FUNDED_NAME_BAD);
074: assertNull("Known-bad name returns null object.", ffc);
075: }
076:
077: public void testGetByCode_blank_code() {
078: ffc = null;
079: ffc = (FederalFundedCode) SpringContext.getBean(
080: KualiCodeService.class).getByCode(
081: FederalFundedCode.class, "");
082: assertNull("Known-empty code returns null object.", ffc);
083: }
084:
085: public void testGetByCode_null_code() {
086: ffc = null;
087: ffc = (FederalFundedCode) SpringContext.getBean(
088: KualiCodeService.class).getByCode(
089: FederalFundedCode.class, null);
090: assertNull("Known-null code returns null object.", ffc);
091: }
092:
093: /*
094: * This method was removed because: 1. Adding new FederalFundedCodes is extremely rare-- this test is not particularly valuable
095: * 2. The old test was broken in several ways: a. it did not clean up after itself ala dbunit b. the resolution of the timestamp
096: * to modify the name was too low-- the test could only be run successfully once per day c. the final assertion ignored the fact
097: * that the new name had been intentionally altered-- it expected the old name to still be there d. the deep copied object had
098: * the same primary key as the one intended to replace it public void testSave() { ffc = null; FederalFundedCode result = null;
099: * String timestamp = DateFormat.getDateInstance().format(new Date()); try { String newName = null; // get the existing value
100: * ffc = (FederalFundedCode) kualiCodeService.getByCode(FederalFundedCode.class, TestConstants.Data5.FEDERAL_FUNDED_CODE1); //
101: * cache the old value, create a new value, and modify the object result = (FederalFundedCode)ObjectUtils.deepCopy(ffc) ;
102: * newName = ffc.getName() + ":"+timestamp; result.setName(newName); // attempt to save the modified object
103: * kualiCodeService.save(result); // open the object byCode() and confirm that the changes were saved result =
104: * (FederalFundedCode) kualiCodeService.getByCode(FederalFundedCode.class, TestConstants.Data5.FEDERAL_FUNDED_CODE1);
105: * assertEquals("Changes to the document were not persisted to the database.", newName, ffc.getName()); } finally { if (ffc !=
106: * null) { kualiCodeService.save(ffc); result = (FederalFundedCode) kualiCodeService.getByCode(FederalFundedCode.class,
107: * TestConstants.Data5.FEDERAL_FUNDED_CODE1); assertEquals("Changes to the document were not persisted to the database.",
108: * ffc.getName(), result.getName()); } } }
109: */
110:
111: public void testActive() {
112: // test known-good active code
113: ffc = null;
114: ffc = (FederalFundedCode) SpringContext.getBean(
115: KualiCodeService.class).getByCode(
116: FederalFundedCode.class,
117: TestConstants.Data5.FEDERAL_FUNDED_CODE1);
118: assertTrue(
119: "The active code associated with this field is incorrect",
120: ffc.isActive());
121:
122: }
123: }
|