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:
017: package org.kuali.core.datadictionary;
018:
019: import org.apache.commons.beanutils.ConversionException;
020: import org.apache.log4j.Level;
021: import org.junit.Test;
022: import org.kuali.core.datadictionary.exception.ClassValidationException;
023: import org.kuali.rice.KNSServiceLocator;
024: import org.kuali.test.KNSTestBase;
025: import org.kuali.test.KNSWithTestSpringContext;
026: import org.xml.sax.SAXParseException;
027:
028: /**
029: * This class is used to test the DataDictionaryBuilder Transactional Document
030: * object.
031: */
032: @KNSWithTestSpringContext
033: public class DataDictionaryBuilder_TransactionalDocumentTest extends
034: KNSTestBase {
035:
036: DataDictionaryBuilder builder = null;
037:
038: static final public String IB_DD_XML = "classpath:org/kuali/module/financial/datadictionary/docs/KualiInternalBillingDocument.xml";
039:
040: @Override
041: public void setUp() throws Exception {
042: super .setUp();
043: builder = new DataDictionaryBuilder(KNSServiceLocator
044: .getValidationCompletionUtils());
045: builder.addUniqueEntries(
046: DataDictionaryBuilderTest.PACKAGE_CORE_BO, true);
047: builder.addUniqueEntries(
048: DataDictionaryBuilderTest.PACKAGE_CORE_DOCUMENT, true);
049: setLogLevel("org.apache.commons.digester", Level.FATAL);
050: setLogLevel("org.kuali.core.datadictionary.XmlErrorHandler",
051: Level.FATAL);
052: }
053:
054: @Test
055: public final void testDataDictionaryBuilder_transactionalDocument_blankDocumentClass() {
056: String INPUT_FILE = DataDictionaryBuilderTest.TESTPACKAGE_INVALID
057: + "td/BlankDocumentClass.xml";
058:
059: boolean failedAsExpected = false;
060:
061: try {
062: builder.addUniqueEntries(INPUT_FILE, true);
063: builder.parseDocument("BlankDocumentClass", true);
064: } catch (DataDictionaryException e) {
065: if (DataDictionaryUtils.saxCause(e) instanceof ConversionException) {
066: failedAsExpected = true;
067: }
068: }
069:
070: assertTrue(failedAsExpected);
071: }
072:
073: @Test
074: public final void testDataDictionaryBuilder_transactionalDocument_invalid() {
075: String INPUT_FILE = DataDictionaryBuilderTest.TESTPACKAGE_INVALID
076: + "td/InvalidTransactionalDocument.xml";
077:
078: boolean failedAsExpected = false;
079:
080: try {
081: builder.addUniqueEntries(INPUT_FILE, true);
082: builder.parseDocument("InvalidTransactionalDocument", true);
083: } catch (DataDictionaryException e) {
084: if (DataDictionaryUtils.saxCause(e) instanceof IllegalStateException) {
085: failedAsExpected = true;
086: } else {
087: throw e;
088: }
089: }
090:
091: assertTrue(failedAsExpected);
092: }
093:
094: @Test
095: public final void testDataDictionaryBuilder_transactionalDocument_invalidDocumentClass() {
096: String INPUT_FILE = DataDictionaryBuilderTest.TESTPACKAGE_INVALID
097: + "td/InvalidDocumentClass.xml";
098:
099: boolean failedAsExpected = false;
100:
101: try {
102: builder.getDataDictionary().setAllowOverrides(true);
103: builder.addOverrideEntries(INPUT_FILE, true);
104: builder.parseDocument("InvalidDocumentClass", true);
105: } catch (DataDictionaryException e) {
106: if (DataDictionaryUtils.saxCause(e) instanceof ClassValidationException) {
107: failedAsExpected = true;
108: }
109: }
110:
111: assertTrue(failedAsExpected);
112: }
113:
114: @Test
115: public final void testDataDictionaryBuilder_transactionalDocument_unknownDocumentClass() {
116: String INPUT_FILE = DataDictionaryBuilderTest.TESTPACKAGE_INVALID
117: + "td/UnknownDocumentClass.xml";
118:
119: boolean failedAsExpected = false;
120:
121: try {
122: builder.addUniqueEntries(INPUT_FILE, true);
123: builder.parseDocument("UnknownDocumentClass", true);
124: } catch (DataDictionaryException e) {
125: // if (DataDictionaryUtils.saxCause(e) instanceof ClassValidationException) {
126: failedAsExpected = true;
127: // }
128: }
129:
130: assertTrue(failedAsExpected);
131: }
132:
133: @Test
134: public final void testDataDictionaryBuilder_transactionalDocument_businessRulesClass_blank() {
135: String INPUT_FILE = DataDictionaryBuilderTest.TESTPACKAGE_INVALID
136: + "td/BRBlank.xml";
137:
138: boolean failedAsExpected = false;
139:
140: try {
141: builder.addUniqueEntries(INPUT_FILE, true);
142: builder.parseDocument("BRBlank", true);
143: } catch (DataDictionaryException e) {
144: if (DataDictionaryUtils.saxCause(e) instanceof ConversionException) {
145: failedAsExpected = true;
146: }
147: }
148:
149: assertTrue(failedAsExpected);
150: }
151:
152: @Test
153: public final void testDataDictionaryBuilder_transactionalDocument_businessRulesClass_invalid() {
154: String INPUT_FILE = DataDictionaryBuilderTest.TESTPACKAGE_INVALID
155: + "td/BRInvalid.xml";
156:
157: boolean failedAsExpected = false;
158:
159: try {
160: builder.getDataDictionary().setAllowOverrides(true);
161: builder.addOverrideEntries(INPUT_FILE, true);
162: builder.parseDocument("BRInvalid", true);
163: } catch (DataDictionaryException e) {
164: if (DataDictionaryUtils.saxCause(e) instanceof ClassValidationException) {
165: failedAsExpected = true;
166: }
167: }
168:
169: assertTrue(failedAsExpected);
170: }
171:
172: // @Test
173: // public final void testDataDictionaryBuilder_transactionalDocument_authorization_blankAction() {
174: // String INPUT_FILE = DataDictionaryBuilderTest.TESTPACKAGE_INVALID + "td/AuthBlankAction.xml";
175: //
176: // boolean failedAsExpected = false;
177: //
178: // try {
179: // builder.addUniqueEntries(INPUT_FILE, true);
180: // builder.parseDocument("AuthBlankAction", true);
181: // } catch (DataDictionaryException e) {
182: // if (DataDictionaryUtils.saxCause(e) instanceof ClassValidationException) {
183: // failedAsExpected = true;
184: // }
185: // }
186: //
187: // assertTrue(failedAsExpected);
188: // }
189:
190: @Test
191: public final void testDataDictionaryBuilder_transactionalDocument_authorization_blankWorkgroup() {
192: String INPUT_FILE = DataDictionaryBuilderTest.TESTPACKAGE_INVALID
193: + "td/AuthBlankWorkgroup.xml";
194:
195: boolean failedAsExpected = false;
196:
197: try {
198: builder.addUniqueEntries(INPUT_FILE, true);
199: builder.parseDocument("AuthBlankWorkgroup", true);
200: } catch (DataDictionaryException e) {
201: if (DataDictionaryUtils.saxCause(e) instanceof IllegalArgumentException) {
202: failedAsExpected = true;
203: }
204: }
205:
206: assertTrue(failedAsExpected);
207: }
208:
209: @Test
210: public final void testDataDictionaryBuilder_transactionalDocument_authorization_emptyAuthorization() {
211: String INPUT_FILE = DataDictionaryBuilderTest.TESTPACKAGE_INVALID
212: + "td/AuthEmptyAuthorization.xml";
213:
214: boolean failedAsExpected = false;
215:
216: try {
217: builder.addUniqueEntries(INPUT_FILE, true);
218: builder.parseDocument("AuthEmptyAuthorization", true);
219: } catch (DataDictionaryException e) {
220: if (e.getCause() instanceof SAXParseException) {
221: failedAsExpected = true;
222: }
223: }
224:
225: assertTrue(failedAsExpected);
226: }
227:
228: @Test
229: public final void testDataDictionaryBuilder_transactionalDocument_authorization_emptyAuthorizationsSection() {
230: String INPUT_FILE = DataDictionaryBuilderTest.TESTPACKAGE_INVALID
231: + "td/AuthEmptyAuthorizationsSection.xml";
232:
233: boolean failedAsExpected = false;
234:
235: try {
236: builder.addUniqueEntries(INPUT_FILE, true);
237: builder.parseDocument("AuthEmptyAuthorizationsSection",
238: true);
239: } catch (DataDictionaryException e) {
240: if (e.getCause() instanceof SAXParseException) {
241: failedAsExpected = true;
242: }
243: }
244:
245: assertTrue(failedAsExpected);
246: }
247:
248: @Test
249: public final void testDataDictionaryBuilder_transactionalDocument_authorization_emptyWorkgroupsList() {
250: String INPUT_FILE = DataDictionaryBuilderTest.TESTPACKAGE_INVALID
251: + "td/AuthEmptyWorkgroupsList.xml";
252:
253: boolean failedAsExpected = false;
254:
255: try {
256: builder.addUniqueEntries(INPUT_FILE, true);
257: builder.parseDocument("AuthEmptyWorkgroupsList", true);
258: } catch (DataDictionaryException e) {
259: if (e.getCause() instanceof SAXParseException) {
260: failedAsExpected = true;
261: }
262: }
263:
264: assertTrue(failedAsExpected);
265: }
266:
267: @Test
268: public final void testDataDictionaryBuilder_transactionalDocument_authorization_missingAction() {
269: String INPUT_FILE = DataDictionaryBuilderTest.TESTPACKAGE_INVALID
270: + "td/AuthMissingAction.xml";
271:
272: boolean failedAsExpected = false;
273:
274: try {
275: builder.addUniqueEntries(INPUT_FILE, true);
276: builder.parseDocument("AuthMissingAction", true);
277: } catch (DataDictionaryException e) {
278: if (e.getCause() instanceof SAXParseException) {
279: failedAsExpected = true;
280: }
281: }
282:
283: assertTrue(failedAsExpected);
284: }
285:
286: @Test
287: public final void testDataDictionaryBuilder_transactionalDocument_authorization_missingAuthorizationsSection() {
288: String INPUT_FILE = DataDictionaryBuilderTest.TESTPACKAGE_INVALID
289: + "td/AuthMissingAuthorizationsSection.xml";
290:
291: boolean failedAsExpected = false;
292:
293: try {
294: builder.addUniqueEntries(INPUT_FILE, true);
295: builder.parseDocument("AuthMissingAuthorizationsSection",
296: true);
297: } catch (DataDictionaryException e) {
298: // if (DataDictionaryUtils.saxCause(e) instanceof ConversionException) {
299: failedAsExpected = true;
300: // }
301: }
302:
303: assertTrue(failedAsExpected);
304: }
305:
306: @Test
307: public final void testDataDictionaryBuilder_transactionalDocument_documentAuthorizer_missingAuthorizerClass() {
308: String INPUT_FILE = DataDictionaryBuilderTest.TESTPACKAGE_INVALID
309: + "td/DocAuthMissing.xml";
310:
311: boolean failedAsExpected = false;
312:
313: try {
314: builder.addUniqueEntries(INPUT_FILE, true);
315: builder.parseDocument("DocAuthMissing", true);
316: } catch (DataDictionaryException e) {
317: // if (DataDictionaryUtils.saxCause(e) instanceof ConversionException) {
318: failedAsExpected = true;
319: // }
320: }
321:
322: assertTrue(failedAsExpected);
323: }
324:
325: @Test
326: public final void testDataDictionaryBuilder_transactionalDocument_documentAuthorizer_blankAuthorizerClass() {
327: String INPUT_FILE = DataDictionaryBuilderTest.TESTPACKAGE_INVALID
328: + "td/DocAuthBlank.xml";
329:
330: boolean failedAsExpected = false;
331:
332: try {
333: builder.addUniqueEntries(INPUT_FILE, true);
334: builder.parseDocument("DocAuthBlank", true);
335: } catch (DataDictionaryException e) {
336: if (DataDictionaryUtils.saxCause(e) instanceof ConversionException) {
337: failedAsExpected = true;
338: }
339: }
340:
341: assertTrue(failedAsExpected);
342: }
343:
344: @Test
345: public final void testDataDictionaryBuilder_transactionalDocument_documentAuthorizer_unknownAuthorizerClass() {
346: String INPUT_FILE = DataDictionaryBuilderTest.TESTPACKAGE_INVALID
347: + "td/DocAuthUnknown.xml";
348:
349: boolean failedAsExpected = false;
350:
351: try {
352: builder.addUniqueEntries(INPUT_FILE, true);
353: builder.parseDocument("DocAuthUnknown", true);
354: } catch (DataDictionaryException e) {
355: // if (DataDictionaryUtils.saxCause(e) instanceof ClassValidationException) {
356: failedAsExpected = true;
357: // }
358: }
359:
360: assertTrue(failedAsExpected);
361: }
362:
363: @Test
364: public final void testDataDictionaryBuilder_transactionalDocument_documentAuthorizer_invalidAuthorizerClass() {
365: String INPUT_FILE = DataDictionaryBuilderTest.TESTPACKAGE_INVALID
366: + "td/DocAuthInvalid.xml";
367:
368: boolean failedAsExpected = false;
369:
370: try {
371: builder.getDataDictionary().setAllowOverrides(true);
372: builder.addOverrideEntries(INPUT_FILE, true);
373: builder.parseDocument("DocAuthInvalid", true);
374: } catch (DataDictionaryException e) {
375: if (DataDictionaryUtils.saxCause(e) instanceof ClassValidationException) {
376: failedAsExpected = true;
377: }
378: }
379:
380: assertTrue(failedAsExpected);
381: }
382: }
|