21
21
22
22
import org .junit .Test ;
23
23
import org .junit .runner .RunWith ;
24
+ import org .springframework .beans .BeansException ;
24
25
import org .springframework .beans .factory .annotation .Autowired ;
26
+ import org .springframework .context .ApplicationContext ;
27
+ import org .springframework .context .ApplicationContextAware ;
25
28
import org .springframework .context .annotation .Bean ;
26
29
import org .springframework .context .annotation .Configuration ;
27
30
import org .springframework .data .elasticsearch .core .ElasticsearchOperations ;
28
31
import org .springframework .data .elasticsearch .core .ElasticsearchTemplate ;
29
32
import org .springframework .data .elasticsearch .repositories .sample .SampleElasticsearchRepository ;
33
+ import org .springframework .data .elasticsearch .repository .ElasticsearchRepository ;
30
34
import org .springframework .data .elasticsearch .repository .config .EnableElasticsearchRepositories ;
31
35
import org .springframework .test .context .ContextConfiguration ;
32
36
import org .springframework .test .context .junit4 .SpringJUnit4ClassRunner ;
37
41
*/
38
42
@ RunWith (SpringJUnit4ClassRunner .class )
39
43
@ ContextConfiguration
40
- public class EnableElasticsearchRepositoriesTests {
44
+ public class EnableElasticsearchRepositoriesTests implements ApplicationContextAware {
45
+
46
+ ApplicationContext context ;
47
+
48
+ @ Override
49
+ public void setApplicationContext (ApplicationContext applicationContext ) throws BeansException {
50
+ this .context = applicationContext ;
51
+ }
41
52
42
53
@ Configuration
43
54
@ EnableElasticsearchRepositories (basePackages = "org.springframework.data.elasticsearch.repositories.sample" )
@@ -56,4 +67,16 @@ public ElasticsearchOperations elasticsearchTemplate() {
56
67
public void bootstrapsRepository () {
57
68
assertThat (repository , is (notNullValue ()));
58
69
}
70
+
71
+ @ Test
72
+ public void shouldScanSelectedPackage () {
73
+ //given
74
+
75
+ //when
76
+ String [] beanNamesForType = context .getBeanNamesForType (ElasticsearchRepository .class );
77
+
78
+ //then
79
+ assertThat (beanNamesForType .length , is (1 ));
80
+ assertThat (beanNamesForType [0 ], is ("sampleElasticsearchRepository" ));
81
+ }
59
82
}
0 commit comments