|
| 1 | +/* |
| 2 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
| 3 | + * the License. You may obtain a copy of the License at |
| 4 | + * |
| 5 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | + * |
| 7 | + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
| 8 | + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 9 | + * specific language governing permissions and limitations under the License. |
| 10 | + * |
| 11 | + * Copyright 2019-2022 the original author or authors. |
| 12 | + */ |
| 13 | +package org.quickperf.spring.springboottest.jooqtest; |
| 14 | + |
| 15 | +import org.jooq.DSLContext; |
| 16 | +import org.jooq.Result; |
| 17 | +import org.junit.Test; |
| 18 | +import org.junit.runner.RunWith; |
| 19 | +import org.quickperf.spring.junit4.QuickPerfSpringRunner; |
| 20 | +import org.quickperf.sql.annotation.ExpectSelect; |
| 21 | +import org.springframework.beans.factory.annotation.Autowired; |
| 22 | +import org.springframework.boot.test.autoconfigure.jooq.JooqTest; |
| 23 | +import org.springframework.test.context.jdbc.Sql; |
| 24 | + |
| 25 | +import static org.assertj.core.api.Assertions.assertThat; |
| 26 | + |
| 27 | +@RunWith(QuickPerfSpringRunner.class) |
| 28 | +@JooqTest |
| 29 | +@Sql(statements = { |
| 30 | + "CREATE TABLE IF NOT EXISTS PLAYER_JOOQ_TEST (id BIGINT PRIMARY KEY, name VARCHAR(255))", |
| 31 | + "INSERT INTO PLAYER_JOOQ_TEST VALUES (1, 'Paul Pogba')", |
| 32 | + "INSERT INTO PLAYER_JOOQ_TEST VALUES (2, 'Antoine Griezmann')" |
| 33 | +}) |
| 34 | +public class ExpectSelectWithJooq { |
| 35 | + |
| 36 | + @Autowired |
| 37 | + private DSLContext dslContext; |
| 38 | + |
| 39 | + @ExpectSelect(1) |
| 40 | + @Test |
| 41 | + public void execute_two_selects() { |
| 42 | + |
| 43 | + Result<?> player1 = |
| 44 | + dslContext.fetch("SELECT id, name FROM PLAYER_JOOQ_TEST WHERE id = 1"); |
| 45 | + |
| 46 | + Result<?> player2 = |
| 47 | + dslContext.fetch("SELECT id, name FROM PLAYER_JOOQ_TEST WHERE id = 2"); |
| 48 | + |
| 49 | + assertThat(player1).hasSize(1); |
| 50 | + assertThat(player2).hasSize(1); |
| 51 | + |
| 52 | + } |
| 53 | + |
| 54 | +} |
0 commit comments