Of course
public class MyDataProvider : MockDataProvider {
@Throws(SQLException::class)
override fun execute(ctx: MockExecuteContext): Array<out MockResult>? {
val create = using(SQLDialect.MYSQL)
val sql = ctx.sql()
println(sql)
val result = create.newResult<Int, String>(field(AUTHOR.ID),
field(AUTHOR.LAST_NAME))
result.add(create.newRecord(field(AUTHOR.ID),
field(AUTHOR.LAST_NAME)).values(1, "Orwell"))
result.add(create.newRecord(field(AUTHOR.ID),
field(AUTHOR.LAST_NAME)).values(2, "One"))
var mock = MockResult(1, result)
return arrayOf(mock)
}
}
@Test
fun JooqTest() {
val provider = MyDataProvider()
val connection = MockConnection(provider)
val create = DSL.using(connection, SQLDialect.DEFAULT)
var rq = create.select().from(AUTHOR.TABLE).where(AUTHOR.ID.eq(2)).fetch()
}
when I run it I get on rq :
0 = {RecordImpl@6450} "+----+---------+\n|
id|LAST_NAME|\n+----+---------+\n| 1|Orwell |\n+----+---------+\n"
1 = {RecordImpl@6451} "+----+---------+\n|
id|LAST_NAME|\n+----+---------+\n| 2|One |\n+----+---------+\n"
I expected get only second row
Br,
Hagi
On Tuesday, September 14, 2021 at 10:19:35 AM UTC+3 [email protected]
wrote:
> Hi Hagi,
>
> The manual already shows how to do it "correctly", but maybe, you can show
> exactly what you did? Otherwise, it will be difficult to spot what you
> might have done wrong.
>
> Thanks
> Lukas
>
> On Tue, Sep 14, 2021 at 7:17 AM Hagi Cohen <[email protected]> wrote:
>
>> I work with Jooq on our system and I try mock DB (MYSQL) for testing.
>>
>> I using JDBC mocking for unit test from your guide
>> https://www.jooq.org/doc/3.7/manual/tools/jdbc-mocking/
>>
>> I didn’t understand and didn’t success get result for query as example:
>> I add more records to results but when run this query I get all results
>> and look filter (where) not execute.
>> Result<BookRecord> result =
>> create.selectFrom(BOOK).where(BOOK.ID.eq(5)).fetch();
>>
>> Can you please help me how write the mock correctly so I get in the end
>> results of query and not all records created.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "jOOQ User Group" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/jooq-user/200930b2-d95c-4df5-90aa-0b7d3c179bb9n%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/jooq-user/200930b2-d95c-4df5-90aa-0b7d3c179bb9n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
--
You received this message because you are subscribed to the Google Groups "jOOQ
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jooq-user/88c75b90-ba27-497e-be3c-3c8a8b26a957n%40googlegroups.com.