Search in sources :

Example 6 with MongoDatabaseFactory

use of org.springframework.data.mongodb.MongoDatabaseFactory in project spring-data-mongodb by spring-projects.

the class MongoNamespaceTests method testMongoTemplateFactory.

// DATAMONGO-140
@Test
public void testMongoTemplateFactory() {
    assertThat(ctx.containsBean("mongoTemplate")).isTrue();
    MongoOperations operations = (MongoOperations) ctx.getBean("mongoTemplate");
    MongoDatabaseFactory dbf = (MongoDatabaseFactory) getField(operations, "mongoDbFactory");
    assertThat(getField(dbf, "databaseName")).isEqualTo("database");
    MongoConverter converter = (MongoConverter) getField(operations, "mongoConverter");
    assertThat(converter).isNotNull();
}
Also used : MongoDatabaseFactory(org.springframework.data.mongodb.MongoDatabaseFactory) MongoOperations(org.springframework.data.mongodb.core.MongoOperations) MongoConverter(org.springframework.data.mongodb.core.convert.MongoConverter) Test(org.junit.Test)

Example 7 with MongoDatabaseFactory

use of org.springframework.data.mongodb.MongoDatabaseFactory in project spring-data-mongodb by spring-projects.

the class MongoNamespaceTests method testSecondMongoTemplateFactory.

// DATAMONGO-140
@Test
public void testSecondMongoTemplateFactory() {
    assertThat(ctx.containsBean("anotherMongoTemplate")).isTrue();
    MongoOperations operations = (MongoOperations) ctx.getBean("anotherMongoTemplate");
    MongoDatabaseFactory dbf = (MongoDatabaseFactory) getField(operations, "mongoDbFactory");
    assertThat(getField(dbf, "databaseName")).isEqualTo("database");
    WriteConcern writeConcern = (WriteConcern) getField(operations, "writeConcern");
    assertThat(writeConcern).isEqualTo(WriteConcern.ACKNOWLEDGED);
}
Also used : MongoDatabaseFactory(org.springframework.data.mongodb.MongoDatabaseFactory) WriteConcern(com.mongodb.WriteConcern) MongoOperations(org.springframework.data.mongodb.core.MongoOperations) Test(org.junit.Test)

Example 8 with MongoDatabaseFactory

use of org.springframework.data.mongodb.MongoDatabaseFactory in project spring-data-mongodb by spring-projects.

the class MongoNamespaceTests method testSecondGridFsTemplateFactory.

// DATAMONGO-628
@Test
public void testSecondGridFsTemplateFactory() {
    assertThat(ctx.containsBean("secondGridFsTemplate")).isTrue();
    GridFsOperations operations = (GridFsOperations) ctx.getBean("secondGridFsTemplate");
    MongoDatabaseFactory dbf = (MongoDatabaseFactory) getField(operations, "dbFactory");
    assertThat(getField(dbf, "databaseName")).isEqualTo("database");
    assertThat(getField(operations, "bucket")).isEqualTo(null);
    MongoConverter converter = (MongoConverter) getField(operations, "converter");
    assertThat(converter).isNotNull();
}
Also used : MongoDatabaseFactory(org.springframework.data.mongodb.MongoDatabaseFactory) MongoConverter(org.springframework.data.mongodb.core.convert.MongoConverter) GridFsOperations(org.springframework.data.mongodb.gridfs.GridFsOperations) Test(org.junit.Test)

Example 9 with MongoDatabaseFactory

use of org.springframework.data.mongodb.MongoDatabaseFactory in project spring-data-mongodb by spring-projects.

the class MongoNamespaceTests method testSecondMongoDbFactory.

@Test
public void testSecondMongoDbFactory() {
    assertThat(ctx.containsBean("secondMongoDbFactory")).isTrue();
    MongoDatabaseFactory dbf = (MongoDatabaseFactory) ctx.getBean("secondMongoDbFactory");
    MongoClient mongo = (MongoClient) getField(dbf, "mongoClient");
    assertThat(mongo.getClusterDescription().getClusterSettings().getHosts()).containsExactly(new ServerAddress());
    assertThat(getField(dbf, "databaseName")).isEqualTo("database");
}
Also used : MongoClient(com.mongodb.client.MongoClient) MongoDatabaseFactory(org.springframework.data.mongodb.MongoDatabaseFactory) ServerAddress(com.mongodb.ServerAddress) Test(org.junit.Test)

Example 10 with MongoDatabaseFactory

use of org.springframework.data.mongodb.MongoDatabaseFactory in project spring-data-mongodb by spring-projects.

the class MongoDbFactoryParserIntegrationTests method usesConnectionStringToCreateClientClient.

// DATAMONGO-2384
@Test
public void usesConnectionStringToCreateClientClient() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("namespace/db-factory-bean.xml");
    MongoDatabaseFactory dbFactory = ctx.getBean("with-connection-string", MongoDatabaseFactory.class);
    assertThat(dbFactory).isInstanceOf(SimpleMongoClientDatabaseFactory.class);
    assertThat(ReflectionTestUtils.getField(dbFactory, "mongoClient")).isInstanceOf(com.mongodb.client.MongoClient.class);
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) MongoDatabaseFactory(org.springframework.data.mongodb.MongoDatabaseFactory) Test(org.junit.jupiter.api.Test)

Aggregations

MongoDatabaseFactory (org.springframework.data.mongodb.MongoDatabaseFactory)19 Test (org.junit.jupiter.api.Test)9 Test (org.junit.Test)7 MongoConverter (org.springframework.data.mongodb.core.convert.MongoConverter)5 MongoDatabase (com.mongodb.client.MongoDatabase)3 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)3 GridFsOperations (org.springframework.data.mongodb.gridfs.GridFsOperations)3 ServerAddress (com.mongodb.ServerAddress)2 WriteConcern (com.mongodb.WriteConcern)2 MongoClient (com.mongodb.client.MongoClient)2 InvocationHandler (java.lang.reflect.InvocationHandler)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 MongoOperations (org.springframework.data.mongodb.core.MongoOperations)2 ClientSessionOptions (com.mongodb.ClientSessionOptions)1 ConnectionString (com.mongodb.ConnectionString)1 CursorType (com.mongodb.CursorType)1 MongoException (com.mongodb.MongoException)1 ReadPreference (com.mongodb.ReadPreference)1 MongoCollection (com.mongodb.client.MongoCollection)1 com.mongodb.client.model (com.mongodb.client.model)1