Remove remnants of support for Embedded Mongo
See gh-30863 and 7e089a6b
This commit is contained in:
parent
7e089a6b81
commit
0fbfb8ef09
|
|
@ -29,7 +29,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
|||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for Mongo.
|
||||
|
|
@ -66,9 +65,8 @@ public class MongoAutoConfiguration {
|
|||
}
|
||||
|
||||
@Bean
|
||||
MongoPropertiesClientSettingsBuilderCustomizer mongoPropertiesCustomizer(MongoProperties properties,
|
||||
Environment environment) {
|
||||
return new MongoPropertiesClientSettingsBuilderCustomizer(properties, environment);
|
||||
MongoPropertiesClientSettingsBuilderCustomizer mongoPropertiesCustomizer(MongoProperties properties) {
|
||||
return new MongoPropertiesClientSettingsBuilderCustomizer(properties);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import com.mongodb.MongoCredential;
|
|||
import com.mongodb.ServerAddress;
|
||||
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
/**
|
||||
* A {@link MongoClientSettingsBuilderCustomizer} that applies properties from a
|
||||
|
|
@ -37,13 +36,10 @@ public class MongoPropertiesClientSettingsBuilderCustomizer implements MongoClie
|
|||
|
||||
private final MongoProperties properties;
|
||||
|
||||
private final Environment environment;
|
||||
|
||||
private int order = 0;
|
||||
|
||||
public MongoPropertiesClientSettingsBuilderCustomizer(MongoProperties properties, Environment environment) {
|
||||
public MongoPropertiesClientSettingsBuilderCustomizer(MongoProperties properties) {
|
||||
this.properties = properties;
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -59,10 +55,6 @@ public class MongoPropertiesClientSettingsBuilderCustomizer implements MongoClie
|
|||
}
|
||||
|
||||
private void applyHostAndPort(MongoClientSettings.Builder settings) {
|
||||
if (getEmbeddedPort() != null) {
|
||||
settings.applyConnectionString(new ConnectionString("mongodb://localhost:" + getEmbeddedPort()));
|
||||
return;
|
||||
}
|
||||
if (this.properties.getUri() != null) {
|
||||
settings.applyConnectionString(new ConnectionString(this.properties.getUri()));
|
||||
return;
|
||||
|
|
@ -98,16 +90,6 @@ public class MongoPropertiesClientSettingsBuilderCustomizer implements MongoClie
|
|||
return (value != null) ? value : defaultValue;
|
||||
}
|
||||
|
||||
private Integer getEmbeddedPort() {
|
||||
if (this.environment != null) {
|
||||
String localPort = this.environment.getProperty("local.mongo.port");
|
||||
if (localPort != null) {
|
||||
return Integer.valueOf(localPort);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return this.order;
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@ import org.springframework.context.annotation.Bean;
|
|||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for Reactive Mongo.
|
||||
|
|
@ -72,9 +71,8 @@ public class MongoReactiveAutoConfiguration {
|
|||
}
|
||||
|
||||
@Bean
|
||||
MongoPropertiesClientSettingsBuilderCustomizer mongoPropertiesCustomizer(MongoProperties properties,
|
||||
Environment environment) {
|
||||
return new MongoPropertiesClientSettingsBuilderCustomizer(properties, environment);
|
||||
MongoPropertiesClientSettingsBuilderCustomizer mongoPropertiesCustomizer(MongoProperties properties) {
|
||||
return new MongoPropertiesClientSettingsBuilderCustomizer(properties);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,8 +24,6 @@ import com.mongodb.ServerAddress;
|
|||
import org.bson.UuidRepresentation;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
|
|
@ -37,8 +35,6 @@ class MongoPropertiesClientSettingsBuilderCustomizerTests {
|
|||
|
||||
private final MongoProperties properties = new MongoProperties();
|
||||
|
||||
private final MockEnvironment environment = new MockEnvironment();
|
||||
|
||||
@Test
|
||||
void portCanBeCustomized() {
|
||||
this.properties.setPort(12345);
|
||||
|
|
@ -141,16 +137,6 @@ class MongoPropertiesClientSettingsBuilderCustomizerTests {
|
|||
assertMongoCredential(settings.getCredential(), "user", "secret", "test");
|
||||
}
|
||||
|
||||
@Test
|
||||
void uriIsIgnoredInEmbeddedMode() {
|
||||
this.properties.setUri("mongodb://mongo.example.com:1234/mydb");
|
||||
this.environment.setProperty("local.mongo.port", "4000");
|
||||
MongoClientSettings settings = customizeSettings();
|
||||
List<ServerAddress> allAddresses = getAllAddresses(settings);
|
||||
assertThat(allAddresses).hasSize(1);
|
||||
assertServerAddress(allAddresses.get(0), "localhost", 4000);
|
||||
}
|
||||
|
||||
@Test
|
||||
void uriOverridesUsernameAndPassword() {
|
||||
this.properties.setUri("mongodb://127.0.0.1:1234/mydb");
|
||||
|
|
@ -191,7 +177,7 @@ class MongoPropertiesClientSettingsBuilderCustomizerTests {
|
|||
|
||||
private MongoClientSettings customizeSettings() {
|
||||
MongoClientSettings.Builder settings = MongoClientSettings.builder();
|
||||
new MongoPropertiesClientSettingsBuilderCustomizer(this.properties, this.environment).customize(settings);
|
||||
new MongoPropertiesClientSettingsBuilderCustomizer(this.properties).customize(settings);
|
||||
return settings.build();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -549,7 +549,7 @@ If that is not what you want, you can disable transaction management for a test
|
|||
[[features.testing.spring-boot-applications.autoconfigured-spring-data-mongodb]]
|
||||
==== Auto-configured Data MongoDB Tests
|
||||
You can use `@DataMongoTest` to test MongoDB applications.
|
||||
By default, it configures an in-memory embedded MongoDB (if available), configures a `MongoTemplate`, scans for `@Document` classes, and configures Spring Data MongoDB repositories.
|
||||
By default, it configures a `MongoTemplate`, scans for `@Document` classes, and configures Spring Data MongoDB repositories.
|
||||
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@DataMongoTest` annotation is used.
|
||||
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
|
||||
(For more about using MongoDB with Spring Boot, see "<<data#data.nosql.mongodb>>", earlier in this chapter.)
|
||||
|
|
@ -560,6 +560,8 @@ The following class shows the `@DataMongoTest` annotation in use:
|
|||
|
||||
include::code:MyDataMongoDbTests[]
|
||||
|
||||
|
||||
|
||||
[[features.testing.spring-boot-applications.autoconfigured-spring-data-neo4j]]
|
||||
==== Auto-configured Data Neo4j Tests
|
||||
You can use `@DataNeo4jTest` to test Neo4j applications.
|
||||
|
|
|
|||
Loading…
Reference in New Issue