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.log4j.Level;
020: import org.junit.After;
021: import org.junit.Before;
022: import org.junit.Test;
023: import org.kuali.rice.KNSServiceLocator;
024: import org.kuali.test.KNSTestBase;
025: import org.kuali.test.KNSWithTestSpringContext;
026:
027: /**
028: * This class is used to test the DataDictionaryBuilder.
029: *
030: *
031: */
032: @KNSWithTestSpringContext
033: public class DataDictionaryBuilderTest extends KNSTestBase {
034: static final String PACKAGE_CORE_BO = "org/kuali/core/bo/datadictionary/";
035:
036: static final String PACKAGE_CORE_DOCUMENT = "org/kuali/core/document/datadictionary/";
037:
038: static final String PACKAGE_KFS = "org/kuali/kfs/datadictionary/";
039:
040: static final String PACKAGE_CHART = "org/kuali/module/chart/datadictionary/";
041:
042: static final String PACKAGE_CG = "org/kuali/module/cg/datadictionary/";
043:
044: static final String PACKAGE_KRA_BUDGET = "org/kuali/module/kra/budget/datadictionary/";
045:
046: static final String PACKAGE_KRA_ROUTINGFORM = "org/kuali/module/kra/routingform/datadictionary/";
047:
048: static final String TESTPACKAGE_INVALID = "org/kuali/core/datadictionary/test/invalid/";
049:
050: DataDictionaryBuilder builder = null;
051:
052: @Before
053: public void setUp() throws Exception {
054: super .setUp();
055:
056: builder = new DataDictionaryBuilder(KNSServiceLocator
057: .getValidationCompletionUtils());
058: builder.setKualiGroupService(KNSServiceLocator
059: .getKualiGroupService());
060: builder.setKualiConfigurationService(KNSServiceLocator
061: .getKualiConfigurationService());
062:
063: // quieten things down a bit
064: setLogLevel("org.apache.commons.digester", Level.FATAL);
065: setLogLevel("org.kuali.core.datadictionary.XmlErrorHandler",
066: Level.FATAL);
067: }
068:
069: @After
070: public void tearDown() throws Exception {
071: super .tearDown();
072: builder = null;
073: }
074:
075: @Test
076: public final void testDataDictionaryBuilder_source_invalid() {
077: boolean failedAsExpected = false;
078:
079: try {
080: builder.addUniqueEntries(null, true);
081: } catch (DataDictionaryException e) {
082: failedAsExpected = true;
083: }
084:
085: assertTrue(failedAsExpected);
086: }
087:
088: @Test
089: public final void testDataDictionaryBuilder_source_unknownFile() {
090: String INPUT_FILE = TESTPACKAGE_INVALID + "foo.xml";
091:
092: boolean failedAsExpected = false;
093:
094: try {
095: builder.addUniqueEntries(INPUT_FILE, true);
096: } catch (DataDictionaryException e) {
097: failedAsExpected = true;
098: }
099:
100: assertTrue(failedAsExpected);
101: }
102:
103: @Test
104: public final void testDataDictionaryBuilder_source_unknownPackage()
105: throws Exception {
106: String UNKNOWN_PACKAGE = TESTPACKAGE_INVALID + "foo/";
107:
108: boolean failedAsExpected = false;
109:
110: try {
111: builder.addUniqueEntries(UNKNOWN_PACKAGE, true);
112: } catch (DataDictionaryException e) {
113: failedAsExpected = true;
114: }
115:
116: assertTrue(failedAsExpected);
117: }
118:
119: @Test
120: public final void testDataDictionaryBuilder_invalidXml() {
121: String INPUT_FILE = TESTPACKAGE_INVALID + "InvalidXml.xml";
122:
123: boolean failedAsExpected = false;
124:
125: try {
126: builder.addUniqueEntries(INPUT_FILE, true);
127: builder.parseBO("InvalidXml", true);
128: } catch (DataDictionaryException e) {
129: failedAsExpected = true;
130: }
131:
132: assertTrue(failedAsExpected);
133: }
134:
135: @Test
136: public final void testDataDictionaryBuilder_getInvalidDictionary() {
137: String INPUT_FILE = TESTPACKAGE_INVALID + "InvalidXml.xml";
138:
139: boolean failedAsExpected = false;
140:
141: try {
142: builder.addUniqueEntries(INPUT_FILE, true);
143: builder.parseBO("InvalidXml", true);
144: } catch (DataDictionaryException e) {
145: failedAsExpected = true;
146: }
147:
148: assertTrue(failedAsExpected);
149: }
150:
151: }
|