fix: 유니크 제약 테스트를 실제로 제약을 검증하도록 보강
연번+기관명 유니크 테스트가 단일 삽입 후 건수만 확인해 uq_organization_no_name 제약이 삭제돼도 통과하는 문제를 수정. 동일 조합 중복 삽입 시 예외 발생과, 동일 연번(008 경찰청/경찰청_치안정책연구소)의 다른 기관명은 정상 저장되는 두 경우를 모두 검증하도록 변경. application.yml의 hikari.schema 설정에는 Flyway 스키마 지정과 별개로 필요한 이유를 주석으로 명시.
@312293c6ae63faa89f979b2035d0d634ea0c0ddd
--- src/main/resources/application.yml
+++ src/main/resources/application.yml
... | ... | @@ -6,6 +6,9 @@ |
| 6 | 6 |
username: ${DB_USERNAME}
|
| 7 | 7 |
password: ${DB_PASSWORD}
|
| 8 | 8 |
hikari: |
| 9 |
+ # flyway.schemas는 Flyway 전용 커넥션에만 적용되므로, 애플리케이션이 실제 사용하는 |
|
| 10 |
+ # HikariCP 커넥션 풀의 search_path는 이 설정으로 별도 지정해야 한다. |
|
| 11 |
+ # 없으면 커넥션이 public 스키마를 기본으로 조회해 "relation organization does not exist" 오류가 난다. |
|
| 9 | 12 |
schema: itnhub |
| 10 | 13 |
flyway: |
| 11 | 14 |
enabled: true |
--- src/test/java/kr/itn/itnhub/SchemaMigrationTest.java
+++ src/test/java/kr/itn/itnhub/SchemaMigrationTest.java
... | ... | @@ -4,6 +4,7 @@ |
| 4 | 4 |
import org.springframework.beans.factory.annotation.Autowired; |
| 5 | 5 |
import org.springframework.boot.test.context.SpringBootTest; |
| 6 | 6 |
import org.springframework.boot.testcontainers.service.connection.ServiceConnection; |
| 7 |
+import org.springframework.dao.DataIntegrityViolationException; |
|
| 7 | 8 |
import org.springframework.jdbc.core.JdbcTemplate; |
| 8 | 9 |
import org.springframework.test.context.DynamicPropertyRegistry; |
| 9 | 10 |
import org.springframework.test.context.DynamicPropertySource; |
... | ... | @@ -12,6 +13,7 @@ |
| 12 | 13 |
import org.testcontainers.junit.jupiter.Testcontainers; |
| 13 | 14 |
|
| 14 | 15 |
import static org.assertj.core.api.Assertions.assertThat; |
| 16 |
+import static org.assertj.core.api.Assertions.assertThatThrownBy; |
|
| 15 | 17 |
|
| 16 | 18 |
@SpringBootTest |
| 17 | 19 |
@Testcontainers |
... | ... | @@ -48,8 +50,18 @@ |
| 48 | 50 |
jdbc.update("insert into organization (org_no, org_name, channel_slug) "
|
| 49 | 51 |
+ "values ('008', '경찰청', '008')");
|
| 50 | 52 |
|
| 53 |
+ // 같은 (org_no, org_name) 조합의 중복 삽입은 제약 위반으로 실패해야 한다. |
|
| 54 |
+ assertThatThrownBy(() -> jdbc.update( |
|
| 55 |
+ "insert into organization (org_no, org_name, channel_slug) " |
|
| 56 |
+ + "values ('008', '경찰청', '008-dup')"))
|
|
| 57 |
+ .isInstanceOf(DataIntegrityViolationException.class); |
|
| 58 |
+ |
|
| 59 |
+ // org_no는 같지만 org_name이 다르면(경찰청_치안정책연구소) 정상적으로 저장되어야 한다. |
|
| 60 |
+ jdbc.update("insert into organization (org_no, org_name, channel_slug) "
|
|
| 61 |
+ + "values ('008', '경찰청_치안정책연구소', '008-2')");
|
|
| 62 |
+ |
|
| 51 | 63 |
assertThat(jdbc.queryForObject( |
| 52 | 64 |
"select count(*) from organization where org_no = '008'", Integer.class)) |
| 53 |
- .isEqualTo(1); |
|
| 65 |
+ .isEqualTo(2); |
|
| 54 | 66 |
} |
| 55 | 67 |
} |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?