View Javadoc
1   /**
2    * Copyright 2005-2016 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   * DataDictionaryBuilderTest tests 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/";
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("KR-SAP", 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("KR-SAP", 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("KR-SAP", UNKNOWN_PACKAGE);
100 		} catch (DataDictionaryException e) {
101 			failedAsExpected = true;
102 		}
103 
104 		assertTrue(failedAsExpected);
105 	}
106 
107 	@Test(expected = DataDictionaryException.class)
108 	public void testDataDictionaryBuilder_ValidFileInvalidXML() throws Exception {
109 		String INPUT_FILE = TESTPACKAGE_INVALID + "InvalidXml1.xml";
110 		dd.addConfigFileLocation("KR-SAP", INPUT_FILE);
111 		dd.parseDataDictionaryConfigurationFiles(false);
112 	}
113 
114 	@Test
115 	public final void testDataDictionaryBuilder_getInvalidDictionary() throws Exception {
116 		String INPUT_FILE = TESTPACKAGE_INVALID + "InvalidXml.xml";
117 
118 		boolean failedAsExpected = false;
119 
120 		try {
121 			dd.addConfigFileLocation("KR-SAP", INPUT_FILE);
122 			dd.parseDataDictionaryConfigurationFiles( false );
123 		} catch (DataDictionaryException e) {
124 			failedAsExpected = true;
125         } catch (Exception e) {
126             LOG.error("Error loading DD files", e);
127             fail("Data Dictionary file load failed but with wrong exception type '" + e.getClass().getName() + "'");
128 		}
129 
130 		assertTrue(failedAsExpected);
131 	}
132 
133 }