Module org.jooq

Class MockFileDatabase

java.lang.Object
org.jooq.tools.jdbc.MockFileDatabase
All Implemented Interfaces:
MockDataProvider

public class MockFileDatabase extends Object implements MockDataProvider
A file-based MockDataProvider.

This data provider reads a database model from a text file, as documented in the below sample file:

 # Comments start off with a hash

 # Statement strings have no prefix and should be ended with a semi-colon
 select 'A' from dual;
 # Statements may be followed by results, using >
 > A
 > -
 > A
 # Statements should be followed by "@ rows: [N]" indicating the update count
 @ rows: 1

 # New statements can be listed int his file
 select 'A', 'B' from dual;
 > A B
 > - -
 > A B
 @ rows: 1

 # Beware of the exact syntax (e.g. using quotes)
 select "TABLE1"."ID1", "TABLE1"."NAME1" from "TABLE1";
 > ID1 NAME1
 > --- -----
 > 1   X
 > 2   Y
 @ rows: 2

 # Statements can return several results
 > F1  F2  F3 is a bit more complex
 > --- --  ----------------------------
 > 1   2   and a string containing data
 > 1.1 x   another string
 @ rows: 2

 > A B "C D"
 > - - -----
 > x y z
 @ rows: 1
 

Results can be loaded using several techniques:

  • When results are prefixed with >, then DSLContext.fetchFromTXT(String) is used
  • In the future, other types of result sources will be supported, such as CSV, XML, JSON

Disclaimer: The general idea of mocking a JDBC connection with this jOOQ API is to provide quick workarounds, injection points, etc. using a very simple JDBC abstraction. It is NOT RECOMMENDED to emulate an entire database (including complex state transitions, transactions, locking, etc.) using this mock API. Once you have this requirement, please consider using an actual database instead for integration testing (e.g. using https://www.testcontainers.org), rather than implementing your test database inside of a MockDataProvider.

Author:
Lukas Eder, Samy Deghou