Search in sources :

Example 1 with ReactiveMongoDatabaseFactory

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

the class SimpleReactiveMongoDatabaseFactoryUnitTests method cascadedWithSessionUsesRootFactory.

// DATAMONGO-1880
@Test
void cascadedWithSessionUsesRootFactory() {
    when(mongoClient.getDatabase("foo")).thenReturn(database);
    ReactiveMongoDatabaseFactory factory = new SimpleReactiveMongoDatabaseFactory(mongoClient, "foo");
    ReactiveMongoDatabaseFactory wrapped = factory.withSession(clientSession).withSession(clientSession);
    InvocationHandler invocationHandler = Proxy.getInvocationHandler(wrapped.getMongoDatabase().block());
    Object singletonTarget = AopProxyUtils.getSingletonTarget(ReflectionTestUtils.getField(invocationHandler, "advised"));
    assertThat(singletonTarget).isSameAs(database);
}
Also used : ReactiveMongoDatabaseFactory(org.springframework.data.mongodb.ReactiveMongoDatabaseFactory) InvocationHandler(java.lang.reflect.InvocationHandler) Test(org.junit.jupiter.api.Test)

Example 2 with ReactiveMongoDatabaseFactory

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

the class MongoReactiveDataAutoConfigurationTests method grisFsTemplateDatabaseName.

private String grisFsTemplateDatabaseName(AssertableApplicationContext context) {
    assertThat(context).hasSingleBean(ReactiveGridFsTemplate.class);
    ReactiveGridFsTemplate template = context.getBean(ReactiveGridFsTemplate.class);
    ReactiveMongoDatabaseFactory factory = (ReactiveMongoDatabaseFactory) ReflectionTestUtils.getField(template, "dbFactory");
    return factory.getMongoDatabase().block().getName();
}
Also used : ReactiveGridFsTemplate(org.springframework.data.mongodb.gridfs.ReactiveGridFsTemplate) ReactiveMongoDatabaseFactory(org.springframework.data.mongodb.ReactiveMongoDatabaseFactory)

Aggregations

ReactiveMongoDatabaseFactory (org.springframework.data.mongodb.ReactiveMongoDatabaseFactory)2 InvocationHandler (java.lang.reflect.InvocationHandler)1 Test (org.junit.jupiter.api.Test)1 ReactiveGridFsTemplate (org.springframework.data.mongodb.gridfs.ReactiveGridFsTemplate)1