1
1
/*
2
- * Copyright 2012-2017 the original author or authors.
2
+ * Copyright 2012-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
16
16
17
17
package org .springframework .boot .autoconfigure .data .neo4j ;
18
18
19
+ import com .github .benmanes .caffeine .cache .Caffeine ;
19
20
import org .junit .Test ;
20
21
import org .neo4j .ogm .session .Session ;
21
22
import org .neo4j .ogm .session .SessionFactory ;
22
23
import org .neo4j .ogm .session .event .Event ;
23
24
import org .neo4j .ogm .session .event .EventListener ;
24
25
import org .neo4j .ogm .session .event .PersistenceEvent ;
25
26
27
+ import org .springframework .beans .factory .config .BeanDefinition ;
26
28
import org .springframework .boot .autoconfigure .AutoConfigurationPackages ;
27
29
import org .springframework .boot .autoconfigure .AutoConfigurations ;
28
30
import org .springframework .boot .autoconfigure .data .neo4j .city .City ;
29
31
import org .springframework .boot .autoconfigure .data .neo4j .country .Country ;
30
32
import org .springframework .boot .autoconfigure .domain .EntityScan ;
31
33
import org .springframework .boot .autoconfigure .transaction .TransactionAutoConfiguration ;
34
+ import org .springframework .boot .test .context .FilteredClassLoader ;
35
+ import org .springframework .boot .test .context .runner .ApplicationContextRunner ;
32
36
import org .springframework .boot .test .context .runner .WebApplicationContextRunner ;
33
37
import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
34
38
import org .springframework .context .annotation .Bean ;
35
39
import org .springframework .context .annotation .Configuration ;
40
+ import org .springframework .data .neo4j .annotation .EnableBookmarkManagement ;
41
+ import org .springframework .data .neo4j .bookmark .BookmarkManager ;
36
42
import org .springframework .data .neo4j .mapping .Neo4jMappingContext ;
37
43
import org .springframework .data .neo4j .transaction .Neo4jTransactionManager ;
38
44
import org .springframework .data .neo4j .web .support .OpenSessionInViewInterceptor ;
45
+ import org .springframework .web .context .WebApplicationContext ;
39
46
40
47
import static org .assertj .core .api .Assertions .assertThat ;
41
48
import static org .mockito .ArgumentMatchers .any ;
51
58
* @author Vince Bickers
52
59
* @author Andy Wilkinson
53
60
* @author Kazuki Shimizu
61
+ * @author Michael Simons
54
62
*/
55
63
public class Neo4jDataAutoConfigurationTests {
56
64
@@ -69,6 +77,7 @@ public void defaultConfiguration() {
69
77
assertThat (context ).hasSingleBean (SessionFactory .class );
70
78
assertThat (context ).hasSingleBean (Neo4jTransactionManager .class );
71
79
assertThat (context ).hasSingleBean (OpenSessionInViewInterceptor .class );
80
+ assertThat (context ).doesNotHaveBean (BookmarkManager .class );
72
81
});
73
82
}
74
83
@@ -146,6 +155,40 @@ public void eventListenersAreAutoRegistered() {
146
155
});
147
156
}
148
157
158
+ @ Test
159
+ public void providesARequestScopedBookmarkManangerIfNecessaryAndPossible () {
160
+ this .contextRunner
161
+ .withUserConfiguration (BookmarkManagementEnabledConfiguration .class )
162
+ .run ((context ) -> {
163
+ BeanDefinition bookmarkManagerBean = context .getBeanFactory ()
164
+ .getBeanDefinition ("scopedTarget.bookmarkManager" );
165
+ assertThat (bookmarkManagerBean .getScope ())
166
+ .isEqualTo (WebApplicationContext .SCOPE_REQUEST );
167
+ });
168
+ }
169
+
170
+ @ Test
171
+ public void providesASingletonScopedBookmarkManangerIfNecessaryAndPossible () {
172
+ new ApplicationContextRunner ()
173
+ .withUserConfiguration (TestConfiguration .class ,
174
+ BookmarkManagementEnabledConfiguration .class )
175
+ .withConfiguration (AutoConfigurations .of (Neo4jDataAutoConfiguration .class ,
176
+ TransactionAutoConfiguration .class ))
177
+ .run ((context ) -> {
178
+ assertThat (context ).hasSingleBean (BookmarkManager .class );
179
+ assertThat (context .getBeanDefinitionNames ())
180
+ .doesNotContain ("scopedTarget.bookmarkManager" );
181
+ });
182
+ }
183
+
184
+ @ Test
185
+ public void doesNotProvideABookmarkManagerIfNotPossible () {
186
+ this .contextRunner .withClassLoader (new FilteredClassLoader (Caffeine .class ))
187
+ .withUserConfiguration (BookmarkManagementEnabledConfiguration .class )
188
+ .run ((context ) -> assertThat (context )
189
+ .doesNotHaveBean (BookmarkManager .class ));
190
+ }
191
+
149
192
private static void assertDomainTypesDiscovered (Neo4jMappingContext mappingContext ,
150
193
Class <?>... types ) {
151
194
for (Class <?> type : types ) {
@@ -180,6 +223,12 @@ public org.neo4j.ogm.config.Configuration myConfiguration() {
180
223
181
224
}
182
225
226
+ @ Configuration
227
+ @ EnableBookmarkManagement
228
+ static class BookmarkManagementEnabledConfiguration {
229
+
230
+ }
231
+
183
232
@ Configuration
184
233
static class EventListenerConfiguration {
185
234
0 commit comments