diff --git a/spring/junit4-spring-boot-1-test/src/test/java/org/quickperf/spring/springboottest/SpringBoot1Junit4JdbcTest.java b/spring/junit4-spring-boot-1-test/src/test/java/org/quickperf/spring/springboottest/SpringBoot1Junit4JdbcTest.java index 616cd8b6..0e950cca 100644 --- a/spring/junit4-spring-boot-1-test/src/test/java/org/quickperf/spring/springboottest/SpringBoot1Junit4JdbcTest.java +++ b/spring/junit4-spring-boot-1-test/src/test/java/org/quickperf/spring/springboottest/SpringBoot1Junit4JdbcTest.java @@ -34,8 +34,7 @@ public void should_detect_select_with_jdbctest() { String testReport = printableResult.toString(); assertThat(testReport) - .contains("You may think that <1> select statement was sent to the database") - .contains("Perhaps you are facing an N+1 select issue"); + .contains("You may think that <1> select statement was sent to the database"); } diff --git a/spring/junit4-spring-boot-1-test/src/test/java/org/quickperf/spring/springboottest/jdbctest/ExpectSelectWithJdbc.java b/spring/junit4-spring-boot-1-test/src/test/java/org/quickperf/spring/springboottest/jdbctest/ExpectSelectWithJdbc.java index 70aa08e3..0f883ade 100644 --- a/spring/junit4-spring-boot-1-test/src/test/java/org/quickperf/spring/springboottest/jdbctest/ExpectSelectWithJdbc.java +++ b/spring/junit4-spring-boot-1-test/src/test/java/org/quickperf/spring/springboottest/jdbctest/ExpectSelectWithJdbc.java @@ -37,7 +37,7 @@ public class ExpectSelectWithJdbc { @ExpectSelect(1) @Test - public void should_detect_two_selects() { + public void execute_two_selects() { java.util.List> player1 = jdbcTemplate.queryForList("SELECT id, name FROM PLAYER_JDBC_TEST WHERE id = 1"); diff --git a/spring/junit4-spring-boot-test/pom.xml b/spring/junit4-spring-boot-test/pom.xml index e7710ce5..f6e94023 100644 --- a/spring/junit4-spring-boot-test/pom.xml +++ b/spring/junit4-spring-boot-test/pom.xml @@ -86,6 +86,11 @@ spring-boot-starter-data-jpa + + org.springframework.boot + spring-boot-starter-jooq + + org.springframework.boot spring-boot-devtools diff --git a/spring/junit4-spring-boot-test/src/test/java/org/quickperf/spring/springboottest/SpringBoot2JUnit4DataJdbcTest.java b/spring/junit4-spring-boot-test/src/test/java/org/quickperf/spring/springboottest/SpringBoot2JUnit4DataJdbcTest.java index 83c687b7..55623e48 100644 --- a/spring/junit4-spring-boot-test/src/test/java/org/quickperf/spring/springboottest/SpringBoot2JUnit4DataJdbcTest.java +++ b/spring/junit4-spring-boot-test/src/test/java/org/quickperf/spring/springboottest/SpringBoot2JUnit4DataJdbcTest.java @@ -34,8 +34,7 @@ public void should_detect_select_with_datajdbctest() { String testReport = printableResult.toString(); assertThat(testReport) - .contains("You may think that <1> select statement was sent to the database") - .contains("Perhaps you are facing an N+1 select issue"); + .contains("You may think that <1> select statement was sent to the database"); } diff --git a/spring/junit4-spring-boot-test/src/test/java/org/quickperf/spring/springboottest/SpringBoot2JUnit4JdbcTest.java b/spring/junit4-spring-boot-test/src/test/java/org/quickperf/spring/springboottest/SpringBoot2JUnit4JdbcTest.java index d812fbcd..1a9029c6 100644 --- a/spring/junit4-spring-boot-test/src/test/java/org/quickperf/spring/springboottest/SpringBoot2JUnit4JdbcTest.java +++ b/spring/junit4-spring-boot-test/src/test/java/org/quickperf/spring/springboottest/SpringBoot2JUnit4JdbcTest.java @@ -34,8 +34,7 @@ public void should_detect_select_with_jdbctest() { String testReport = printableResult.toString(); assertThat(testReport) - .contains("You may think that <1> select statement was sent to the database") - .contains("Perhaps you are facing an N+1 select issue"); + .contains("You may think that <1> select statement was sent to the database"); } diff --git a/spring/junit4-spring-boot-test/src/test/java/org/quickperf/spring/springboottest/SpringBoot2JUnit4JooqTest.java b/spring/junit4-spring-boot-test/src/test/java/org/quickperf/spring/springboottest/SpringBoot2JUnit4JooqTest.java new file mode 100644 index 00000000..b2fac20b --- /dev/null +++ b/spring/junit4-spring-boot-test/src/test/java/org/quickperf/spring/springboottest/SpringBoot2JUnit4JooqTest.java @@ -0,0 +1,41 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2019-2022 the original author or authors. + */ +package org.quickperf.spring.springboottest; + +import org.junit.Test; +import org.junit.experimental.results.PrintableResult; +import org.quickperf.spring.springboottest.jooqtest.ExpectSelectWithJooq; + +import static org.assertj.core.api.Assertions.assertThat; + +public class SpringBoot2JUnit4JooqTest { + + @Test + public void should_detect_select_with_jooqtest() { + + // GIVEN + Class testClass = ExpectSelectWithJooq.class; + + // WHEN + PrintableResult printableResult = PrintableResult.testResult(testClass); + + // THEN + assertThat(printableResult.failureCount()).isOne(); + + String testReport = printableResult.toString(); + assertThat(testReport) + .contains("You may think that <1> select statement was sent to the database"); + + } + +} diff --git a/spring/junit4-spring-boot-test/src/test/java/org/quickperf/spring/springboottest/datajdbctest/ExpectSelectWithDataJdbc.java b/spring/junit4-spring-boot-test/src/test/java/org/quickperf/spring/springboottest/datajdbctest/ExpectSelectWithDataJdbc.java index 23e6ee5a..a236cd0e 100644 --- a/spring/junit4-spring-boot-test/src/test/java/org/quickperf/spring/springboottest/datajdbctest/ExpectSelectWithDataJdbc.java +++ b/spring/junit4-spring-boot-test/src/test/java/org/quickperf/spring/springboottest/datajdbctest/ExpectSelectWithDataJdbc.java @@ -37,7 +37,7 @@ public class ExpectSelectWithDataJdbc { @ExpectSelect(1) @Test - public void should_detect_two_selects() { + public void execute_two_selects() { java.util.List> player1 = jdbcTemplate.queryForList("SELECT id, name FROM PLAYER_DATA_JDBC_TEST WHERE id = 1"); diff --git a/spring/junit4-spring-boot-test/src/test/java/org/quickperf/spring/springboottest/jdbctest/ExpectSelectWithJdbc.java b/spring/junit4-spring-boot-test/src/test/java/org/quickperf/spring/springboottest/jdbctest/ExpectSelectWithJdbc.java index 70aa08e3..0f883ade 100644 --- a/spring/junit4-spring-boot-test/src/test/java/org/quickperf/spring/springboottest/jdbctest/ExpectSelectWithJdbc.java +++ b/spring/junit4-spring-boot-test/src/test/java/org/quickperf/spring/springboottest/jdbctest/ExpectSelectWithJdbc.java @@ -37,7 +37,7 @@ public class ExpectSelectWithJdbc { @ExpectSelect(1) @Test - public void should_detect_two_selects() { + public void execute_two_selects() { java.util.List> player1 = jdbcTemplate.queryForList("SELECT id, name FROM PLAYER_JDBC_TEST WHERE id = 1"); diff --git a/spring/junit4-spring-boot-test/src/test/java/org/quickperf/spring/springboottest/jooqtest/ExpectSelectWithJooq.java b/spring/junit4-spring-boot-test/src/test/java/org/quickperf/spring/springboottest/jooqtest/ExpectSelectWithJooq.java new file mode 100644 index 00000000..e0967f60 --- /dev/null +++ b/spring/junit4-spring-boot-test/src/test/java/org/quickperf/spring/springboottest/jooqtest/ExpectSelectWithJooq.java @@ -0,0 +1,54 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2019-2022 the original author or authors. + */ +package org.quickperf.spring.springboottest.jooqtest; + +import org.jooq.DSLContext; +import org.jooq.Result; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.quickperf.spring.junit4.QuickPerfSpringRunner; +import org.quickperf.sql.annotation.ExpectSelect; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jooq.JooqTest; +import org.springframework.test.context.jdbc.Sql; + +import static org.assertj.core.api.Assertions.assertThat; + +@RunWith(QuickPerfSpringRunner.class) +@JooqTest +@Sql(statements = { + "CREATE TABLE IF NOT EXISTS PLAYER_JOOQ_TEST (id BIGINT PRIMARY KEY, name VARCHAR(255))", + "INSERT INTO PLAYER_JOOQ_TEST VALUES (1, 'Paul Pogba')", + "INSERT INTO PLAYER_JOOQ_TEST VALUES (2, 'Antoine Griezmann')" +}) +public class ExpectSelectWithJooq { + + @Autowired + private DSLContext dslContext; + + @ExpectSelect(1) + @Test + public void execute_two_selects() { + + Result player1 = + dslContext.fetch("SELECT id, name FROM PLAYER_JOOQ_TEST WHERE id = 1"); + + Result player2 = + dslContext.fetch("SELECT id, name FROM PLAYER_JOOQ_TEST WHERE id = 2"); + + assertThat(player1).hasSize(1); + assertThat(player2).hasSize(1); + + } + +} diff --git a/spring/junit5-spring-boot-3-test/pom.xml b/spring/junit5-spring-boot-3-test/pom.xml index 71964179..04ae5f62 100644 --- a/spring/junit5-spring-boot-3-test/pom.xml +++ b/spring/junit5-spring-boot-3-test/pom.xml @@ -90,6 +90,11 @@ spring-boot-starter-data-jdbc + + org.springframework.boot + spring-boot-starter-jooq + + org.springframework.boot spring-boot-starter-web diff --git a/spring/junit5-spring-boot-3-test/src/test/java/org/quickperf/spring/springboottest/SpringBoot3JUnit5DataJdbcTest.java b/spring/junit5-spring-boot-3-test/src/test/java/org/quickperf/spring/springboottest/SpringBoot3JUnit5DataJdbcTest.java index 1907d349..63733b1f 100644 --- a/spring/junit5-spring-boot-3-test/src/test/java/org/quickperf/spring/springboottest/SpringBoot3JUnit5DataJdbcTest.java +++ b/spring/junit5-spring-boot-3-test/src/test/java/org/quickperf/spring/springboottest/SpringBoot3JUnit5DataJdbcTest.java @@ -36,8 +36,7 @@ void should_detect_select_with_data_jdbc_test() { String errorReport = jUnit5TestsResult.getErrorReport(); assertThat(errorReport) - .contains("You may think that <1> select statement was sent to the database") - .contains("Perhaps you are facing an N+1 select issue"); + .contains("You may think that <1> select statement was sent to the database"); } diff --git a/spring/junit5-spring-boot-3-test/src/test/java/org/quickperf/spring/springboottest/SpringBoot3JUnit5JdbcTest.java b/spring/junit5-spring-boot-3-test/src/test/java/org/quickperf/spring/springboottest/SpringBoot3JUnit5JdbcTest.java index 696cbd0b..0d620456 100644 --- a/spring/junit5-spring-boot-3-test/src/test/java/org/quickperf/spring/springboottest/SpringBoot3JUnit5JdbcTest.java +++ b/spring/junit5-spring-boot-3-test/src/test/java/org/quickperf/spring/springboottest/SpringBoot3JUnit5JdbcTest.java @@ -36,8 +36,7 @@ void should_detect_select_with_jdbc_test() { String errorReport = jUnit5TestsResult.getErrorReport(); assertThat(errorReport) - .contains("You may think that <1> select statement was sent to the database") - .contains("Perhaps you are facing an N+1 select issue"); + .contains("You may think that <1> select statement was sent to the database"); } diff --git a/spring/junit5-spring-boot-3-test/src/test/java/org/quickperf/spring/springboottest/SpringBoot3JUnit5JooqTest.java b/spring/junit5-spring-boot-3-test/src/test/java/org/quickperf/spring/springboottest/SpringBoot3JUnit5JooqTest.java new file mode 100644 index 00000000..968e5c54 --- /dev/null +++ b/spring/junit5-spring-boot-3-test/src/test/java/org/quickperf/spring/springboottest/SpringBoot3JUnit5JooqTest.java @@ -0,0 +1,43 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2019-2022 the original author or authors. + */ +package org.quickperf.spring.springboottest; + +import org.junit.jupiter.api.Test; +import org.quickperf.junit5.JUnit5Tests; +import org.quickperf.junit5.JUnit5Tests.JUnit5TestsResult; +import org.quickperf.spring.springboottest.jooqtest.ExpectSelectWithJooq; + +import static org.assertj.core.api.Assertions.assertThat; + +class SpringBoot3JUnit5JooqTest { + + @Test + void should_detect_select_with_jooq_test() { + + // GIVEN + Class testClass = ExpectSelectWithJooq.class; + JUnit5Tests jUnit5Tests = JUnit5Tests.createInstance(testClass); + + // WHEN + JUnit5TestsResult jUnit5TestsResult = jUnit5Tests.run(); + + // THEN + assertThat(jUnit5TestsResult.getNumberOfFailures()).isOne(); + + String errorReport = jUnit5TestsResult.getErrorReport(); + assertThat(errorReport) + .contains("You may think that <1> select statement was sent to the database"); + + } + +} diff --git a/spring/junit5-spring-boot-3-test/src/test/java/org/quickperf/spring/springboottest/datajdbctest/ExpectSelectWithDataJdbc.java b/spring/junit5-spring-boot-3-test/src/test/java/org/quickperf/spring/springboottest/datajdbctest/ExpectSelectWithDataJdbc.java index 1ee16830..98290903 100644 --- a/spring/junit5-spring-boot-3-test/src/test/java/org/quickperf/spring/springboottest/datajdbctest/ExpectSelectWithDataJdbc.java +++ b/spring/junit5-spring-boot-3-test/src/test/java/org/quickperf/spring/springboottest/datajdbctest/ExpectSelectWithDataJdbc.java @@ -36,7 +36,7 @@ public class ExpectSelectWithDataJdbc { @ExpectSelect(1) @Test - public void should_detect_two_selects() { + public void execute_two_selects() { java.util.List> player1 = jdbcTemplate.queryForList("SELECT id, name FROM PLAYER_DATA_JDBC_TEST WHERE id = 1"); diff --git a/spring/junit5-spring-boot-3-test/src/test/java/org/quickperf/spring/springboottest/jdbctest/ExpectSelectWithJdbc.java b/spring/junit5-spring-boot-3-test/src/test/java/org/quickperf/spring/springboottest/jdbctest/ExpectSelectWithJdbc.java index 94492534..52fcc63b 100644 --- a/spring/junit5-spring-boot-3-test/src/test/java/org/quickperf/spring/springboottest/jdbctest/ExpectSelectWithJdbc.java +++ b/spring/junit5-spring-boot-3-test/src/test/java/org/quickperf/spring/springboottest/jdbctest/ExpectSelectWithJdbc.java @@ -36,7 +36,7 @@ public class ExpectSelectWithJdbc { @ExpectSelect(1) @Test - public void should_detect_two_selects() { + public void execute_two_selects() { java.util.List> player1 = jdbcTemplate.queryForList("SELECT id, name FROM PLAYER_JDBC_TEST WHERE id = 1"); diff --git a/spring/junit5-spring-boot-3-test/src/test/java/org/quickperf/spring/springboottest/jooqtest/ExpectSelectWithJooq.java b/spring/junit5-spring-boot-3-test/src/test/java/org/quickperf/spring/springboottest/jooqtest/ExpectSelectWithJooq.java new file mode 100644 index 00000000..fbcdbeba --- /dev/null +++ b/spring/junit5-spring-boot-3-test/src/test/java/org/quickperf/spring/springboottest/jooqtest/ExpectSelectWithJooq.java @@ -0,0 +1,53 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2019-2022 the original author or authors. + */ +package org.quickperf.spring.springboottest.jooqtest; + +import org.jooq.DSLContext; +import org.jooq.Result; +import org.junit.jupiter.api.Test; +import org.quickperf.junit5.QuickPerfTest; +import org.quickperf.sql.annotation.ExpectSelect; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jooq.JooqTest; +import org.springframework.test.context.jdbc.Sql; + +import static org.assertj.core.api.Assertions.assertThat; + +@QuickPerfTest +@JooqTest +@Sql(statements = { + "CREATE TABLE IF NOT EXISTS PLAYER_JOOQ_TEST (id BIGINT PRIMARY KEY, name VARCHAR(255))", + "INSERT INTO PLAYER_JOOQ_TEST VALUES (1, 'Paul Pogba')", + "INSERT INTO PLAYER_JOOQ_TEST VALUES (2, 'Antoine Griezmann')" +}) +public class ExpectSelectWithJooq { + + @Autowired + private DSLContext dslContext; + + @ExpectSelect(1) + @Test + public void execute_two_selects() { + + Result player1 = + dslContext.fetch("SELECT id, name FROM PLAYER_JOOQ_TEST WHERE id = 1"); + + Result player2 = + dslContext.fetch("SELECT id, name FROM PLAYER_JOOQ_TEST WHERE id = 2"); + + assertThat(player1).hasSize(1); + assertThat(player2).hasSize(1); + + } + +} diff --git a/spring/spring-boot-2-sql-starter/src/main/resources/META-INF/spring.factories b/spring/spring-boot-2-sql-starter/src/main/resources/META-INF/spring.factories index 2b7eac9f..b89c90fb 100644 --- a/spring/spring-boot-2-sql-starter/src/main/resources/META-INF/spring.factories +++ b/spring/spring-boot-2-sql-starter/src/main/resources/META-INF/spring.factories @@ -8,4 +8,7 @@ org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureJdbc=\ org.quickperf.spring.boot.QuickPerfProxyBeanAutoConfiguration org.springframework.boot.test.autoconfigure.data.jdbc.AutoConfigureDataJdbc=\ +org.quickperf.spring.boot.QuickPerfProxyBeanAutoConfiguration + +org.springframework.boot.test.autoconfigure.jooq.AutoConfigureJooq=\ org.quickperf.spring.boot.QuickPerfProxyBeanAutoConfiguration \ No newline at end of file diff --git a/spring/spring-boot-2-sql-starter/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.jooq.AutoConfigureJooq.imports b/spring/spring-boot-2-sql-starter/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.jooq.AutoConfigureJooq.imports new file mode 100644 index 00000000..8f206e65 --- /dev/null +++ b/spring/spring-boot-2-sql-starter/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.jooq.AutoConfigureJooq.imports @@ -0,0 +1 @@ +org.quickperf.spring.boot.QuickPerfProxyBeanAutoConfiguration