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.core.service;
017:
018: import org.kuali.core.lookup.valueFinder.ValueFinder;
019: import org.kuali.kfs.context.KualiTestBase;
020: import org.kuali.kfs.context.SpringContext;
021: import org.kuali.kfs.lookup.valuefinder.FiscalYearFinder;
022: import org.kuali.module.chart.bo.Account;
023: import org.kuali.module.chart.bo.SubAccount;
024: import org.kuali.module.chart.bo.SubObjCd;
025: import org.kuali.test.ConfigureContext;
026:
027: @ConfigureContext
028: public class MaintenanceDocumentDictionaryServiceTest extends
029: KualiTestBase {
030:
031: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
032: .getLogger(MaintenanceDocumentDictionaryServiceTest.class);
033:
034: // tests to make sure IllegalArgumentExceptions are being thrown on
035: // null parameters
036: public void testGetFieldDefaultValue_NullArguments() {
037:
038: boolean exceptionThrown;
039:
040: // test the boClass null argument
041: exceptionThrown = false;
042: try {
043: SpringContext
044: .getBean(MaintenanceDocumentDictionaryService.class)
045: .getFieldDefaultValue((Class) null, "accountNumber");
046: } catch (IllegalArgumentException e) {
047: exceptionThrown = true;
048: } catch (Exception e) {
049: exceptionThrown = false;
050: }
051: assertTrue(
052: "An IllegalArgumentException should have been thrown.",
053: exceptionThrown);
054:
055: // test the docTypeName null argument
056: exceptionThrown = false;
057: try {
058: SpringContext.getBean(
059: MaintenanceDocumentDictionaryService.class)
060: .getFieldDefaultValue((String) null,
061: "accountNumber");
062: } catch (IllegalArgumentException e) {
063: exceptionThrown = true;
064: } catch (Exception e) {
065: exceptionThrown = false;
066: }
067: assertTrue(
068: "An IllegalArgumentException should have been thrown.",
069: exceptionThrown);
070:
071: // test the fieldName null argument
072: exceptionThrown = false;
073: try {
074: SpringContext.getBean(
075: MaintenanceDocumentDictionaryService.class)
076: .getFieldDefaultValue("docTypeName", null);
077: } catch (IllegalArgumentException e) {
078: exceptionThrown = true;
079: } catch (Exception e) {
080: exceptionThrown = false;
081: }
082: assertTrue(
083: "An IllegalArgumentException should have been thrown.",
084: exceptionThrown);
085: }
086:
087: public void testGetFieldDefaultValue_Account() {
088:
089: String result;
090: result = SpringContext.getBean(
091: MaintenanceDocumentDictionaryService.class)
092: .getFieldDefaultValue(Account.class,
093: "accountsFringesBnftIndicator");
094: LOG.debug(result);
095: assertEquals("true", result);
096:
097: }
098:
099: public void testGetFieldDefaultValue_SubAccount() {
100:
101: String result;
102: result = SpringContext.getBean(
103: MaintenanceDocumentDictionaryService.class)
104: .getFieldDefaultValue(SubAccount.class,
105: "subAccountActiveIndicator");
106: LOG.debug(result);
107: assertEquals("true", result);
108:
109: result = SpringContext.getBean(
110: MaintenanceDocumentDictionaryService.class)
111: .getFieldDefaultValue(SubAccount.class,
112: "a21SubAccount.subAccountTypeCode");
113: LOG.debug(result);
114: assertEquals("EX", result);
115:
116: result = SpringContext.getBean(
117: MaintenanceDocumentDictionaryService.class)
118: .getFieldDefaultValue(SubAccount.class,
119: "a21SubAccount.offCampusCode");
120: LOG.debug(result);
121: assertEquals("false", result);
122:
123: }
124:
125: public void testGetFieldDefaultValue_SubObjectCode() {
126:
127: String result;
128:
129: result = SpringContext.getBean(
130: MaintenanceDocumentDictionaryService.class)
131: .getFieldDefaultValue(SubObjCd.class,
132: "universityFiscalYear");
133: LOG.debug(result);
134: assertEquals(getValueFromFinder(FiscalYearFinder.class), result);
135:
136: result = SpringContext.getBean(
137: MaintenanceDocumentDictionaryService.class)
138: .getFieldDefaultValue(SubObjCd.class,
139: "financialSubObjectActiveIndicator");
140: LOG.debug(result);
141: assertEquals("true", result);
142:
143: }
144:
145: private String getValueFromFinder(Class finderClass) {
146:
147: ValueFinder valueFinder = null;
148: try {
149: valueFinder = (ValueFinder) finderClass.newInstance();
150: } catch (InstantiationException e) {
151: e.printStackTrace();
152: assertTrue(
153: "An InstantiationException should not have been thrown.",
154: false);
155: } catch (IllegalAccessException e) {
156: e.printStackTrace();
157: assertTrue(
158: "An IllegalAccessException should not have been thrown.",
159: false);
160: }
161:
162: assertNotNull("The valueFinder object should not be null.",
163: valueFinder);
164:
165: return valueFinder.getValue();
166: }
167: }
|