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.datadictionary.exporter;
017:
018: import java.util.Map;
019:
020: import org.junit.Test;
021: import org.kuali.core.bo.BusinessObjectAttributeEntry;
022: import org.kuali.core.datadictionary.BusinessObjectEntry;
023: import org.kuali.core.datadictionary.DataDictionary;
024: import org.kuali.core.datadictionary.DataDictionaryBuilder;
025: import org.kuali.core.datadictionary.bos.PaymentReasonCode;
026: import org.kuali.rice.KNSServiceLocator;
027: import org.kuali.test.KNSTestBase;
028: import org.kuali.test.KNSWithTestSpringContext;
029:
030: /**
031: * This class is used to test the BusinessObjectEntryMapper.
032: *
033: *
034: */
035: @KNSWithTestSpringContext
036: public class BusinessObjectEntryMapperTest extends KNSTestBase {
037: private DataDictionaryBuilder builder;
038: private DataDictionary dataDictionary;
039:
040: @Override
041: public void setUp() throws Exception {
042: super .setUp();
043:
044: if (null == builder) {
045: builder = new DataDictionaryBuilder(KNSServiceLocator
046: .getValidationCompletionUtils());
047:
048: builder.setKualiGroupService(KNSServiceLocator
049: .getKualiGroupService());
050: builder.setKualiConfigurationService(KNSServiceLocator
051: .getKualiConfigurationService());
052:
053: // builder.addUniqueEntries("classpath:org/kuali/core/bo/datadictionary/AdHocRoutePerson.xml", true);
054: // builder.addUniqueEntries("classpath:org/kuali/core/bo/datadictionary/AdHocRouteWorkgroup.xml", true);
055: // builder.addUniqueEntries("classpath:org/kuali/core/bo/datadictionary/Attachment.xml", true);
056: // builder.addUniqueEntries("classpath:org/kuali/core/bo/datadictionary/AttributeReferenceDummy.xml", true);
057: // builder.addUniqueEntries("classpath:org/kuali/core/bo/datadictionary/BusinessObjectAttributeEntry.xml", true);
058: // builder.addUniqueEntries("classpath:org/kuali/core/bo/datadictionary/BusinessRule.xml", true);
059: // builder.addUniqueEntries("classpath:org/kuali/core/bo/datadictionary/BusinessRuleSecurity.xml", true);
060: // builder.addUniqueEntries("classpath:org/kuali/core/bo/datadictionary/Campus.xml", true);
061: // builder.addUniqueEntries("classpath:org/kuali/core/bo/datadictionary/CampusType.xml", true);
062: // builder.addUniqueEntries("classpath:org/kuali/core/bo/datadictionary/DocumentGroup.xml", true);
063: // builder.addUniqueEntries("classpath:org/kuali/core/bo/datadictionary/DocumentHeader.xml", true);
064: // builder.addUniqueEntries("classpath:org/kuali/core/bo/datadictionary/DocumentStatus.xml", true);
065: // builder.addUniqueEntries("classpath:org/kuali/core/bo/datadictionary/DocumentType.xml", true);
066: // builder.addUniqueEntries("classpath:org/kuali/core/bo/datadictionary/EmployeeStatus.xml", true);
067: // builder.addUniqueEntries("classpath:org/kuali/core/bo/datadictionary/EmployeeType.xml", true);
068: // builder.addUniqueEntries("classpath:org/kuali/core/bo/datadictionary/FinancialSystemParameter.xml", true);
069: // builder.addUniqueEntries("classpath:org/kuali/core/bo/datadictionary/FinancialSystemParameterSecurity.xml", true);
070: // builder.addUniqueEntries("classpath:org/kuali/core/bo/datadictionary/Note.xml", true);
071: // builder.addUniqueEntries("classpath:org/kuali/core/bo/datadictionary/NoteType.xml", true);
072: // builder.addUniqueEntries("classpath:org/kuali/core/bo/datadictionary/UniversalUser.xml", true);
073:
074: builder
075: .addUniqueEntries(
076: "classpath:org/kuali/core/datadictionary/test/PaymentReasonCode.xml",
077: true);
078: builder
079: .addUniqueEntries(
080: "classpath:org/kuali/core/bo/datadictionary/BusinessObjectAttributeEntry.xml",
081: true);
082: // builder.addUniqueEntries("classpath:org/kuali/module/chart/datadictionary/", true);
083: // builder.addUniqueEntries("classpath:org/kuali/module/financial/datadictionary/", true);
084: // builder.addUniqueEntries("classpath:org/kuali/module/cg/datadictionary/", true);
085: // builder.addUniqueEntries("classpath:org/kuali/module/kra/budget/datadictionary/",true);
086: // builder.addUniqueEntries("classpath:org/kuali/module/kra/routingform/datadictionary/",true);
087:
088: dataDictionary = builder.getDataDictionary();
089: }
090: }
091:
092: @Override
093: public void tearDown() throws Exception {
094: super .tearDown();
095:
096: // free these up to prevent heap overflows
097: builder = null;
098: dataDictionary = null;
099: }
100:
101: @Test
102: public final void testConstructor_nullEntry() {
103: boolean failedAsExpected = false;
104:
105: try {
106: new BusinessObjectEntryMapper().mapEntry(null);
107: } catch (IllegalArgumentException e) {
108: failedAsExpected = true;
109: } catch (Exception e) {
110: e.printStackTrace();
111: }
112:
113: assertTrue(failedAsExpected);
114: }
115:
116: @Test
117: public final void testExportInquiryProperties_title() {
118: Map entryMap = map(PaymentReasonCode.class);
119:
120: String path = "inquiry.title";
121: String property = (String) ExporterTestUtils.traverseMap(
122: entryMap, path);
123: assertEquals("Payment Reason Code inquiry", property);
124: }
125:
126: @Test
127: public final void testExportInquiryProperties_inquiryField() {
128: Map entryMap = map(PaymentReasonCode.class);
129:
130: String path = "inquiry.inquiryFields.code.attributeName";
131: String property = (String) ExporterTestUtils.traverseMap(
132: entryMap, path);
133: assertEquals("code", property);
134: }
135:
136: @Test
137: public final void testExportInquiryProperties_inquiryFields() {
138: Map entryMap = map(PaymentReasonCode.class);
139:
140: // test retrieval, order and value for all fields
141: String path = "inquiry.inquiryFields";
142: String[][] expectedFieldValues = {
143: { "code.attributeName", "code" },
144: { "name.attributeName", "name" },
145: { "description.attributeName", "description" },
146: { "active.attributeName", "active" } };
147:
148: Map fields = (Map) ExporterTestUtils
149: .traverseMap(entryMap, path);
150: ExporterTestUtils.comparePropertyStrings(fields,
151: expectedFieldValues);
152: }
153:
154: @Test
155: public final void testExportLookupProperties_title() {
156: Map entryMap = map(BusinessObjectAttributeEntry.class);
157:
158: String path = "lookup.title";
159: String property = (String) ExporterTestUtils.traverseMap(
160: entryMap, path);
161: assertEquals("Data Dictionary Attribute Lookup", property);
162: }
163:
164: @Test
165: public final void testExportLookupProperties_noMenubar() {
166: Map entryMap = map(BusinessObjectAttributeEntry.class);
167:
168: String path = "lookup.menubar";
169: String property = (String) ExporterTestUtils.traverseMap(
170: entryMap, path);
171: assertNull(property);
172: }
173:
174: @Test
175: public final void testExportLookupProperties_menubar() {
176: Map entryMap = map(PaymentReasonCode.class);
177:
178: String path = "lookup.menubar";
179: String property = (String) ExporterTestUtils.traverseMap(
180: entryMap, path);
181: assertTrue(property.equals("payment reason code menu bar"));
182: }
183:
184: @Test
185: public final void testExportLookupProperties_instructions() {
186: Map entryMap = map(BusinessObjectAttributeEntry.class);
187:
188: String path = "lookup.instructions";
189: String property = (String) ExporterTestUtils.traverseMap(
190: entryMap, path);
191: assertEquals("Lookup attributes for a Business Object.",
192: property);
193: }
194:
195: @Test
196: public final void testExportLookupProperties_defaultSort_sortAscending() {
197: Map entryMap = map(BusinessObjectAttributeEntry.class);
198:
199: String path = "lookup.defaultSort.sortAscending";
200: String property = (String) ExporterTestUtils.traverseMap(
201: entryMap, path);
202: assertEquals("false", property);
203: }
204:
205: @Test
206: public final void testExportLookupProperties_defaultSort_field() {
207: Map entryMap = map(BusinessObjectAttributeEntry.class);
208:
209: String path = "lookup.defaultSort.sortAttributes.attributeName.attributeName";
210: String property = (String) ExporterTestUtils.traverseMap(
211: entryMap, path);
212: assertEquals("attributeName", property);
213: }
214:
215: @Test
216: public final void testExportLookupProperties_defaultSort_fields() {
217: // ValidBusinessObject.xml defines ObjectCode businessObjectEntry
218: Map entryMap = map(PaymentReasonCode.class);
219:
220: // test retrieval, order, and value for all fields
221: String path = "lookup.defaultSort.sortAttributes";
222: String[][] expectedValues = { { "code.attributeName", "code" } };
223:
224: Map sortAttributes = (Map) ExporterTestUtils.traverseMap(
225: entryMap, path);
226: assertEquals(1, sortAttributes.size());
227: ExporterTestUtils.comparePropertyStrings(sortAttributes,
228: expectedValues);
229: }
230:
231: @Test
232: public final void testExportLookupProperties_lookupField() {
233: Map entryMap = map(PaymentReasonCode.class);
234:
235: String path = "lookup.lookupFields.code.attributeName";
236: String property = (String) ExporterTestUtils.traverseMap(
237: entryMap, path);
238: assertEquals(property, "code");
239: }
240:
241: @Test
242: public final void testExportLookupProperties_lookupFields() {
243: // ValidBusinessObject.xml defines entry for ObjectCode.class
244: Map entryMap = map(PaymentReasonCode.class);
245:
246: // test retrieval, order, and value for all fields
247: String path = "lookup.lookupFields";
248: String[][] expectedValues = { { "code.required", "true" },
249: { "name.attributeName", "name" },
250: { "name.required", "false" },
251: { "description.attributeName", "description" },
252: { "description.required", "false" },
253: { "active.attributeName", "active" },
254: { "active.required", "false" }
255:
256: };
257:
258: Map lookupFields = (Map) ExporterTestUtils.traverseMap(
259: entryMap, path);
260: assertEquals(4, lookupFields.size());
261: ExporterTestUtils.comparePropertyStrings(lookupFields,
262: expectedValues);
263: }
264:
265: @Test
266: public final void testExportLookupProperties_resultField() {
267: Map entryMap = map(BusinessObjectAttributeEntry.class);
268:
269: String path = "lookup.resultFields.attributeMaxLength.attributeName";
270: String property = (String) ExporterTestUtils.traverseMap(
271: entryMap, path);
272: assertEquals(property, "attributeMaxLength");
273: }
274:
275: @Test
276: public final void testExportLookupProperties_resultFields() {
277: Map entryMap = map(BusinessObjectAttributeEntry.class);
278:
279: // test retrieval, order, and value for all fields
280: String path = "lookup.resultFields";
281: String[][] expectedValues = {
282: { "attributeName.attributeName", "attributeName" },
283: { "attributeLabel.attributeName", "attributeLabel" },
284: { "attributeSummary.attributeName", "attributeSummary" },
285: { "attributeMaxLength.attributeName",
286: "attributeMaxLength", },
287: { "attributeValidatingExpression.attributeName",
288: "attributeValidatingExpression" },
289: { "attributeControlType.attributeName",
290: "attributeControlType" },
291: { "attributeFormatterClassName.attributeName",
292: "attributeFormatterClassName" }, };
293:
294: Map resultFields = (Map) ExporterTestUtils.traverseMap(
295: entryMap, path);
296: assertEquals(7, resultFields.size());
297: ExporterTestUtils.comparePropertyStrings(resultFields,
298: expectedValues);
299: }
300:
301: @Test
302: public final void testExportAttribute_simpleProperties() {
303: Map entryMap = map(PaymentReasonCode.class);
304:
305: String path = "attributes.description";
306: String[][] expectedValues = { { "forceUppercase", "false" },
307: { "label", "Payment Reason Description" },
308: { "shortLabel", "Description" },
309: { "maxLength", "2500" }, { "summary", " " },
310: { "*description", ".*meaningful.*codes.*" },
311: { "formatterClass", null }, };
312:
313: Map attribute = (Map) ExporterTestUtils.traverseMap(entryMap,
314: path);
315: ExporterTestUtils.comparePropertyStrings(attribute,
316: expectedValues);
317: }
318:
319: @Test
320: public final void testExportAttributes_simpleProperties() {
321: Map entryMap = map(PaymentReasonCode.class);
322:
323: String path = "attributes";
324: String[][] expectedValues = { { "code.name", "code" },
325: { "code.maxLength", "1" },
326: { "code.forceUppercase", "true" },
327: { "name.name", "name" }, { "name.maxLength", "40" },
328: { "name.forceUppercase", "false" },
329: { "description.name", "description" },
330: { "description.maxLength", "2500" },
331: { "description.forceUppercase", "false" },
332: { "active.name", "active" },
333: { "active.maxLength", "1" },
334: { "active.forceUppercase", "false" },
335: { "versionNumber.name", "versionNumber" },
336: { "versionNumber.maxLength", "8" },
337: { "versionNumber.forceUppercase", "true" } };
338:
339: Map attributes = (Map) ExporterTestUtils.traverseMap(entryMap,
340: path);
341: assertEquals(5, attributes.size());
342: ExporterTestUtils.comparePropertyStrings(attributes,
343: expectedValues);
344:
345: // testing additional attribute-properties
346: Map anotherEntryMap = map(PaymentReasonCode.class);
347:
348: String[][] moreExpectedValues = {
349: // default to false
350: { "code.name", "code" }, { "code.required", "true" },
351: // explicitly set to false
352: { "name.name", "name" }, { "name.required", "false" } };
353:
354: ExporterTestUtils.comparePropertyStrings(
355: (Map) ExporterTestUtils.traverseMap(anotherEntryMap,
356: path), moreExpectedValues);
357:
358: }
359:
360: @Test
361: public final void testExportAttribute_control() {
362: Map entryMap = map(PaymentReasonCode.class);
363:
364: // test several attributes of differing types
365: String codePath = "attributes.code.control";
366: String[][] codeExpectedValues = { { "text", "true" },
367: { "size", "1" } };
368: ExporterTestUtils
369: .comparePropertyStrings((Map) ExporterTestUtils
370: .traverseMap(entryMap, codePath),
371: codeExpectedValues);
372:
373: String namePath = "attributes.name.control";
374: String[][] nameExpectedValues = { { "text", "true" },
375: { "size", "40" } };
376: ExporterTestUtils
377: .comparePropertyStrings((Map) ExporterTestUtils
378: .traverseMap(entryMap, namePath),
379: nameExpectedValues);
380:
381: String descrciptionPath = "attributes.description.control";
382: String[][] descriptionExpectedValues = {
383: { "textarea", "true" }, { "rows", "10" },
384: { "cols", "50" } };
385: ExporterTestUtils.comparePropertyStrings(
386: (Map) ExporterTestUtils.traverseMap(entryMap,
387: descrciptionPath), descriptionExpectedValues);
388:
389: String activePath = "attributes.active.control";
390: String[][] activeExpectedValues = { { "checkbox", "true" } };
391: ExporterTestUtils.comparePropertyStrings(
392: (Map) ExporterTestUtils.traverseMap(entryMap,
393: activePath), activeExpectedValues);
394:
395: String versionNumberPath = "attributes.versionNumber.control";
396: String[][] versionNumberExpectedValues = { { "hidden", "true" } };
397: ExporterTestUtils
398: .comparePropertyStrings((Map) ExporterTestUtils
399: .traverseMap(entryMap, versionNumberPath),
400: versionNumberExpectedValues);
401: }
402:
403: /* utility methods */
404: private Map map(Class entryClass) {
405: Map map = null;
406:
407: BusinessObjectEntry entry = dataDictionary
408: .getBusinessObjectEntry(entryClass.getName());
409: BusinessObjectEntryMapper mapper = new BusinessObjectEntryMapper();
410: map = mapper.mapEntry(entry).getExportData();
411:
412: return map;
413: }
414: }
|