16
16
17
17
package org .springframework .boot .autoconfigure .mongo ;
18
18
19
+ import javax .net .SocketFactory ;
20
+
19
21
import com .mongodb .Mongo ;
22
+ import com .mongodb .MongoClient ;
20
23
import com .mongodb .MongoClientOptions ;
21
24
import org .junit .After ;
22
25
import org .junit .Test ;
28
31
import org .springframework .context .annotation .Configuration ;
29
32
30
33
import static org .assertj .core .api .Assertions .assertThat ;
34
+ import static org .mockito .Mockito .mock ;
31
35
32
36
/**
33
37
* Tests for {@link MongoAutoConfiguration}.
34
38
*
35
39
* @author Dave Syer
40
+ * @author Stephane Nicoll
36
41
*/
37
42
public class MongoAutoConfigurationTests {
38
43
@@ -78,6 +83,20 @@ public void optionsAddedButNoHost() {
78
83
.isEqualTo (300 );
79
84
}
80
85
86
+ @ Test
87
+ public void optionsSslConfig () {
88
+ this .context = new AnnotationConfigApplicationContext ();
89
+ EnvironmentTestUtils .addEnvironment (this .context ,
90
+ "spring.data.mongodb.uri:mongodb://localhost/test" );
91
+ this .context .register (SslOptionsConfig .class ,
92
+ PropertyPlaceholderAutoConfiguration .class , MongoAutoConfiguration .class );
93
+ this .context .refresh ();
94
+ MongoClient mongo = this .context .getBean (MongoClient .class );
95
+ MongoClientOptions options = mongo .getMongoClientOptions ();
96
+ assertThat (options .isSslEnabled ()).isTrue ();
97
+ assertThat (options .getSocketFactory ()).isSameAs (this .context .getBean ("mySocketFactory" ));
98
+ }
99
+
81
100
@ Configuration
82
101
protected static class OptionsConfig {
83
102
@@ -88,4 +107,19 @@ public MongoClientOptions mongoOptions() {
88
107
89
108
}
90
109
110
+ @ Configuration
111
+ protected static class SslOptionsConfig {
112
+
113
+ @ Bean
114
+ public MongoClientOptions mongoClientOptions () {
115
+ return MongoClientOptions .builder ().sslEnabled (true ).socketFactory (mySocketFactory ()).build ();
116
+ }
117
+
118
+ @ Bean
119
+ public SocketFactory mySocketFactory () {
120
+ return mock (SocketFactory .class );
121
+ }
122
+
123
+ }
124
+
91
125
}
0 commit comments