Class WithDatabaseLoaded

java.lang.Object
fr.ght1pc9kc.testy.jooq.WithDatabaseLoaded
All Implemented Interfaces:
org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.Extension

public final class WithDatabaseLoaded extends Object implements org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.BeforeEachCallback

This extension depends on a DatasourceExtension and runs a Flyway migration on the related DB catalog.

By default, the SQL scripts have to be located into db.migration.<catalog> in the classpath, where <catalog> is the name of DataSource catalog. The names of the SQL files shall match Flyway naming convention.

The SQL scripts are run **before all the test methods**. They are expected to be used to create the database schema.


 private static final WithInMemoryDatasource wDataSource = WithInMemoryDatasource.builder()
         .setCatalog("my_catalog")
         .build();

 // SQL files shall be located in classpath:db.migration.my_catalog
 private static final WithDatabaseLoaded wDatabaseLoaded = WithDatabaseLoaded.builder()
         .setDatasourceExtension(wDataSource)
         .build();

 @RegisterExtension
 static final ChainedExtension chain = ChainedExtension
         .outer(wDataSource)
         .append(wDatabaseLoaded)
         .register();
 
  • Constructor Details

    • WithDatabaseLoaded

      public WithDatabaseLoaded()
  • Method Details

    • beforeAll

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

      public void beforeEach(org.junit.jupiter.api.extension.ExtensionContext context)
      Specified by:
      beforeEach in interface org.junit.jupiter.api.extension.BeforeEachCallback
    • builder