#13 spring db: test - detach test db & rollback
This commit is contained in:
@@ -5,28 +5,52 @@ import hello.itemservice.repository.ItemSearchCond;
|
||||
import hello.itemservice.repository.ItemUpdateDto;
|
||||
import hello.itemservice.repository.memory.MemoryItemRepository;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.Commit;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.support.DefaultTransactionDefinition;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@Transactional
|
||||
@SpringBootTest
|
||||
class ItemRepositoryTest {
|
||||
|
||||
@Autowired
|
||||
ItemRepository itemRepository;
|
||||
|
||||
// @Autowired
|
||||
// PlatformTransactionManager transactionManager;
|
||||
//
|
||||
// TransactionStatus status;
|
||||
|
||||
// @BeforeEach
|
||||
// void beforeEach() {
|
||||
// // 트랜잭션 시작
|
||||
// status = transactionManager.getTransaction(new DefaultTransactionDefinition());
|
||||
// }
|
||||
|
||||
@AfterEach
|
||||
void afterEach() {
|
||||
//MemoryItemRepository 의 경우 제한적으로 사용
|
||||
if (itemRepository instanceof MemoryItemRepository) {
|
||||
((MemoryItemRepository) itemRepository).clearStore();
|
||||
}
|
||||
|
||||
// 트랜잭션 롤백
|
||||
// transactionManager.rollback(status);
|
||||
}
|
||||
|
||||
// @Commit
|
||||
// @Rollback(value = false)
|
||||
@Test
|
||||
void save() {
|
||||
//given
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
spring.profiles.active=test
|
||||
|
||||
spring.datasource.url=jdbc:h2:tcp://localhost/~/testcase
|
||||
spring.datasource.username=sa
|
||||
|
||||
#jdbcTemplate sql log
|
||||
logging.level.org.springframework.jdbc=debug
|
||||
Reference in New Issue
Block a user