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.

Usage:

 @RegisterExtension
 static final WithEmbeddedMongo wMongo = WithEmbeddedMongo.builder()
         .dbVersion(MongoVersion.V7)
         .dbName(DATABASE)
         .build();
 
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
     

    Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension

    org.junit.jupiter.api.extension.TestInstantiationAwareExtension.ExtensionContextScope
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    afterAll(org.junit.jupiter.api.extension.ExtensionContext context)
     
    void
    beforeAll(org.junit.jupiter.api.extension.ExtensionContext context)
     
     
    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

  • Constructor Details

    • WithEmbeddedMongo

      public WithEmbeddedMongo()
  • Method Details

    • getMongoFactory

      public org.springframework.data.mongodb.ReactiveMongoDatabaseFactory getMongoFactory()
      Retrieve the latest initialized Factory. Avoid to require ExtensionContext 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 interface org.junit.jupiter.api.extension.BeforeAllCallback
    • afterAll

      public void afterAll(org.junit.jupiter.api.extension.ExtensionContext context)
      Specified by:
      afterAll in interface org.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 interface org.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 interface org.junit.jupiter.api.extension.ParameterResolver
    • builder