From a8e12b57a09875c9005f4bab2802b206d64149db Mon Sep 17 00:00:00 2001 From: sosow0212 Date: Tue, 6 Aug 2024 17:00:19 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=8F=84=EB=A9=94=EC=9D=B8=20=EB=AA=A8?= =?UTF-8?q?=EB=93=88=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EA=B2=A9=EB=A6=AC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20(Web=EC=9D=84=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EB=AA=BB=ED=95=B4=20Transactional=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/domain/helper/IntegrationHelper.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 backend/pcloud-domain/src/test/java/com/domain/helper/IntegrationHelper.java diff --git a/backend/pcloud-domain/src/test/java/com/domain/helper/IntegrationHelper.java b/backend/pcloud-domain/src/test/java/com/domain/helper/IntegrationHelper.java new file mode 100644 index 00000000..ee8aeec5 --- /dev/null +++ b/backend/pcloud-domain/src/test/java/com/domain/helper/IntegrationHelper.java @@ -0,0 +1,39 @@ +package com.domain.helper; + +import org.junit.jupiter.api.BeforeEach; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.test.context.support.AbstractTestExecutionListener; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +@Transactional +@SpringBootTest +public class IntegrationHelper extends AbstractTestExecutionListener { + + @Autowired + private JdbcTemplate jdbcTemplate; + + @BeforeEach + void init() { + validateH2Database(); + List truncateAllTablesQuery = jdbcTemplate.queryForList("SELECT CONCAT('TRUNCATE TABLE ', TABLE_NAME, ';') AS q FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'PUBLIC'", String.class); + truncateAllTables(truncateAllTablesQuery); + } + + private void validateH2Database() { + jdbcTemplate.queryForObject("SELECT H2VERSION() FROM DUAL", String.class); + } + + private void truncateAllTables(List truncateAllTablesQuery) { + jdbcTemplate.execute("SET FOREIGN_KEY_CHECKS = 0"); + + for (String truncateQuery : truncateAllTablesQuery) { + jdbcTemplate.execute(truncateQuery); + } + + jdbcTemplate.execute("SET FOREIGN_KEY_CHECKS = 1"); + } +}