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:
>, then
DSLContext#fetchFromTXT(String) is usedDisclaimer
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.
| Modifier and Type | Field and Description |
|---|---|
| private final MockFileDatabaseConfiguration | |
| private final DSLContext | |
| private static final Pattern | |
| private static final JooqLogger | |
| private final Map | |
| private final Map | |
| private String | nullLiteral
Deprecated
|
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| public | |
| public | |
| public | |
| public | |
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public MockResult[] | execute(MockExecuteContext
The execution context. ctx)Implements org. |
| private void | |
| public MockFileDatabase | nullLiteral(String literal)
Deprecated
- Use
Specify the MockFileDatabaseConfiguration#nullLiteral(String)
instead.
null literal, i.e. the string that should be
parsed as a null reference, rather than as the string
itself.
|
| public Map |
| configuration | back to summary |
|---|---|
| private final MockFileDatabaseConfiguration configuration | |
| create | back to summary |
|---|---|
| private final DSLContext create | |
| END_OF_STATEMENT | back to summary |
|---|---|
| private static final Pattern END_OF_STATEMENT | |
| log | back to summary |
|---|---|
| private static final JooqLogger log | |
| matchExactly | back to summary |
|---|---|
| private final Map<String, List<MockResult>> matchExactly | |
| matchPattern | back to summary |
|---|---|
| private final Map<Pattern, List<MockResult>> matchPattern | |
| nullLiteral | back to summary |
|---|---|
| private String nullLiteral
Deprecated
| |
| MockFileDatabase | back to summary |
|---|---|
| public MockFileDatabase(File file) throws IOException | |
| MockFileDatabase | back to summary |
|---|---|
| public MockFileDatabase(File file, String encoding) throws IOException | |
| MockFileDatabase | back to summary |
|---|---|
| public MockFileDatabase(InputStream stream) throws IOException | |
| MockFileDatabase | back to summary |
|---|---|
| public MockFileDatabase(InputStream stream, String encoding) throws IOException | |
| MockFileDatabase | back to summary |
|---|---|
| public MockFileDatabase(Reader reader) throws IOException | |
| MockFileDatabase | back to summary |
|---|---|
| public MockFileDatabase(String string) throws IOException | |
| MockFileDatabase | back to summary |
|---|---|
| public MockFileDatabase(Source source) throws IOException | |
| MockFileDatabase | back to summary |
|---|---|
| public MockFileDatabase(MockFileDatabaseConfiguration configuration) throws IOException | |
| execute | back to summary |
|---|---|
| public MockResult[] execute(MockExecuteContext ctx) throws SQLException Implements org. Doc from org. Execution callback for a JDBC query execution.
This callback will be called by
The various execution modes are unified into this simple method. Implementations should adhere to this contract:
| |
| load | back to summary |
|---|---|
| private void load() throws FileNotFoundException, IOException | |
| nullLiteral | back to summary |
|---|---|
| public MockFileDatabase nullLiteral(String literal)
Deprecated - Use
Specify the
| |
| queries | back to summary |
|---|---|
| public Map Deprecated - Experimental: Do not use. Subject to change.
| |