1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.krad.datadictionary;
18
19 import org.apache.log4j.Logger;
20 import org.junit.After;
21 import org.junit.Before;
22 import org.junit.Test;
23
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
26
27
28
29
30
31
32
33 public class DataDictionaryBuilderTest {
34 protected final Logger LOG = Logger.getLogger(getClass());
35
36 static final String PACKAGE_CORE_BO = "org/kuali/rice/krad/bo/datadictionary/";
37
38 static final String PACKAGE_CORE_DOCUMENT = "org/kuali/rice/krad/document/datadictionary/";
39
40 static final String PACKAGE_KFS = "org/kuali/kfs/datadictionary/";
41
42 static final String PACKAGE_CHART = "org/kuali/module/chart/datadictionary/";
43
44 static final String PACKAGE_CG = "org/kuali/module/cg/datadictionary/";
45
46 static final String PACKAGE_KRA_BUDGET = "org/kuali/module/kra/budget/datadictionary/";
47
48 static final String PACKAGE_KRA_ROUTINGFORM = "org/kuali/module/kra/routingform/datadictionary/";
49
50 static final String TESTPACKAGE_INVALID = "org/kuali/rice/krad/datadictionary/test/invalid/";
51
52 DataDictionary dd = null;
53
54 @Before
55 public void setUp() throws Exception {
56
57 dd = new DataDictionary();
58 }
59
60 @After
61 public void tearDown() throws Exception {
62 dd = null;
63 }
64
65 @Test
66 public final void testDataDictionaryBuilder_source_invalid() throws Exception {
67 boolean failedAsExpected = false;
68
69 try {
70 dd.addConfigFileLocation(null);
71 } catch (DataDictionaryException e) {
72 failedAsExpected = true;
73 }
74
75 assertTrue(failedAsExpected);
76 }
77
78 @Test
79 public final void testDataDictionaryBuilder_source_unknownFile() throws Exception {
80 String INPUT_FILE = TESTPACKAGE_INVALID + "foo.xml";
81
82 boolean failedAsExpected = false;
83
84 try {
85 dd.addConfigFileLocation(INPUT_FILE);
86 } catch (DataDictionaryException e) {
87 failedAsExpected = true;
88 }
89
90 assertTrue(failedAsExpected);
91 }
92
93 @Test
94 public final void testDataDictionaryBuilder_source_unknownPackage() throws Exception {
95 String UNKNOWN_PACKAGE = TESTPACKAGE_INVALID + "foo/";
96
97 boolean failedAsExpected = false;
98
99 try {
100 dd.addConfigFileLocation(UNKNOWN_PACKAGE);
101 } catch (DataDictionaryException e) {
102 failedAsExpected = true;
103 }
104
105 assertTrue(failedAsExpected);
106 }
107
108 @Test
109 public final void testDataDictionaryBuilder_invalidXml() throws Exception {
110 String INPUT_FILE = TESTPACKAGE_INVALID + "InvalidXml.xml";
111
112 boolean failedAsExpected = false;
113
114 try {
115 dd.addConfigFileLocation(INPUT_FILE);
116 dd.parseDataDictionaryConfigurationFiles( false );
117 } catch (DataDictionaryException e) {
118 failedAsExpected = true;
119 } catch (Exception e) {
120 LOG.error("Error loading DD files", e);
121 fail("Data Dictionary file load failed but with wrong exception type '" + e.getClass().getName() + "'");
122 }
123
124 assertTrue(failedAsExpected);
125 }
126
127 @Test
128 public final void testDataDictionaryBuilder_getInvalidDictionary() throws Exception {
129 String INPUT_FILE = TESTPACKAGE_INVALID + "InvalidXml.xml";
130
131 boolean failedAsExpected = false;
132
133 try {
134 dd.addConfigFileLocation(INPUT_FILE);
135 dd.parseDataDictionaryConfigurationFiles( false );
136 } catch (DataDictionaryException e) {
137 failedAsExpected = true;
138 } catch (Exception e) {
139 LOG.error("Error loading DD files", e);
140 fail("Data Dictionary file load failed but with wrong exception type '" + e.getClass().getName() + "'");
141 }
142
143 assertTrue(failedAsExpected);
144 }
145
146 }