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.datadictionary.DataDictionary;
022: import org.kuali.core.datadictionary.DataDictionaryBuilder;
023: import org.kuali.core.datadictionary.MaintenanceDocumentEntry;
024: import org.kuali.core.datadictionary.bos.PaymentReasonCode;
025: import org.kuali.core.impls.RiceTestMaintenanceDocumentRule;
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 MaintenanceDocumentEntryExporter.
032: *
033: *
034: */
035: @KNSWithTestSpringContext
036: public class MaintenanceDocumentEntryMapperTest extends KNSTestBase {
037: private DataDictionaryBuilder builder;
038: private DataDictionary dataDictionary;
039:
040: @Override
041: public void setUp() throws Exception {
042: super .setUp();
043:
044: builder = new DataDictionaryBuilder(KNSServiceLocator
045: .getValidationCompletionUtils());
046: builder.setKualiGroupService(KNSServiceLocator
047: .getKualiGroupService());
048: builder.setKualiConfigurationService(KNSServiceLocator
049: .getKualiConfigurationService());
050:
051: builder
052: .addUniqueEntries(
053: "classpath:org/kuali/core/datadictionary/test/PaymentReasonCodeMaintenanceDocument.xml",
054: true);
055: dataDictionary = builder.getDataDictionary();
056: }
057:
058: public final void testConstructor_nullEntry() {
059: boolean failedAsExpected = false;
060:
061: try {
062: new MaintenanceDocumentEntryMapper().mapEntry(null);
063: } catch (IllegalArgumentException e) {
064: failedAsExpected = true;
065: }
066:
067: assertTrue(failedAsExpected);
068: }
069:
070: @Test
071: public final void testExportSimpleProperties_businessObjectClass() {
072: Map entryMap = mapAccountMaintenanceDocument();
073:
074: String path = "businessObjectClass";
075: String property = (String) ExporterTestUtils.traverseMap(
076: entryMap, path);
077: assertEquals(PaymentReasonCode.class.getName(), property);
078: }
079:
080: @Test
081: public final void testExportSimpleProperties_maintainableClass() {
082: Map entryMap = mapAccountMaintenanceDocument();
083:
084: String path = "maintainableClass";
085: String property = (String) ExporterTestUtils.traverseMap(
086: entryMap, path);
087: assertEquals(
088: org.kuali.core.maintenance.KualiMaintainableImpl.class
089: .getName(), property);
090: }
091:
092: @Test
093: public final void testExportSimpleProperties_documentTypeName() {
094: Map entryMap = mapAccountMaintenanceDocument();
095:
096: String path = "documentTypeName";
097: String property = (String) ExporterTestUtils.traverseMap(
098: entryMap, path);
099: assertEquals("KualiPaymentReasonCodeMaintenanceDocument",
100: property);
101: }
102:
103: @Test
104: public final void testExportSimpleProperties_documentTypeCode() {
105: Map entryMap = mapAccountMaintenanceDocument();
106:
107: String path = "documentTypeCode";
108: String property = (String) ExporterTestUtils.traverseMap(
109: entryMap, path);
110: assertEquals("DVPR", property);
111: }
112:
113: @Test
114: public final void testExportSimpleProperties_businessRulesClass() {
115: Map entryMap = mapAccountMaintenanceDocument();
116:
117: String path = "businessRulesClass";
118: String property = (String) ExporterTestUtils.traverseMap(
119: entryMap, path);
120: assertEquals(RiceTestMaintenanceDocumentRule.class.getName(),
121: property);
122: }
123:
124: @Test
125: public final void testExportSimpleProperties_label() {
126: Map entryMap = mapAccountMaintenanceDocument();
127:
128: String path = "label";
129: String property = (String) ExporterTestUtils.traverseMap(
130: entryMap, path);
131: assertEquals("Payment Reason Code Maintenance Document",
132: property);
133: }
134:
135: @Test
136: public final void testExportSimpleProperties_shortLabel() {
137: Map entryMap = mapAccountMaintenanceDocument();
138:
139: String path = "shortLabel";
140: String property = (String) ExporterTestUtils.traverseMap(
141: entryMap, path);
142: assertEquals("PayReasonMaintDoc", property);
143: }
144:
145: @Test
146: public final void testExportSimpleProperties_summary() {
147: Map entryMap = mapAccountMaintenanceDocument();
148:
149: String path = "summary";
150: String property = (String) ExporterTestUtils.traverseMap(
151: entryMap, path);
152: assertEquals("Payment Reason Code Maintenance Document",
153: property);
154: }
155:
156: @Test
157: public final void testExportSimpleProperties_description() {
158: Map entryMap = mapAccountMaintenanceDocument();
159:
160: String path = "description";
161: String property = (String) ExporterTestUtils.traverseMap(
162: entryMap, path);
163: assertTrue(property
164: .equals("Document used to create or update Payment Reason objects"));
165: }
166:
167: @Test
168: public final void testExportSimpleProperties_documentAuthorizerClass() {
169: Map entryMap = mapAccountMaintenanceDocument();
170:
171: String path = "documentAuthorizerClass";
172: String property = (String) ExporterTestUtils.traverseMap(
173: entryMap, path);
174:
175: assertEquals(
176: "org.kuali.core.document.authorization.MaintenanceDocumentAuthorizerBase",
177: property);
178: }
179:
180: @Test
181: public final void testExportSection() {
182: Map entryMap = mapAccountMaintenanceDocument();
183:
184: String titlePath = "maintainableSections.0.title";
185: String title = (String) ExporterTestUtils.traverseMap(entryMap,
186: titlePath);
187: assertEquals("Edit Payment Reason", title);
188:
189: String itemsPath = "maintainableSections.0.maintainableItems";
190: Map items = (Map) ExporterTestUtils.traverseMap(entryMap,
191: itemsPath);
192: assertEquals(5, items.size());
193:
194: Map item = (Map) items.get("code");
195: assertEquals("code", item.get("name"));
196: assertEquals("true", item.get("required"));
197: }
198:
199: @Test
200: public final void testExportSections() {
201: Map entryMap = mapAccountMaintenanceDocument();
202:
203: String sectionsPath = "maintainableSections";
204: Map sections = (Map) ExporterTestUtils.traverseMap(entryMap,
205: sectionsPath);
206: assertEquals(2, sections.size());
207:
208: // check section metadata
209: String[][] expectedSectionsData = {
210: { "0.title", "Edit Payment Reason" },
211: { "1.title", "Maintenance Section 2" } };
212: ExporterTestUtils.comparePropertyStrings(sections,
213: expectedSectionsData);
214:
215: // check section 0 item data
216: // ain't nothing but fields, so far
217: String[][] expectedItemData0 = { { "code.field", "true" },
218: { "code.name", "code" }, { "code.required", "true" },
219: { "name.field", "true" }, { "name.name", "name" },
220: { "name.required", "false" },
221: { "description.field", "true" },
222: { "description.name", "description" },
223: { "description.required", "false" },
224: { "active.field", "true" },
225: { "active.name", "active" },
226: { "active.required", "false" },
227: { "versionNumber.field", "true" },
228: { "versionNumber.name", "versionNumber" },
229: { "versionNumber.required", "false" } };
230:
231: Map items0 = (Map) ExporterTestUtils.traverseMap(sections,
232: "0.maintainableItems");
233: ExporterTestUtils.comparePropertyStrings(items0,
234: expectedItemData0);
235:
236: String[][] expectedItemData1 = {
237: { "section2Field1.field", "true" },
238: { "section2Field1.name", "section2Field1" },
239: { "section2Field1.required", "true" },
240: { "section2Field2.field", "true" },
241: { "section2Field2.name", "section2Field2" },
242: { "section2Field2.required", "false" } };
243:
244: Map items2 = (Map) ExporterTestUtils.traverseMap(sections,
245: "1.maintainableItems");
246: ExporterTestUtils.comparePropertyStrings(items2,
247: expectedItemData1);
248:
249: }
250:
251: /* utility methods */
252: private Map mapAccountMaintenanceDocument() {
253: Class entryClass = PaymentReasonCode.class;
254:
255: MaintenanceDocumentEntry entry = dataDictionary
256: .getMaintenanceDocumentEntryForBusinessObjectClass(entryClass);
257: MaintenanceDocumentEntryMapper mapper = new MaintenanceDocumentEntryMapper();
258: Map map = mapper.mapEntry(entry).getExportData();
259:
260: return map;
261: }
262: }
|