1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package ch.elca.el4j.tests.core.beans;
19
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertTrue;
22
23 import java.util.Map;
24
25 import org.junit.Test;
26 import org.springframework.context.ApplicationContext;
27
28 import ch.elca.el4j.core.beans.BeanLocator;
29 import ch.elca.el4j.core.context.ModuleApplicationContext;
30
31
32
33
34
35
36
37
38 public class BeanLocatorTest {
39
40
41 final ApplicationContext m_appContext;
42
43
44
45
46 public BeanLocatorTest() {
47 m_appContext = new ModuleApplicationContext(
48 "classpath:scenarios/core/beans/*.xml", false);
49 }
50
51
52
53
54 @Test
55 public void testLocateClassesOfSpecificTypes() {
56 BeanLocator beanLocator = (BeanLocator) m_appContext
57 .getBean("locateClassesOfSpecificTypes");
58 Map beans = beanLocator.getBeans();
59 String[] expectedBeans = new String[] {"classB1", "classB2",
60 "classB3", "fourthB", "classC", "secondC", "thirdC", "classW1",
61 "classW2", "thirdW"};
62 checkIfAllExpectedBeansAreInMap(beans, expectedBeans);
63 }
64
65
66
67
68 @Test
69 public void testLocateClassesOfSpecificTypesPlusExcludeList() {
70 BeanLocator beanLocator = (BeanLocator) m_appContext
71 .getBean("locateClassesOfSpecificTypesPlusExcludeList");
72 Map beans = beanLocator.getBeans();
73 String[] expectedBeans = new String[] {"fourthB", "secondC", "thirdC",
74 "thirdW"};
75 checkIfAllExpectedBeansAreInMap(beans, expectedBeans);
76 }
77
78
79
80
81 @Test
82 public void testLocateClassesOfSpecificTypesPlusIncludeList() {
83 BeanLocator beanLocator = (BeanLocator) m_appContext
84 .getBean("locateClassesOfSpecificTypesPlusIncludeList");
85 Map beans = beanLocator.getBeans();
86 String[] expectedBeans = new String[] {"classC", "secondC", "thirdC",
87 "thirdW"};
88 checkIfAllExpectedBeansAreInMap(beans, expectedBeans);
89 }
90
91
92
93
94
95 @Test
96 public void testLocateClassesOfSpecificTypesPlusIncludeAndExcludeList() {
97 BeanLocator beanLocator = (BeanLocator) m_appContext.getBean(
98 "locateClassesOfSpecificTypesPlusIncludeAndExcludeList");
99 Map beans = beanLocator.getBeans();
100 String[] expectedBeans = new String[] {"classB2", "classB3", "classC",
101 "secondC", "thirdC", "firstV", "classW2"};
102
103 checkIfAllExpectedBeansAreInMap(beans, expectedBeans);
104 }
105
106
107
108
109
110
111
112
113
114
115 private void checkIfAllExpectedBeansAreInMap(Map beans,
116 String[] expectedBeans) {
117 int expectedNumberOfBeans = (expectedBeans != null
118 ? expectedBeans.length : 0);
119 assertEquals("There is not the expected number of beans.",
120 expectedNumberOfBeans, beans.size());
121
122 for (int i = 0; i < expectedNumberOfBeans; i++) {
123 String beanName = expectedBeans[i];
124 assertTrue("Bean with name '" + beanName
125 + "' is not present in map.", beans.containsKey(beanName));
126 }
127 }
128 }