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.chart.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.MandatoryTransferEliminationCode;
022: import org.kuali.test.ConfigureContext;
023: import org.kuali.test.suite.AnnotationTestSuite;
024: import org.kuali.test.suite.CrossSectionSuite;
025:
026: /**
027: * This class tests the MandatoryTransferEliminationCode service.
028: */
029: @AnnotationTestSuite(CrossSectionSuite.class)
030: @ConfigureContext
031: public class MandatoryTransferEliminationCodeServiceTest extends
032: KualiTestBase {
033:
034: private static final String GOOD_CODE = "N";
035: private static final String GOOD_NAME = "NEITHER";
036: private static final String NONEXISTENT_CODE = "A"; // This code is not in the database. Please do not add it, or you will break
037: // this test.
038: private static final String NONEXISTENT_NAME = "BAD";
039:
040: /**
041: * @see org.kuali.test.KualiTestBase#setUp()
042: */
043: @Override
044: protected void setUp() throws Exception {
045: super .setUp();
046: validateTestFixtures();
047: }
048:
049: /**
050: * Performs miscellaneous tests for this service.
051: */
052: public void testByCode_valid_name() {
053: // test known-good byCode
054: MandatoryTransferEliminationCode mtec = (MandatoryTransferEliminationCode) SpringContext
055: .getBean(KualiCodeService.class).getByCode(
056: MandatoryTransferEliminationCode.class,
057: GOOD_CODE);
058: assertEquals(
059: "Known-good code results in expected returned Name.",
060: GOOD_NAME, mtec.getName());
061: }
062:
063: public void testByName_valid_name() {
064: // test known-good byName
065: MandatoryTransferEliminationCode mtec = (MandatoryTransferEliminationCode) SpringContext
066: .getBean(KualiCodeService.class).getByName(
067: MandatoryTransferEliminationCode.class,
068: GOOD_NAME);
069: assertEquals(
070: "Known-good name results in expected returned code.",
071: GOOD_CODE, mtec.getCode());
072: }
073:
074: public void stestByCode_invalid_name() {
075: // test known-bad byCode
076: MandatoryTransferEliminationCode mtec = (MandatoryTransferEliminationCode) SpringContext
077: .getBean(KualiCodeService.class).getByCode(
078: MandatoryTransferEliminationCode.class,
079: NONEXISTENT_CODE);
080: assertNull("Known-bad code returns null object.", mtec);
081: }
082:
083: public void testByName_invalid_name() {
084: // test known-bad byName
085: MandatoryTransferEliminationCode mtec = (MandatoryTransferEliminationCode) SpringContext
086: .getBean(KualiCodeService.class).getByName(
087: MandatoryTransferEliminationCode.class,
088: NONEXISTENT_NAME);
089: assertNull("Known-bad code returns null object.", mtec);
090: }
091:
092: public void testByCode_empty() {
093: // test known-bad byCode
094: MandatoryTransferEliminationCode mtec = (MandatoryTransferEliminationCode) SpringContext
095: .getBean(KualiCodeService.class).getByCode(
096: MandatoryTransferEliminationCode.class, "");
097: assertNull("Known-empty code returns null object.", mtec);
098: }
099:
100: public void testByCode_null() {
101: // test known-bad byCode
102: MandatoryTransferEliminationCode mtec = (MandatoryTransferEliminationCode) SpringContext
103: .getBean(KualiCodeService.class).getByCode(
104: MandatoryTransferEliminationCode.class, null);
105: assertNull("Known-null code returns null object.", mtec);
106: }
107:
108: public void testSave() {
109: String oldName;
110: String newName;
111:
112: // get the existing value
113: MandatoryTransferEliminationCode mtec = (MandatoryTransferEliminationCode) SpringContext
114: .getBean(KualiCodeService.class).getByCode(
115: MandatoryTransferEliminationCode.class,
116: GOOD_CODE);
117:
118: // cache the old value, create a new value, and modify the object
119: oldName = mtec.getName();
120: newName = oldName + "2";
121: mtec.setName(newName);
122:
123: // attempt to save the modified object
124: SpringContext.getBean(KualiCodeService.class).save(mtec);
125:
126: // open the object byCode() and confirm that the changes were saved
127: mtec = null;
128: mtec = (MandatoryTransferEliminationCode) SpringContext
129: .getBean(KualiCodeService.class).getByCode(
130: MandatoryTransferEliminationCode.class,
131: GOOD_CODE);
132: assertEquals(
133: "Changes to the document were not persisted to the database.",
134: newName, mtec.getName());
135:
136: // revert back to the old name if it worked
137: mtec.setName(oldName);
138: SpringContext.getBean(KualiCodeService.class).save(mtec);
139:
140: mtec = null;
141: mtec = (MandatoryTransferEliminationCode) SpringContext
142: .getBean(KualiCodeService.class).getByCode(
143: MandatoryTransferEliminationCode.class,
144: GOOD_CODE);
145: assertEquals(
146: "Changes to the document were not persisted to the database.",
147: oldName, mtec.getName());
148: }
149:
150: public void testActive() {
151:
152: // test known-good active code
153: MandatoryTransferEliminationCode mtec = (MandatoryTransferEliminationCode) SpringContext
154: .getBean(KualiCodeService.class).getByCode(
155: MandatoryTransferEliminationCode.class,
156: GOOD_CODE);
157: assertEquals(
158: "The active code associated with this field is incorrect",
159: true, mtec.isActive());
160:
161: }
162:
163: private void validateTestFixtures() {
164: MandatoryTransferEliminationCode code = (MandatoryTransferEliminationCode) SpringContext
165: .getBean(KualiCodeService.class).getByCode(
166: MandatoryTransferEliminationCode.class,
167: GOOD_CODE);
168: assertEquals(GOOD_CODE, code.getCode());
169: assertEquals(GOOD_NAME, code.getName());
170:
171: code = (MandatoryTransferEliminationCode) SpringContext
172: .getBean(KualiCodeService.class).getByName(
173: MandatoryTransferEliminationCode.class,
174: GOOD_NAME);
175: assertEquals(GOOD_CODE, code.getCode());
176: assertEquals(GOOD_NAME, code.getName());
177:
178: code = (MandatoryTransferEliminationCode) SpringContext
179: .getBean(KualiCodeService.class).getByCode(
180: MandatoryTransferEliminationCode.class,
181: NONEXISTENT_CODE);
182: assertNull(code);
183: code = (MandatoryTransferEliminationCode) SpringContext
184: .getBean(KualiCodeService.class).getByName(
185: MandatoryTransferEliminationCode.class,
186: NONEXISTENT_CODE);
187: assertNull(code);
188: }
189: }
|