1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package ch.elca.el4j.tests.core.context;
19
20 import static org.junit.Assert.fail;
21
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24 import org.junit.Test;
25 import org.springframework.beans.factory.BeanDefinitionStoreException;
26 import org.springframework.beans.factory.NoSuchBeanDefinitionException;
27
28 import ch.elca.el4j.core.context.ModuleApplicationContext;
29
30
31
32
33
34
35
36
37
38 public class ModuleApplicationContextTest {
39
40
41 private static Logger s_logger
42 = LoggerFactory.getLogger(ModuleApplicationContextTest.class);
43
44
45 String m_fileName1 = "classpath:scenarios/core/context/beans1.xml";
46
47
48 String m_fileName2 = "classpath:scenarios/core/context/beans2.xml";
49
50
51 String m_fileName3 = "classpath:scenarios/core/context/beans3.xml";
52
53
54 String m_allFileNamesInClasspath = "classpath:scenarios/core/context/*.xml";
55
56
57 String m_allFileNamesInBothClasspaths
58 = "classpath:scenarios/core/context/**/*.xml";
59
60
61 String m_mandatoryFiles = "classpath*:mandatory/*.xml";
62
63
64
65
66
67
68 @Test
69 public void testInclusiveFileNameNull() {
70
71 try {
72 new ModuleApplicationContext((String) null, false);
73 fail("NullPointerException should have been thrown.");
74 } catch (NullPointerException e) {
75 }
76
77 }
78
79
80
81
82
83
84 @Test
85 public void testOneInclusiveFileName() {
86 ModuleApplicationContext tac
87 = new ModuleApplicationContext(m_fileName1, false);
88 tac.getBean("Bean1");
89 }
90
91
92
93
94
95
96 @Test
97 public void testTwoInclusiveFileNames() {
98 ModuleApplicationContext tac = new ModuleApplicationContext(
99 new String[] {m_fileName1, m_fileName2 }, false);
100
101 tac.getBean("Bean1");
102 tac.getBean("Bean2");
103 }
104
105
106
107
108
109
110 @Test
111 public void testOneInclusiveFileNameExclusiveFileNamesIsNull() {
112
113 try {
114 new ModuleApplicationContext(m_fileName1, (String) null, false);
115 fail("NullPointerException should have been thrown.");
116 } catch (NullPointerException e) {
117 }
118
119 }
120
121
122
123
124
125
126 @Test
127 public void testOneInclusiveFileNameExclusiveFileNamesIsEmpty() {
128 ModuleApplicationContext tac = new ModuleApplicationContext(m_fileName1,
129 "", false);
130 tac.getBean("Bean1");
131 }
132
133
134
135
136
137
138
139
140 @Test
141 public void testOneInclusiveFileNamesAnotherExclusiveFileName() {
142 ModuleApplicationContext tac
143 = new ModuleApplicationContext(m_fileName1, m_fileName2, false);
144 tac.getBean("Bean1");
145
146 try {
147 tac.getBean("Bean2");
148 fail("NoSuchBeanDefinitionException should have been thrown.");
149 } catch (NoSuchBeanDefinitionException e) {
150 }
151
152 }
153
154
155
156
157
158
159 @Test
160 public void testTwoInclusiveFileNamesOneExclusiveFileName() {
161 ModuleApplicationContext tac = new ModuleApplicationContext(
162 new String[] {m_fileName1, m_fileName2 }, m_fileName2, false);
163 tac.getBean("Bean1");
164
165 try {
166 tac.getBean("Bean2");
167 fail("NoSuchBeanDefinitionException should have been thrown.");
168 } catch (NoSuchBeanDefinitionException e) {
169 }
170
171 }
172
173
174
175
176
177
178
179 @Test
180 public void testAllInClasspathFileNamesMinusTwoExclusiveFileNames() {
181 ModuleApplicationContext tac = new ModuleApplicationContext(
182 m_allFileNamesInClasspath,
183 new String[] {m_fileName1, m_fileName3}, false);
184
185 try {
186 tac.getBean("Bean1");
187 fail("NoSuchBeanDefinitionException should have been thrown.");
188 } catch (NoSuchBeanDefinitionException e) {
189 }
190
191 tac.getBean("Bean2");
192
193 try {
194 tac.getBean("Bean3");
195 fail("NoSuchBeanDefinitionException should have been thrown.");
196 } catch (NoSuchBeanDefinitionException e) {
197 }
198
199 try {
200 tac.getBean("Bean4");
201 fail("NoSuchBeanDefinitionException should have been thrown.");
202 } catch (NoSuchBeanDefinitionException e) {
203 }
204
205 }
206
207
208
209
210
211
212
213 @Test
214 public void testAllInClasspathFileNamesMinusAllInClasspathFileNames() {
215 ModuleApplicationContext tac = new ModuleApplicationContext(
216 m_allFileNamesInClasspath, m_allFileNamesInClasspath, false);
217
218 try {
219 tac.getBean("Bean1");
220 fail("NoSuchBeanDefinitionException should have been thrown.");
221 } catch (NoSuchBeanDefinitionException e) {
222 }
223
224 try {
225 tac.getBean("Bean2");
226 fail("NoSuchBeanDefinitionException should have been thrown.");
227 } catch (NoSuchBeanDefinitionException e) {
228 }
229
230 try {
231 tac.getBean("Bean3");
232 fail("NoSuchBeanDefinitionException should have been thrown.");
233 } catch (NoSuchBeanDefinitionException e) {
234 }
235
236 try {
237 tac.getBean("Bean4");
238 fail("NoSuchBeanDefinitionException should have been thrown.");
239 } catch (NoSuchBeanDefinitionException e) {
240 }
241
242 }
243
244
245
246
247
248
249
250 @Test
251 public void testAllInBothClasspathsMinusAllInFilepath1() {
252 ModuleApplicationContext tac = new ModuleApplicationContext(
253 m_allFileNamesInBothClasspaths, m_allFileNamesInClasspath, false);
254
255 try {
256 tac.getBean("Bean1");
257 fail("NoSuchBeanDefinitionExceptiona should have been thrown.");
258 } catch (NoSuchBeanDefinitionException e) {
259 }
260
261 try {
262 tac.getBean("Bean2");
263 fail("NoSuchBeanDefinitionExceptionb should have been thrown.");
264 } catch (NoSuchBeanDefinitionException e) {
265 }
266
267 try {
268 tac.getBean("Bean3");
269 fail("NoSuchBeanDefinitionExceptionc should have been thrown.");
270 } catch (NoSuchBeanDefinitionException e) {
271 }
272
273 try {
274 tac.getBean("Bean4");
275 fail("NoSuchBeanDefinitionExceptiond should have been thrown.");
276 } catch (NoSuchBeanDefinitionException e) {
277 }
278
279 tac.getBean("Bean5");
280
281 }
282
283
284
285
286
287
288
289 @Test
290 public void testOneExistingInclusiveFileNamePlusOneNonExistingFileName() {
291 ModuleApplicationContext tac = new ModuleApplicationContext(
292 new String[] {m_fileName1, "non existing file path"}, false);
293 tac.getBean("Bean1");
294 }
295
296
297
298
299
300
301 @Test
302 public void testBeanDefinitionOverridingIsFalse() {
303
304 try {
305 new ModuleApplicationContext(
306 new String[] {m_fileName1, m_fileName1}, false);
307 fail("BeanDefinitionStoreException should have been thrown.");
308 } catch (BeanDefinitionStoreException e) {
309 }
310
311 }
312
313
314
315
316
317
318 @Test
319 public void testMandatoryWarning() {
320 s_logger.warn("There should be no message with level at least 'WARN'"
321 + "between THIS");
322 new ModuleApplicationContext(
323 new String[] {m_mandatoryFiles, m_fileName1}, false);
324 s_logger.warn("and THIS message.");
325 }
326 }