|
|
|
@ -29,8 +29,10 @@ import org.junit.Test; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigurations; |
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigurations; |
|
|
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner; |
|
|
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner; |
|
|
|
|
|
|
|
import org.springframework.context.ApplicationContext; |
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
|
|
|
|
import org.springframework.test.util.ReflectionTestUtils; |
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
import static org.mockito.ArgumentMatchers.any; |
|
|
|
import static org.mockito.ArgumentMatchers.any; |
|
|
|
@ -59,10 +61,8 @@ public class MongoReactiveAutoConfigurationTests { |
|
|
|
public void optionsAdded() { |
|
|
|
public void optionsAdded() { |
|
|
|
this.contextRunner.withPropertyValues("spring.data.mongodb.host:localhost") |
|
|
|
this.contextRunner.withPropertyValues("spring.data.mongodb.host:localhost") |
|
|
|
.withUserConfiguration(OptionsConfig.class) |
|
|
|
.withUserConfiguration(OptionsConfig.class) |
|
|
|
.run((context) -> assertThat( |
|
|
|
.run((context) -> assertThat(getSettings(context).getSocketSettings() |
|
|
|
context.getBean(MongoClient.class).getSettings() |
|
|
|
.getReadTimeout(TimeUnit.SECONDS)).isEqualTo(300)); |
|
|
|
.getSocketSettings().getReadTimeout(TimeUnit.SECONDS)) |
|
|
|
|
|
|
|
.isEqualTo(300)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -70,9 +70,8 @@ public class MongoReactiveAutoConfigurationTests { |
|
|
|
this.contextRunner |
|
|
|
this.contextRunner |
|
|
|
.withPropertyValues("spring.data.mongodb.uri:mongodb://localhost/test") |
|
|
|
.withPropertyValues("spring.data.mongodb.uri:mongodb://localhost/test") |
|
|
|
.withUserConfiguration(OptionsConfig.class) |
|
|
|
.withUserConfiguration(OptionsConfig.class) |
|
|
|
.run((context) -> assertThat(context.getBean(MongoClient.class) |
|
|
|
.run((context) -> assertThat(getSettings(context).getReadPreference()) |
|
|
|
.getSettings().getReadPreference()) |
|
|
|
.isEqualTo(ReadPreference.nearest())); |
|
|
|
.isEqualTo(ReadPreference.nearest())); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -81,9 +80,7 @@ public class MongoReactiveAutoConfigurationTests { |
|
|
|
.withPropertyValues("spring.data.mongodb.uri:mongodb://localhost/test") |
|
|
|
.withPropertyValues("spring.data.mongodb.uri:mongodb://localhost/test") |
|
|
|
.withUserConfiguration(SslOptionsConfig.class).run((context) -> { |
|
|
|
.withUserConfiguration(SslOptionsConfig.class).run((context) -> { |
|
|
|
assertThat(context).hasSingleBean(MongoClient.class); |
|
|
|
assertThat(context).hasSingleBean(MongoClient.class); |
|
|
|
MongoClient mongo = context.getBean(MongoClient.class); |
|
|
|
MongoClientSettings settings = getSettings(context); |
|
|
|
com.mongodb.async.client.MongoClientSettings settings = mongo |
|
|
|
|
|
|
|
.getSettings(); |
|
|
|
|
|
|
|
assertThat(settings.getApplicationName()).isEqualTo("test-config"); |
|
|
|
assertThat(settings.getApplicationName()).isEqualTo("test-config"); |
|
|
|
assertThat(settings.getStreamFactoryFactory()) |
|
|
|
assertThat(settings.getStreamFactoryFactory()) |
|
|
|
.isSameAs(context.getBean("myStreamFactoryFactory")); |
|
|
|
.isSameAs(context.getBean("myStreamFactoryFactory")); |
|
|
|
@ -94,9 +91,8 @@ public class MongoReactiveAutoConfigurationTests { |
|
|
|
public void nettyStreamFactoryFactoryIsConfiguredAutomatically() { |
|
|
|
public void nettyStreamFactoryFactoryIsConfiguredAutomatically() { |
|
|
|
this.contextRunner.run((context) -> { |
|
|
|
this.contextRunner.run((context) -> { |
|
|
|
assertThat(context).hasSingleBean(MongoClient.class); |
|
|
|
assertThat(context).hasSingleBean(MongoClient.class); |
|
|
|
assertThat(context.getBean(MongoClient.class).getSettings() |
|
|
|
assertThat(getSettings(context).getStreamFactoryFactory()) |
|
|
|
.getStreamFactoryFactory()) |
|
|
|
.isInstanceOf(NettyStreamFactoryFactory.class); |
|
|
|
.isInstanceOf(NettyStreamFactoryFactory.class); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -106,14 +102,21 @@ public class MongoReactiveAutoConfigurationTests { |
|
|
|
"spring.data.mongodb.uri:mongodb://localhost/test?appname=auto-config") |
|
|
|
"spring.data.mongodb.uri:mongodb://localhost/test?appname=auto-config") |
|
|
|
.withUserConfiguration(SimpleCustomizerConfig.class).run((context) -> { |
|
|
|
.withUserConfiguration(SimpleCustomizerConfig.class).run((context) -> { |
|
|
|
assertThat(context).hasSingleBean(MongoClient.class); |
|
|
|
assertThat(context).hasSingleBean(MongoClient.class); |
|
|
|
MongoClient client = context.getBean(MongoClient.class); |
|
|
|
MongoClientSettings settings = getSettings(context); |
|
|
|
assertThat(client.getSettings().getApplicationName()) |
|
|
|
assertThat(settings.getApplicationName()) |
|
|
|
.isEqualTo("overridden-name"); |
|
|
|
.isEqualTo("overridden-name"); |
|
|
|
assertThat(client.getSettings().getStreamFactoryFactory()) |
|
|
|
assertThat(settings.getStreamFactoryFactory()) |
|
|
|
.isEqualTo(SimpleCustomizerConfig.streamFactoryFactory); |
|
|
|
.isEqualTo(SimpleCustomizerConfig.streamFactoryFactory); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("deprecation") |
|
|
|
|
|
|
|
private MongoClientSettings getSettings(ApplicationContext context) { |
|
|
|
|
|
|
|
MongoClient client = context.getBean(MongoClient.class); |
|
|
|
|
|
|
|
return (MongoClientSettings) ReflectionTestUtils.getField(client.getSettings(), |
|
|
|
|
|
|
|
"wrapped"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
@Configuration |
|
|
|
static class OptionsConfig { |
|
|
|
static class OptionsConfig { |
|
|
|
|
|
|
|
|
|
|
|
|