View Javadoc

1   /**
2    * Copyright 2005-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.datadictionary;
17  
18  import org.apache.log4j.Logger;
19  import org.junit.After;
20  import org.junit.Before;
21  import org.junit.Test;
22  
23  import static org.junit.Assert.assertTrue;
24  import static org.junit.Assert.fail;
25  
26  /**
27   * This class is used to test the DataDictionaryBuilder.
28   * 
29   * 
30   */
31  
32  public class DataDictionaryBuilderTest {
33      protected final Logger LOG = Logger.getLogger(getClass());
34  
35      static final String PACKAGE_CORE_BO = "org/kuali/rice/krad/bo/datadictionary/";
36  
37  	static final String PACKAGE_CORE_DOCUMENT = "org/kuali/rice/krad/document/datadictionary/";
38  
39  	static final String PACKAGE_KFS = "org/kuali/kfs/datadictionary/";
40  
41  	static final String PACKAGE_CHART = "org/kuali/module/chart/datadictionary/";
42  
43  	static final String PACKAGE_CG = "org/kuali/module/cg/datadictionary/";
44  
45  	static final String PACKAGE_KRA_BUDGET = "org/kuali/module/kra/budget/datadictionary/";
46  
47  	static final String PACKAGE_KRA_ROUTINGFORM = "org/kuali/module/kra/routingform/datadictionary/";
48  
49  	static final String TESTPACKAGE_INVALID = "org/kuali/rice/krad/datadictionary/test/invalid/";
50  
51  	DataDictionary dd = null;
52  
53  	@Before
54  	public void setUp() throws Exception {
55  
56  		dd = new DataDictionary();
57  	}
58  
59  	@After
60  	public void tearDown() throws Exception {
61  		dd = null;
62  	}
63  
64  	@Test
65  	public final void testDataDictionaryBuilder_source_invalid() throws Exception {
66  		boolean failedAsExpected = false;
67  
68  		try {
69  			dd.addConfigFileLocation(null);
70  		} catch (DataDictionaryException e) {
71  			failedAsExpected = true;
72  		}
73  
74  		assertTrue(failedAsExpected);
75  	}
76  
77  	@Test
78  	public final void testDataDictionaryBuilder_source_unknownFile() throws Exception {
79  		String INPUT_FILE = TESTPACKAGE_INVALID + "foo.xml";
80  
81  		boolean failedAsExpected = false;
82  
83  		try {
84  			dd.addConfigFileLocation(INPUT_FILE);
85  		} catch (DataDictionaryException e) {
86  			failedAsExpected = true;
87  		}
88  
89  		assertTrue(failedAsExpected);
90  	}
91  
92  	@Test
93  	public final void testDataDictionaryBuilder_source_unknownPackage() throws Exception {
94  		String UNKNOWN_PACKAGE = TESTPACKAGE_INVALID + "foo/";
95  
96  		boolean failedAsExpected = false;
97  
98  		try {
99  			dd.addConfigFileLocation(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(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(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 }