21
21
import javax .sql .DataSource ;
22
22
23
23
import org .junit .jupiter .api .Test ;
24
+ import org .mockito .Answers ;
24
25
25
26
import org .springframework .boot .autoconfigure .AutoConfigurations ;
26
27
import org .springframework .boot .autoconfigure .TestAutoConfigurationPackage ;
32
33
import org .springframework .boot .autoconfigure .jdbc .JdbcTemplateAutoConfiguration ;
33
34
import org .springframework .boot .autoconfigure .sql .init .SqlInitializationAutoConfiguration ;
34
35
import org .springframework .boot .test .context .runner .ApplicationContextRunner ;
36
+ import org .springframework .context .annotation .Bean ;
35
37
import org .springframework .context .annotation .Configuration ;
36
38
import org .springframework .data .domain .ManagedTypes ;
39
+ import org .springframework .data .jdbc .core .JdbcAggregateTemplate ;
40
+ import org .springframework .data .jdbc .core .convert .DataAccessStrategy ;
41
+ import org .springframework .data .jdbc .core .convert .JdbcConverter ;
42
+ import org .springframework .data .jdbc .core .convert .JdbcCustomConversions ;
37
43
import org .springframework .data .jdbc .core .mapping .JdbcMappingContext ;
38
44
import org .springframework .data .jdbc .repository .config .AbstractJdbcConfiguration ;
39
45
import org .springframework .data .jdbc .repository .config .EnableJdbcRepositories ;
46
+ import org .springframework .data .relational .RelationalManagedTypes ;
47
+ import org .springframework .data .relational .core .dialect .Dialect ;
40
48
import org .springframework .data .repository .Repository ;
41
49
import org .springframework .jdbc .core .namedparam .NamedParameterJdbcOperations ;
42
50
import org .springframework .test .util .ReflectionTestUtils ;
43
51
44
52
import static org .assertj .core .api .Assertions .assertThat ;
53
+ import static org .mockito .Mockito .mock ;
45
54
46
55
/**
47
56
* Tests for {@link JdbcRepositoriesAutoConfiguration}.
@@ -128,6 +137,56 @@ void honoursUsersEnableJdbcRepositoriesConfiguration() {
128
137
});
129
138
}
130
139
140
+ @ Test
141
+ void allowsUserToDefineCustomRelationalManagedTypes () {
142
+ allowsUserToDefineCustomBean (RelationalManagedTypesConfiguration .class , RelationalManagedTypes .class ,
143
+ "customRelationalManagedTypes" );
144
+ }
145
+
146
+ @ Test
147
+ void allowsUserToDefineCustomJdbcMappingContext () {
148
+ allowsUserToDefineCustomBean (JdbcMappingContextConfiguration .class , JdbcMappingContext .class ,
149
+ "customJdbcMappingContext" );
150
+ }
151
+
152
+ @ Test
153
+ void allowsUserToDefineCustomJdbcConverter () {
154
+ allowsUserToDefineCustomBean (JdbcConverterConfiguration .class , JdbcConverter .class , "customJdbcConverter" );
155
+ }
156
+
157
+ @ Test
158
+ void allowsUserToDefineCustomJdbcCustomConversions () {
159
+ allowsUserToDefineCustomBean (JdbcCustomConversionsConfiguration .class , JdbcCustomConversions .class ,
160
+ "customJdbcCustomConversions" );
161
+ }
162
+
163
+ @ Test
164
+ void allowsUserToDefineCustomJdbcAggregateTemplate () {
165
+ allowsUserToDefineCustomBean (JdbcAggregateTemplateConfiguration .class , JdbcAggregateTemplate .class ,
166
+ "customJdbcAggregateTemplate" );
167
+ }
168
+
169
+ @ Test
170
+ void allowsUserToDefineCustomDataAccessStrategy () {
171
+ allowsUserToDefineCustomBean (DataAccessStrategyConfiguration .class , DataAccessStrategy .class ,
172
+ "customDataAccessStrategy" );
173
+ }
174
+
175
+ @ Test
176
+ void allowsUserToDefineCustomDialect () {
177
+ allowsUserToDefineCustomBean (DialectConfiguration .class , Dialect .class , "customDialect" );
178
+ }
179
+
180
+ private void allowsUserToDefineCustomBean (Class <?> configuration , Class <?> beanType , String beanName ) {
181
+ this .contextRunner .with (database ())
182
+ .withConfiguration (AutoConfigurations .of (JdbcTemplateAutoConfiguration .class ,
183
+ DataSourceTransactionManagerAutoConfiguration .class ))
184
+ .withUserConfiguration (configuration , EmptyConfiguration .class ).run ((context ) -> {
185
+ assertThat (context ).hasSingleBean (beanType );
186
+ assertThat (context ).hasBean (beanName );
187
+ });
188
+ }
189
+
131
190
private Function <ApplicationContextRunner , ApplicationContextRunner > database () {
132
191
return (runner ) -> runner
133
192
.withConfiguration (AutoConfigurations .of (DataSourceAutoConfiguration .class ,
@@ -154,4 +213,74 @@ static class EnableRepositoriesConfiguration {
154
213
155
214
}
156
215
216
+ @ Configuration (proxyBeanMethods = false )
217
+ static class RelationalManagedTypesConfiguration {
218
+
219
+ @ Bean
220
+ RelationalManagedTypes customRelationalManagedTypes () {
221
+ return RelationalManagedTypes .empty ();
222
+ }
223
+
224
+ }
225
+
226
+ @ Configuration (proxyBeanMethods = false )
227
+ static class JdbcMappingContextConfiguration {
228
+
229
+ @ Bean
230
+ JdbcMappingContext customJdbcMappingContext () {
231
+ return mock (JdbcMappingContext .class );
232
+ }
233
+
234
+ }
235
+
236
+ @ Configuration (proxyBeanMethods = false )
237
+ static class JdbcConverterConfiguration {
238
+
239
+ @ Bean
240
+ JdbcConverter customJdbcConverter () {
241
+ return mock (JdbcConverter .class );
242
+ }
243
+
244
+ }
245
+
246
+ @ Configuration (proxyBeanMethods = false )
247
+ static class JdbcCustomConversionsConfiguration {
248
+
249
+ @ Bean
250
+ JdbcCustomConversions customJdbcCustomConversions () {
251
+ return mock (JdbcCustomConversions .class , Answers .RETURNS_MOCKS );
252
+ }
253
+
254
+ }
255
+
256
+ @ Configuration (proxyBeanMethods = false )
257
+ static class JdbcAggregateTemplateConfiguration {
258
+
259
+ @ Bean
260
+ JdbcAggregateTemplate customJdbcAggregateTemplate () {
261
+ return mock (JdbcAggregateTemplate .class );
262
+ }
263
+
264
+ }
265
+
266
+ @ Configuration (proxyBeanMethods = false )
267
+ static class DataAccessStrategyConfiguration {
268
+
269
+ @ Bean
270
+ DataAccessStrategy customDataAccessStrategy () {
271
+ return mock (DataAccessStrategy .class );
272
+ }
273
+
274
+ }
275
+
276
+ @ Configuration (proxyBeanMethods = false )
277
+ static class DialectConfiguration {
278
+
279
+ @ Bean
280
+ Dialect customDialect () {
281
+ return mock (Dialect .class , Answers .RETURNS_MOCKS );
282
+ }
283
+
284
+ }
285
+
157
286
}
0 commit comments