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.TransactionalDocumentEntry;
024: import org.kuali.rice.KNSServiceLocator;
025: import org.kuali.test.KNSTestBase;
026: import org.kuali.test.KNSWithTestSpringContext;
027:
028: import edu.sampleu.travel.document.TravelDocument2;
029: import edu.sampleu.travel.document.rule.TravelDocumentRule;
030:
031: /**
032: * This class is used to test the TransactionalDocumentEntryMapper.
033: *
034: *
035: */
036: @KNSWithTestSpringContext
037: public class TransactionalDocumentEntryMapperTest extends KNSTestBase {
038: private DataDictionaryBuilder builder;
039: private DataDictionary dataDictionary;
040:
041: @Override
042: public void setUp() throws Exception {
043: super .setUp();
044:
045: builder = new DataDictionaryBuilder(KNSServiceLocator
046: .getValidationCompletionUtils());
047: builder.setKualiGroupService(KNSServiceLocator
048: .getKualiGroupService());
049: builder.setKualiConfigurationService(KNSServiceLocator
050: .getKualiConfigurationService());
051:
052: builder
053: .addUniqueEntries(
054: "classpath:/edu/sampleu/travel/datadictionary/TravelRequestDocument.xml",
055: true);
056: builder
057: .addUniqueEntries(
058: "classpath:org/kuali/core/bo/datadictionary/AttributeReferenceDummy.xml",
059: true);
060: builder.parseDocument("TravelRequest", true);
061:
062: dataDictionary = builder.getDataDictionary();
063: }
064:
065: public final void testConstructor_nullEntry() {
066: boolean failedAsExpected = false;
067:
068: try {
069: new TransactionalDocumentEntryMapper().mapEntry(null);
070: } catch (IllegalArgumentException e) {
071: failedAsExpected = true;
072: }
073:
074: assertTrue(failedAsExpected);
075: }
076:
077: @Test
078: public final void testExportSimpleProperties_classname() {
079: Map entryMap = mapTravelDocument2();
080:
081: String path = "documentClass";
082: String property = (String) ExporterTestUtils.traverseMap(
083: entryMap, path);
084: assertEquals(TravelDocument2.class.getName(), property);
085: }
086:
087: @Test
088: public final void testExportSimpleProperties_documentTypeName() {
089: Map entryMap = mapTravelDocument2();
090:
091: String path = "documentTypeName";
092: String property = (String) ExporterTestUtils.traverseMap(
093: entryMap, path);
094: assertEquals("TravelRequest", property);
095: }
096:
097: @Test
098: public final void testExportSimpleProperties_documentTypeCode() {
099: Map entryMap = mapTravelDocument2();
100:
101: String path = "documentTypeCode";
102: String property = (String) ExporterTestUtils.traverseMap(
103: entryMap, path);
104: assertEquals("TRD2", property);
105: }
106:
107: @Test
108: public final void testExportSimpleProperties_businessRulesClass() {
109: Map entryMap = mapTravelDocument2();
110:
111: String path = "businessRulesClass";
112: String property = (String) ExporterTestUtils.traverseMap(
113: entryMap, path);
114: assertEquals(TravelDocumentRule.class.getName(), property);
115: }
116:
117: @Test
118: public final void testExportSimpleProperties_label() {
119: Map entryMap = mapTravelDocument2();
120:
121: String path = "label";
122: String property = (String) ExporterTestUtils.traverseMap(
123: entryMap, path);
124: assertEquals("Travel Doc 2", property);
125: }
126:
127: @Test
128: public final void testExportSimpleProperties_shortLabel() {
129: Map entryMap = mapTravelDocument2();
130:
131: String path = "shortLabel";
132: String property = (String) ExporterTestUtils.traverseMap(
133: entryMap, path);
134: assertEquals("TRDoc2", property);
135: }
136:
137: @Test
138: public final void testExportSimpleProperties_summary() {
139: Map entryMap = mapTravelDocument2();
140:
141: String path = "summary";
142: String property = (String) ExporterTestUtils.traverseMap(
143: entryMap, path);
144: assertEquals(" ", property);
145: }
146:
147: @Test
148: public final void testExportSimpleProperties_description() {
149: Map entryMap = mapTravelDocument2();
150:
151: String path = "description";
152: String property = (String) ExporterTestUtils.traverseMap(
153: entryMap, path);
154: assertTrue(property.equals("Doing it right"));
155: }
156:
157: @Test
158: public final void testExportSimpleProperties_allowsCopy() {
159: Map entryMap = mapTravelDocument2();
160:
161: String path = "allowsCopy";
162: String property = (String) ExporterTestUtils.traverseMap(
163: entryMap, path);
164: assertEquals("false", property);
165: }
166:
167: @Test
168: public final void testExportSimpleProperties_allowsErrorCorrection() {
169: Map entryMap = mapTravelDocument2();
170:
171: String path = "allowsErrorCorrection";
172: String property = (String) ExporterTestUtils.traverseMap(
173: entryMap, path);
174: assertEquals("false", property);
175: }
176:
177: @Test
178: public final void testExportSimpleProperties_documentAuthorizerClass() {
179: Map entryMap = mapTravelDocument2();
180:
181: String path = "documentAuthorizerClass";
182: String property = (String) ExporterTestUtils.traverseMap(
183: entryMap, path);
184:
185: assertEquals(
186: "edu.sampleu.travel.document.authorizer.TravelDocumentAuthorizer",
187: property);
188: }
189:
190: /* utility methods */
191: private Map mapTravelDocument2() {
192:
193: TransactionalDocumentEntry entry = (TransactionalDocumentEntry) dataDictionary
194: .getDictionaryObjectEntry(TravelDocument2.class
195: .getName());
196: TransactionalDocumentEntryMapper mapper = new TransactionalDocumentEntryMapper();
197: Map map = mapper.mapEntry(entry).getExportData();
198:
199: return map;
200: }
201: }
|