Class WithInMemoryDatasource

java.lang.Object
fr.ght1pc9kc.testy.jooq.WithInMemoryDatasource
All Implemented Interfaces:
DatasourceExtension, 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 WithInMemoryDatasource extends Object implements org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.AfterAllCallback, org.junit.jupiter.api.extension.ParameterResolver, DatasourceExtension
Allow to create an H2 in-memory database.

Usable with ExtendWith or RegisterExtension:


     @RegisterExtension
     static WithInMemoryDatasource wDs = WithInMemoryDatasource.builder()
             .setCatalog(CATALOG_NAME)
             .wrapTcpServer(true)
             .build();
 

The default value for the catalog is random UUID. By default the TCP Server was not run.

The database parameters :

  • MODE=MySQL
  • DB_CLOSE_DELAY=-1
  • DATABASE_TO_UPPER=false
  • TIMEZONE=UTC
  • SCHEMA created and set

For inject the auto-generated catalog name use DbCatalogName annotation

See Also:
  • Constructor Details

    • WithInMemoryDatasource

      public WithInMemoryDatasource()
  • Method Details

    • beforeAll

      public void beforeAll(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Specified by:
      beforeAll in interface org.junit.jupiter.api.extension.BeforeAllCallback
      Throws:
      Exception
    • getCatalog

      public String getCatalog(org.junit.jupiter.api.extension.ExtensionContext context)
      Description copied from interface: DatasourceExtension
      Retrieve the name of the DataSource catalog
      Specified by:
      getCatalog in interface DatasourceExtension
      Parameters:
      context - The extension context
      Returns:
      The catalog name
    • getDataSource

      public DataSource getDataSource(org.junit.jupiter.api.extension.ExtensionContext context)
      Description copied from interface: DatasourceExtension
      Retrieve the DataSource from the contextual extension Store
      Specified by:
      getDataSource in interface DatasourceExtension
      Parameters:
      context - The extension context
      Returns:
      A usable DataSource
    • 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