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
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 to launch 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.
- See Also:
-
Nested Class Summary
-
Field Summary
-
Constructor Summary
-
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)
-
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
- Specified by:
beforeAll
in interfaceorg.junit.jupiter.api.extension.BeforeAllCallback
- Throws:
IOException
-
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
-