-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
테스트 코드 작성 환경 설정 #85
테스트 코드 작성 환경 설정 #85
Changes from 14 commits
412cf51
c4db65e
2721dd3
dd04e9b
1534964
1bb8175
f8b4850
41c25a1
21ef50d
15a0790
50b17cf
ea9b97f
23d811a
99266c9
91d1f14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.project.bumawiki.global.annotation; | ||
|
||
import org.junit.jupiter.api.DisplayNameGeneration; | ||
import org.junit.jupiter.api.DisplayNameGenerator; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import static java.lang.annotation.ElementType.*; | ||
import static java.lang.annotation.RetentionPolicy.*; | ||
|
||
@Target(TYPE) | ||
@Retention(RUNTIME) | ||
@Transactional | ||
@SpringBootTest | ||
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) | ||
public @interface ServiceTest { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.project.bumawiki.global.truncate; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@Component | ||
public class Truncate { | ||
@Autowired | ||
private JdbcTemplate jdbcTemplate; | ||
|
||
@Transactional | ||
public void beforeEach() { | ||
final List<String> truncateQueries = getTruncateQueries(jdbcTemplate); | ||
execute(jdbcTemplate, "SET REFERENTIAL_INTEGRITY FALSE"); | ||
truncateTables(jdbcTemplate, truncateQueries); | ||
execute(jdbcTemplate, "SET REFERENTIAL_INTEGRITY TRUE"); | ||
} | ||
|
||
private List<String> getTruncateQueries(final JdbcTemplate jdbcTemplate) { | ||
return jdbcTemplate.queryForList("SELECT Concat('TRUNCATE TABLE ', TABLE_NAME, ' RESTART IDENTITY;') AS q FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'PUBLIC'", String.class); | ||
} | ||
|
||
private void truncateTables(final JdbcTemplate jdbcTemplate, final List<String> truncateQueries) { | ||
truncateQueries.forEach(v -> execute(jdbcTemplate, v)); | ||
} | ||
|
||
private void execute(final JdbcTemplate jdbcTemplate, final String query) { | ||
jdbcTemplate.execute(query); | ||
} | ||
} | ||
Comment on lines
+16
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이거의 전체 흐름을 설명해주세요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. truncate 처리를 코드에서 진행하기 위한 함수입니다
위와같은 형태로 테이블 개수에 상관없이 모든 테이블을 truncate하는 것을 코드 형태로 작성된 클래스입니다 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 굳굳! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 항상 추상클래스로 구현 받아왔는데, 인터페이스로 처리하는 것도 좋네요!!