-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 도메인 모듈 테스트 격리 추가 (Web을 사용하지 못해 Transactional 설정)
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
backend/pcloud-domain/src/test/java/com/domain/helper/IntegrationHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> 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<String> truncateAllTablesQuery) { | ||
jdbcTemplate.execute("SET FOREIGN_KEY_CHECKS = 0"); | ||
|
||
for (String truncateQuery : truncateAllTablesQuery) { | ||
jdbcTemplate.execute(truncateQuery); | ||
} | ||
|
||
jdbcTemplate.execute("SET FOREIGN_KEY_CHECKS = 1"); | ||
} | ||
} |