Skip to content

Commit 08868ff

Browse files
authored
Add @JooqTest support for Spring Boot (#258)
1 parent ed82cda commit 08868ff

18 files changed

Lines changed: 215 additions & 15 deletions

File tree

spring/junit4-spring-boot-1-test/src/test/java/org/quickperf/spring/springboottest/SpringBoot1Junit4JdbcTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ public void should_detect_select_with_jdbctest() {
3434

3535
String testReport = printableResult.toString();
3636
assertThat(testReport)
37-
.contains("You may think that <1> select statement was sent to the database")
38-
.contains("Perhaps you are facing an N+1 select issue");
37+
.contains("You may think that <1> select statement was sent to the database");
3938

4039
}
4140

spring/junit4-spring-boot-1-test/src/test/java/org/quickperf/spring/springboottest/jdbctest/ExpectSelectWithJdbc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class ExpectSelectWithJdbc {
3737

3838
@ExpectSelect(1)
3939
@Test
40-
public void should_detect_two_selects() {
40+
public void execute_two_selects() {
4141

4242
java.util.List<java.util.Map<String, Object>> player1 =
4343
jdbcTemplate.queryForList("SELECT id, name FROM PLAYER_JDBC_TEST WHERE id = 1");

spring/junit4-spring-boot-test/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@
8686
<artifactId>spring-boot-starter-data-jpa</artifactId>
8787
</dependency>
8888

89+
<dependency>
90+
<groupId>org.springframework.boot</groupId>
91+
<artifactId>spring-boot-starter-jooq</artifactId>
92+
</dependency>
93+
8994
<dependency>
9095
<groupId>org.springframework.boot</groupId>
9196
<artifactId>spring-boot-devtools</artifactId>

spring/junit4-spring-boot-test/src/test/java/org/quickperf/spring/springboottest/SpringBoot2JUnit4DataJdbcTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ public void should_detect_select_with_datajdbctest() {
3434

3535
String testReport = printableResult.toString();
3636
assertThat(testReport)
37-
.contains("You may think that <1> select statement was sent to the database")
38-
.contains("Perhaps you are facing an N+1 select issue");
37+
.contains("You may think that <1> select statement was sent to the database");
3938

4039
}
4140

spring/junit4-spring-boot-test/src/test/java/org/quickperf/spring/springboottest/SpringBoot2JUnit4JdbcTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ public void should_detect_select_with_jdbctest() {
3434

3535
String testReport = printableResult.toString();
3636
assertThat(testReport)
37-
.contains("You may think that <1> select statement was sent to the database")
38-
.contains("Perhaps you are facing an N+1 select issue");
37+
.contains("You may think that <1> select statement was sent to the database");
3938

4039
}
4140

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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;
14+
15+
import org.junit.Test;
16+
import org.junit.experimental.results.PrintableResult;
17+
import org.quickperf.spring.springboottest.jooqtest.ExpectSelectWithJooq;
18+
19+
import static org.assertj.core.api.Assertions.assertThat;
20+
21+
public class SpringBoot2JUnit4JooqTest {
22+
23+
@Test
24+
public void should_detect_select_with_jooqtest() {
25+
26+
// GIVEN
27+
Class<?> testClass = ExpectSelectWithJooq.class;
28+
29+
// WHEN
30+
PrintableResult printableResult = PrintableResult.testResult(testClass);
31+
32+
// THEN
33+
assertThat(printableResult.failureCount()).isOne();
34+
35+
String testReport = printableResult.toString();
36+
assertThat(testReport)
37+
.contains("You may think that <1> select statement was sent to the database");
38+
39+
}
40+
41+
}

spring/junit4-spring-boot-test/src/test/java/org/quickperf/spring/springboottest/datajdbctest/ExpectSelectWithDataJdbc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class ExpectSelectWithDataJdbc {
3737

3838
@ExpectSelect(1)
3939
@Test
40-
public void should_detect_two_selects() {
40+
public void execute_two_selects() {
4141

4242
java.util.List<java.util.Map<String, Object>> player1 =
4343
jdbcTemplate.queryForList("SELECT id, name FROM PLAYER_DATA_JDBC_TEST WHERE id = 1");

spring/junit4-spring-boot-test/src/test/java/org/quickperf/spring/springboottest/jdbctest/ExpectSelectWithJdbc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class ExpectSelectWithJdbc {
3737

3838
@ExpectSelect(1)
3939
@Test
40-
public void should_detect_two_selects() {
40+
public void execute_two_selects() {
4141

4242
java.util.List<java.util.Map<String, Object>> player1 =
4343
jdbcTemplate.queryForList("SELECT id, name FROM PLAYER_JDBC_TEST WHERE id = 1");
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
}

spring/junit5-spring-boot-3-test/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@
9090
<artifactId>spring-boot-starter-data-jdbc</artifactId>
9191
</dependency>
9292

93+
<dependency>
94+
<groupId>org.springframework.boot</groupId>
95+
<artifactId>spring-boot-starter-jooq</artifactId>
96+
</dependency>
97+
9398
<dependency>
9499
<groupId>org.springframework.boot</groupId>
95100
<artifactId>spring-boot-starter-web</artifactId>

0 commit comments

Comments
 (0)