use of com.mongodb.MongoClient in project spring-boot by spring-projects.
the class EmbeddedMongoAutoConfigurationTests method randomlyAllocatedPortIsAvailableWhenCreatingMongoClient.
@Test
public void randomlyAllocatedPortIsAvailableWhenCreatingMongoClient() {
load(MongoClientConfiguration.class);
MongoClient client = this.context.getBean(MongoClient.class);
Integer mongoPort = Integer.valueOf(this.context.getEnvironment().getProperty("local.mongo.port"));
assertThat(client.getAddress().getPort()).isEqualTo(mongoPort);
}
use of com.mongodb.MongoClient in project spring-boot by spring-projects.
the class EmbeddedMongoAutoConfigurationTests method useRandomPortByDefault.
@Test
public void useRandomPortByDefault() {
load();
assertThat(this.context.getBeansOfType(MongoClient.class)).hasSize(1);
MongoClient client = this.context.getBean(MongoClient.class);
Integer mongoPort = Integer.valueOf(this.context.getEnvironment().getProperty("local.mongo.port"));
assertThat(client.getAddress().getPort()).isEqualTo(mongoPort);
}
use of com.mongodb.MongoClient in project spring-boot by spring-projects.
the class MongoAutoConfigurationTests method optionsSslConfig.
@Test
public void optionsSslConfig() {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context, "spring.data.mongodb.uri:mongodb://localhost/test");
this.context.register(SslOptionsConfig.class, PropertyPlaceholderAutoConfiguration.class, MongoAutoConfiguration.class);
this.context.refresh();
MongoClient mongo = this.context.getBean(MongoClient.class);
MongoClientOptions options = mongo.getMongoClientOptions();
assertThat(options.isSslEnabled()).isTrue();
assertThat(options.getSocketFactory()).isSameAs(this.context.getBean("mySocketFactory"));
}
use of com.mongodb.MongoClient in project spring-boot by spring-projects.
the class MongoClientFactoryTests method uriIsIgnoredInEmbeddedMode.
@Test
public void uriIsIgnoredInEmbeddedMode() {
MongoProperties properties = new MongoProperties();
properties.setUri("mongodb://mongo.example.com:1234/mydb");
this.environment.setProperty("local.mongo.port", "4000");
MongoClient client = createMongoClient(properties, this.environment);
List<ServerAddress> allAddresses = extractServerAddresses(client);
assertThat(allAddresses).hasSize(1);
assertServerAddress(allAddresses.get(0), "localhost", 4000);
}
use of com.mongodb.MongoClient in project java-design-patterns by iluwatar.
the class MongoBank method connect.
/**
* Connect to database with given parameters
*/
public void connect(String dbName, String accountsCollectionName) {
if (mongoClient != null) {
mongoClient.close();
}
mongoClient = new MongoClient(System.getProperty("mongo-host"), Integer.parseInt(System.getProperty("mongo-port")));
database = mongoClient.getDatabase(dbName);
accountsCollection = database.getCollection(accountsCollectionName);
}
Aggregations