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 java.util.LinkedHashMap;
019: import java.util.Map;
020:
021: import org.kuali.core.datadictionary.DataDictionary;
022: import org.kuali.core.document.DocumentBase;
023: import org.kuali.core.document.MaintenanceDocument;
024: import org.kuali.core.document.MaintenanceDocumentBase;
025: import org.kuali.kfs.context.KualiTestBase;
026: import org.kuali.kfs.context.SpringContext;
027: import org.kuali.module.financial.document.InternalBillingDocument;
028: import org.kuali.test.ConfigureContext;
029:
030: /**
031: * This class tests the DataDictionary service. It tests the actual service, after letting Spring initialize it using whatever
032: * configuration information is in the current, project-wide Spring config file(s)
033: */
034: @ConfigureContext
035: public class DataDictionaryServiceTest extends KualiTestBase {
036:
037: public final void testGetDataDictionary() {
038: DataDictionary dataDictionary = SpringContext.getBean(
039: DataDictionaryService.class).getDataDictionary();
040: assertNotNull(dataDictionary);
041:
042: Map businessObjectEntries = dataDictionary
043: .getBusinessObjectEntries();
044: assertNotNull(businessObjectEntries);
045:
046: Map documentEntries = dataDictionary.getDocumentEntries();
047: assertNotNull(documentEntries);
048: }
049:
050: public final void testGetDocumentClassByTypeName_nullName() {
051: boolean failedAsExpected = false;
052:
053: try {
054: SpringContext.getBean(DataDictionaryService.class)
055: .getDocumentClassByTypeName(null);
056: } catch (IllegalArgumentException e) {
057: failedAsExpected = true;
058: }
059:
060: assertTrue(failedAsExpected);
061: }
062:
063: public final void testGetDocumentClassByTypeName_blankName() {
064: boolean failedAsExpected = false;
065:
066: try {
067: SpringContext.getBean(DataDictionaryService.class)
068: .getDocumentClassByTypeName(" ");
069: } catch (IllegalArgumentException e) {
070: failedAsExpected = true;
071: }
072:
073: assertTrue(failedAsExpected);
074: }
075:
076: public final void testGetDocumentClassByTypeName_unknownName() {
077: Class clazz = SpringContext
078: .getBean(DataDictionaryService.class)
079: .getDocumentClassByTypeName("foo");
080:
081: assertNull(clazz);
082: }
083:
084: public final void testGetDocumentClassByTypeName_knownNameTransactionalDocument() {
085: Class clazz = SpringContext
086: .getBean(DataDictionaryService.class)
087: .getDocumentClassByTypeName("InternalBillingDocument");
088:
089: assertEquals(InternalBillingDocument.class, clazz);
090: }
091:
092: public final void testGetDocumentClassByTypeName_knownNameMaintenanceDocument() {
093: boolean passedAsExpected = false;
094:
095: Class clazz = SpringContext
096: .getBean(DataDictionaryService.class)
097: .getDocumentClassByTypeName(
098: "SubAccountMaintenanceDocument");
099:
100: try {
101: MaintenanceDocument clazzInstance = (MaintenanceDocument) clazz
102: .newInstance();
103: passedAsExpected = (clazzInstance instanceof MaintenanceDocumentBase);
104: } catch (Exception e) {
105: passedAsExpected = false;
106: }
107:
108: assertTrue(
109: "getClassByName failed for known maintenanceDocument type",
110: passedAsExpected);
111: }
112:
113: public final void testGetDocumentTypeCodeByTypeName_nullName() {
114: try {
115: SpringContext.getBean(DataDictionaryService.class)
116: .getDocumentTypeCodeByTypeName(null);
117: fail("got null type name");
118: } catch (IllegalArgumentException e) {
119: // good
120: }
121: }
122:
123: public final void testGetDocumentTypeCodeByTypeName_blankName() {
124: try {
125: SpringContext.getBean(DataDictionaryService.class)
126: .getDocumentTypeCodeByTypeName(" ");
127: fail("got blank type name");
128: } catch (IllegalArgumentException e) {
129: // good
130: }
131: }
132:
133: public final void testGetDocumentTypeCodeByTypeName_unknownName() {
134: assertNull(SpringContext.getBean(DataDictionaryService.class)
135: .getDocumentTypeCodeByTypeName("foo"));
136: }
137:
138: public final void testGetDocumentTypeCodeByTypeName_knownNameTransactionalDocument() {
139: assertEquals("IB", SpringContext.getBean(
140: DataDictionaryService.class)
141: .getDocumentTypeCodeByTypeName(
142: "InternalBillingDocument"));
143: }
144:
145: public final void testGetDocumentTypeCodeByTypeName_knownNameMaintenanceDocument() {
146: assertEquals("SACC", SpringContext.getBean(
147: DataDictionaryService.class)
148: .getDocumentTypeCodeByTypeName(
149: "SubAccountMaintenanceDocument"));
150: }
151:
152: public final void testGetDocumentTypeNameByClass_nullClass() {
153: boolean failedAsExpected = false;
154:
155: try {
156: SpringContext.getBean(DataDictionaryService.class)
157: .getDocumentTypeNameByClass(null);
158: } catch (IllegalArgumentException e) {
159: failedAsExpected = true;
160: }
161:
162: assertTrue(failedAsExpected);
163: }
164:
165: public final void testGetDocumentTypeNameByClass_nonDocClass() {
166: boolean failedAsExpected = false;
167:
168: try {
169: SpringContext.getBean(DataDictionaryService.class)
170: .getDocumentTypeNameByClass(Integer.class);
171: } catch (IllegalArgumentException e) {
172: failedAsExpected = true;
173: }
174:
175: assertTrue(failedAsExpected);
176: }
177:
178: public final void testGetDocumentTypeNameByClass_unknownDocClass() {
179: String documentTypeName = SpringContext.getBean(
180: DataDictionaryService.class)
181: .getDocumentTypeNameByClass(MockDocument.class);
182:
183: assertNull(documentTypeName);
184: }
185:
186: public final void testGetDocumentTypeNameByClass_knownTransactionalDocument() {
187: String documentTypeName = SpringContext.getBean(
188: DataDictionaryService.class)
189: .getDocumentTypeNameByClass(
190: InternalBillingDocument.class);
191:
192: assertEquals("InternalBillingDocument", documentTypeName);
193: }
194:
195: private static class MockDocument extends DocumentBase {
196: @Override
197: public final void populateDocumentForRouting() {
198: throw new UnsupportedOperationException();
199: }
200:
201: protected LinkedHashMap toStringMapper() {
202: return new LinkedHashMap();
203: }
204:
205: public boolean getAllowsCopy() {
206: return false;
207: }
208: }
209: }
|