1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package ch.elca.el4j.tests.services.persistence.generic.dao;
18
19 import static org.junit.Assert.assertTrue;
20
21 import org.junit.Test;
22 import org.springframework.context.ApplicationContext;
23
24 import ch.elca.el4j.core.context.ModuleApplicationContext;
25 import ch.elca.el4j.services.persistence.generic.dao.DaoRegistry;
26 import ch.elca.el4j.services.persistence.generic.dao.GenericDao;
27 import ch.elca.el4j.services.persistence.generic.dao.impl.DefaultDaoRegistry;
28
29
30
31
32 public class DaoAutocollectionTest {
33
34 @Test
35 public void testDaoAutocollection() {
36 ApplicationContext ac = new ModuleApplicationContext(
37 new String[] {"scenarios/core/dao/springConfig.xml"}, false);
38
39
40
41 DaoRegistry registry = (DaoRegistry) ac.getBean("registry");
42
43 GenericDao<?> dao = registry.getFor(String.class);
44
45
46
47 assertTrue(dao != null);
48 assertTrue(dao instanceof Dao1);
49
50 dao = registry.getFor(Long.class);
51 assertTrue(dao != null);
52 assertTrue(dao instanceof Dao2);
53
54 assertTrue(ac.getBeanNamesForType(GenericDao.class).length == 2);
55 }
56
57
58
59
60 @Test
61 public void testDaoPatternMatching() {
62 ApplicationContext ac = new ModuleApplicationContext(
63 new String[] {"scenarios/core/dao/springConfig.xml"}, false);
64
65
66 DaoRegistry registry = (DaoRegistry) ac.getBean("registryWithFilter");
67
68
69 GenericDao<?> dao = registry.getFor(String.class);
70 assertTrue(dao != null);
71 assertTrue(dao instanceof Dao1);
72
73
74 dao = registry.getFor(Long.class);
75 assertTrue(dao == null);
76
77 }
78
79
80
81
82 @Test
83 public void testConcurrent() {
84 final ApplicationContext ac = new ModuleApplicationContext(
85 new String[] {"scenarios/core/dao/springConfig.xml", "scenarios/core/dao/concurrentConfig.xml"}, false);
86
87 ImpatientClass impatientClass = (ImpatientClass) ac.getBean("impatientClass");
88
89 assertTrue("DaoRegistry didn't wait for completely initialized Spring context", impatientClass.join());
90 }
91
92 }