001/**
002 * Copyright 2005-2015 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.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/ecl2.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 */
016package org.kuali.rice.krad.datadictionary;
017
018import org.apache.log4j.Logger;
019import org.junit.After;
020import org.junit.Before;
021import org.junit.Test;
022
023import static org.junit.Assert.assertTrue;
024import static org.junit.Assert.fail;
025
026/**
027 * DataDictionaryBuilderTest tests the DataDictionaryBuilder
028 *
029 *
030 */
031
032public class DataDictionaryBuilderTest {
033    protected final Logger LOG = Logger.getLogger(getClass());
034
035    static final String PACKAGE_CORE_BO = "org/kuali/rice/krad/bo/datadictionary/";
036
037        static final String PACKAGE_CORE_DOCUMENT = "org/kuali/rice/krad/document/datadictionary/";
038
039        static final String PACKAGE_KFS = "org/kuali/kfs/datadictionary/";
040
041        static final String PACKAGE_CHART = "org/kuali/module/chart/datadictionary/";
042
043        static final String PACKAGE_CG = "org/kuali/module/cg/datadictionary/";
044
045        static final String PACKAGE_KRA_BUDGET = "org/kuali/module/kra/budget/datadictionary/";
046
047        static final String PACKAGE_KRA_ROUTINGFORM = "org/kuali/module/kra/routingform/datadictionary/";
048
049        static final String TESTPACKAGE_INVALID = "org/kuali/rice/krad/datadictionary/test/invalid/";
050
051        DataDictionary dd = null;
052
053        @Before
054        public void setUp() throws Exception {
055
056                dd = new DataDictionary();
057        }
058
059        @After
060        public void tearDown() throws Exception {
061                dd = null;
062        }
063
064        @Test
065        public final void testDataDictionaryBuilder_source_invalid() throws Exception {
066                boolean failedAsExpected = false;
067
068                try {
069                        dd.addConfigFileLocation("KR-SAP", null);
070                } catch (DataDictionaryException e) {
071                        failedAsExpected = true;
072                }
073
074                assertTrue(failedAsExpected);
075        }
076
077        @Test
078        public final void testDataDictionaryBuilder_source_unknownFile() throws Exception {
079                String INPUT_FILE = TESTPACKAGE_INVALID + "foo.xml";
080
081                boolean failedAsExpected = false;
082
083                try {
084                        dd.addConfigFileLocation("KR-SAP", INPUT_FILE);
085                } catch (DataDictionaryException e) {
086                        failedAsExpected = true;
087                }
088
089                assertTrue(failedAsExpected);
090        }
091
092        @Test
093        public final void testDataDictionaryBuilder_source_unknownPackage() throws Exception {
094                String UNKNOWN_PACKAGE = TESTPACKAGE_INVALID + "foo/";
095
096                boolean failedAsExpected = false;
097
098                try {
099                        dd.addConfigFileLocation("KR-SAP", UNKNOWN_PACKAGE);
100                } catch (DataDictionaryException e) {
101                        failedAsExpected = true;
102                }
103
104                assertTrue(failedAsExpected);
105        }
106
107        @Test
108        public final void testDataDictionaryBuilder_invalidXml() throws Exception {
109                String INPUT_FILE = TESTPACKAGE_INVALID + "InvalidXml.xml";
110
111                boolean failedAsExpected = false;
112
113                try {
114                        dd.addConfigFileLocation("KR-SAP", INPUT_FILE);
115                        dd.parseDataDictionaryConfigurationFiles( false );
116                } catch (DataDictionaryException e) {
117                        failedAsExpected = true;
118                } catch (Exception e) {
119            LOG.error("Error loading DD files", e);
120                    fail("Data Dictionary file load failed but with wrong exception type '" + e.getClass().getName() + "'");
121                }
122
123                assertTrue(failedAsExpected);
124        }
125
126        @Test
127        public final void testDataDictionaryBuilder_getInvalidDictionary() throws Exception {
128                String INPUT_FILE = TESTPACKAGE_INVALID + "InvalidXml.xml";
129
130                boolean failedAsExpected = false;
131
132                try {
133                        dd.addConfigFileLocation("KR-SAP", INPUT_FILE);
134                        dd.parseDataDictionaryConfigurationFiles( false );
135                } catch (DataDictionaryException e) {
136                        failedAsExpected = true;
137        } catch (Exception e) {
138            LOG.error("Error loading DD files", e);
139            fail("Data Dictionary file load failed but with wrong exception type '" + e.getClass().getName() + "'");
140                }
141
142                assertTrue(failedAsExpected);
143        }
144
145}