|
|
|
@ -19,11 +19,11 @@ package org.springframework.boot.autoconfigure.mongo.embedded; |
|
|
|
import java.io.File; |
|
|
|
import java.io.File; |
|
|
|
import java.net.UnknownHostException; |
|
|
|
import java.net.UnknownHostException; |
|
|
|
|
|
|
|
|
|
|
|
import com.mongodb.CommandResult; |
|
|
|
|
|
|
|
import com.mongodb.MongoClient; |
|
|
|
import com.mongodb.MongoClient; |
|
|
|
import de.flapdoodle.embed.mongo.config.IMongodConfig; |
|
|
|
import de.flapdoodle.embed.mongo.config.IMongodConfig; |
|
|
|
import de.flapdoodle.embed.mongo.config.Storage; |
|
|
|
import de.flapdoodle.embed.mongo.config.Storage; |
|
|
|
import de.flapdoodle.embed.mongo.distribution.Feature; |
|
|
|
import de.flapdoodle.embed.mongo.distribution.Feature; |
|
|
|
|
|
|
|
import org.bson.Document; |
|
|
|
import org.junit.After; |
|
|
|
import org.junit.After; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
|
|
|
|
@ -82,8 +82,8 @@ public class EmbeddedMongoAutoConfigurationTests { |
|
|
|
load(); |
|
|
|
load(); |
|
|
|
assertThat(this.context.getBeansOfType(MongoClient.class)).hasSize(1); |
|
|
|
assertThat(this.context.getBeansOfType(MongoClient.class)).hasSize(1); |
|
|
|
MongoClient client = this.context.getBean(MongoClient.class); |
|
|
|
MongoClient client = this.context.getBean(MongoClient.class); |
|
|
|
Integer mongoPort = Integer.valueOf( |
|
|
|
Integer mongoPort = Integer |
|
|
|
this.context.getEnvironment().getProperty("local.mongo.port")); |
|
|
|
.valueOf(this.context.getEnvironment().getProperty("local.mongo.port")); |
|
|
|
assertThat(client.getAddress().getPort()).isEqualTo(mongoPort); |
|
|
|
assertThat(client.getAddress().getPort()).isEqualTo(mongoPort); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -92,8 +92,8 @@ public class EmbeddedMongoAutoConfigurationTests { |
|
|
|
load("spring.data.mongodb.port=0"); |
|
|
|
load("spring.data.mongodb.port=0"); |
|
|
|
assertThat(this.context.getBeansOfType(MongoClient.class)).hasSize(1); |
|
|
|
assertThat(this.context.getBeansOfType(MongoClient.class)).hasSize(1); |
|
|
|
MongoClient client = this.context.getBean(MongoClient.class); |
|
|
|
MongoClient client = this.context.getBean(MongoClient.class); |
|
|
|
Integer mongoPort = Integer.valueOf( |
|
|
|
Integer mongoPort = Integer |
|
|
|
this.context.getEnvironment().getProperty("local.mongo.port")); |
|
|
|
.valueOf(this.context.getEnvironment().getProperty("local.mongo.port")); |
|
|
|
assertThat(client.getAddress().getPort()).isEqualTo(mongoPort); |
|
|
|
assertThat(client.getAddress().getPort()).isEqualTo(mongoPort); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -101,8 +101,8 @@ public class EmbeddedMongoAutoConfigurationTests { |
|
|
|
public void randomlyAllocatedPortIsAvailableWhenCreatingMongoClient() { |
|
|
|
public void randomlyAllocatedPortIsAvailableWhenCreatingMongoClient() { |
|
|
|
load(MongoClientConfiguration.class); |
|
|
|
load(MongoClientConfiguration.class); |
|
|
|
MongoClient client = this.context.getBean(MongoClient.class); |
|
|
|
MongoClient client = this.context.getBean(MongoClient.class); |
|
|
|
Integer mongoPort = Integer.valueOf( |
|
|
|
Integer mongoPort = Integer |
|
|
|
this.context.getEnvironment().getProperty("local.mongo.port")); |
|
|
|
.valueOf(this.context.getEnvironment().getProperty("local.mongo.port")); |
|
|
|
assertThat(client.getAddress().getPort()).isEqualTo(mongoPort); |
|
|
|
assertThat(client.getAddress().getPort()).isEqualTo(mongoPort); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -172,7 +172,7 @@ public class EmbeddedMongoAutoConfigurationTests { |
|
|
|
MongoDataAutoConfiguration.class, EmbeddedMongoAutoConfiguration.class); |
|
|
|
MongoDataAutoConfiguration.class, EmbeddedMongoAutoConfiguration.class); |
|
|
|
this.context.refresh(); |
|
|
|
this.context.refresh(); |
|
|
|
MongoTemplate mongo = this.context.getBean(MongoTemplate.class); |
|
|
|
MongoTemplate mongo = this.context.getBean(MongoTemplate.class); |
|
|
|
CommandResult buildInfo = mongo.executeCommand("{ buildInfo: 1 }"); |
|
|
|
Document buildInfo = mongo.executeCommand("{ buildInfo: 1 }"); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(buildInfo.getString("version")).isEqualTo(expectedVersion); |
|
|
|
assertThat(buildInfo.getString("version")).isEqualTo(expectedVersion); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -187,8 +187,7 @@ public class EmbeddedMongoAutoConfigurationTests { |
|
|
|
ctx.register(config); |
|
|
|
ctx.register(config); |
|
|
|
} |
|
|
|
} |
|
|
|
EnvironmentTestUtils.addEnvironment(ctx, environment); |
|
|
|
EnvironmentTestUtils.addEnvironment(ctx, environment); |
|
|
|
ctx.register(EmbeddedMongoAutoConfiguration.class, |
|
|
|
ctx.register(EmbeddedMongoAutoConfiguration.class, MongoAutoConfiguration.class, |
|
|
|
MongoAutoConfiguration.class, |
|
|
|
|
|
|
|
PropertyPlaceholderAutoConfiguration.class); |
|
|
|
PropertyPlaceholderAutoConfiguration.class); |
|
|
|
ctx.refresh(); |
|
|
|
ctx.refresh(); |
|
|
|
this.context = ctx; |
|
|
|
this.context = ctx; |
|
|
|
|