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 TypeMethodDescriptionvoid
afterAll
(org.junit.jupiter.api.extension.ExtensionContext context) void
beforeAll
(org.junit.jupiter.api.extension.ExtensionContext context) builder()
org.springframework.data.mongodb.ReactiveMongoDatabaseFactory
Retrieve the latest initialized Factory.org.springframework.data.mongodb.core.ReactiveMongoTemplate
getMongoTemplate
(org.junit.jupiter.api.extension.ExtensionContext context) resolveParameter
(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) boolean
supportsParameter
(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, wait
Methods 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 requireExtensionContext
and allow SpringBoot mock.If possible, prefer inject
ReactiveMongoDatabaseFactory
in test method instead.- Returns:
- the
ReactiveMongoDatabaseFactory
created 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:
beforeAll
in interfaceorg.junit.jupiter.api.extension.BeforeAllCallback
-
afterAll
public void afterAll(org.junit.jupiter.api.extension.ExtensionContext context) - Specified by:
afterAll
in 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:
supportsParameter
in 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:
resolveParameter
in interfaceorg.junit.jupiter.api.extension.ParameterResolver
-
builder
-