Package fr.ght1pc9kc.testy.mongo
Class WithEmbeddedMongo
java.lang.Object
fr.ght1pc9kc.testy.mongo.WithEmbeddedMongo
- All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterAllCallback,org.junit.jupiter.api.extension.BeforeAllCallback,org.junit.jupiter.api.extension.Extension,org.junit.jupiter.api.extension.ParameterResolver,org.junit.jupiter.api.extension.TestInstantiationAwareExtension
public class WithEmbeddedMongo
extends Object
implements org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.AfterAllCallback, org.junit.jupiter.api.extension.ParameterResolver
Allow launching en Embedded Mongo DB
The flapdoodle download the expected version of Mongo DB in ~/.embedmongo and
run a database for the test.
From this database, an async MongoClient is created and a Spring ReactiveMongoDatabaseFactory wrap it.
@RegisterExtension
static final WithEmbeddedMongo wMongo = WithEmbeddedMongo.builder()
.dbVersion(MongoVersion.V7)
.dbName(DATABASE)
.build();
- See Also:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension
org.junit.jupiter.api.extension.TestInstantiationAwareExtension.ExtensionContextScope -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidafterAll(org.junit.jupiter.api.extension.ExtensionContext context) voidbeforeAll(org.junit.jupiter.api.extension.ExtensionContext context) builder()org.springframework.data.mongodb.ReactiveMongoDatabaseFactoryRetrieve the latest initialized Factory.org.springframework.data.mongodb.core.ReactiveMongoTemplategetMongoTemplate(org.junit.jupiter.api.extension.ExtensionContext context) resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) booleansupportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension
getTestInstantiationExtensionContextScope
-
Field Details
-
P_MONGO_DB_NAME
- See Also:
-
-
Constructor Details
-
WithEmbeddedMongo
public WithEmbeddedMongo()
-
-
Method Details
-
getMongoFactory
public org.springframework.data.mongodb.ReactiveMongoDatabaseFactory getMongoFactory()Retrieve the latest initialized Factory. Avoid to requireExtensionContextand allow SpringBoot mock.If possible, prefer inject
ReactiveMongoDatabaseFactoryin test method instead.- Returns:
- the
ReactiveMongoDatabaseFactorycreated in the beforeAll.
-
getMongoTemplate
public org.springframework.data.mongodb.core.ReactiveMongoTemplate getMongoTemplate(org.junit.jupiter.api.extension.ExtensionContext context) -
beforeAll
public void beforeAll(org.junit.jupiter.api.extension.ExtensionContext context) - Specified by:
beforeAllin interfaceorg.junit.jupiter.api.extension.BeforeAllCallback
-
afterAll
public void afterAll(org.junit.jupiter.api.extension.ExtensionContext context) - Specified by:
afterAllin interfaceorg.junit.jupiter.api.extension.AfterAllCallback
-
supportsParameter
public boolean supportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) - Specified by:
supportsParameterin interfaceorg.junit.jupiter.api.extension.ParameterResolver
-
resolveParameter
public Object resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) - Specified by:
resolveParameterin interfaceorg.junit.jupiter.api.extension.ParameterResolver
-
builder
-