|
5 | 5 | import static org.mockito.ArgumentMatchers.any; |
6 | 6 | import static org.mockito.Mockito.when; |
7 | 7 |
|
| 8 | +import com.mongodb.DuplicateKeyException; |
8 | 9 | import io.ejangs.docsa.domain.branch.dao.mysql.BranchRepository; |
9 | 10 | import io.ejangs.docsa.domain.branch.entity.Branch; |
10 | 11 | import io.ejangs.docsa.domain.commit.dao.mysql.CommitRepository; |
|
34 | 35 | import org.junit.jupiter.api.Test; |
35 | 36 | import org.springframework.beans.factory.annotation.Autowired; |
36 | 37 | import org.springframework.boot.test.context.SpringBootTest; |
| 38 | +import org.springframework.dao.DataAccessException; |
| 39 | +import org.springframework.dao.RecoverableDataAccessException; |
37 | 40 | import org.springframework.test.context.ActiveProfiles; |
38 | 41 | import org.springframework.test.context.bean.override.mockito.MockitoBean; |
39 | 42 | import org.springframework.transaction.annotation.Propagation; |
@@ -62,9 +65,6 @@ class SaveServiceIntegrationTest { |
62 | 65 | @Autowired |
63 | 66 | private CommitRepository commitRepository; |
64 | 67 |
|
65 | | - @Autowired |
66 | | - private EntityManager em; |
67 | | - |
68 | 68 | @MockitoBean |
69 | 69 | private SaveContentRepository saveContentRepository; |
70 | 70 |
|
@@ -123,15 +123,12 @@ void updateSave_fails_whenMongoSaveFails_thenMysqlDeleted() throws Exception { |
123 | 123 | Optional.of(saveContent)); |
124 | 124 |
|
125 | 125 | when(saveContentRepository.save(any())) |
126 | | - .thenThrow(new CustomException(DatabaseErrorCode.DATABASE_ERROR)); |
| 126 | + .thenThrow(new RecoverableDataAccessException("mongo write failed")); |
127 | 127 |
|
128 | 128 | assertThatThrownBy(() -> saveService.updateSave(dto, request)) |
129 | 129 | .isInstanceOf(CustomException.class) |
130 | 130 | .hasMessageContaining(DatabaseErrorCode.DATABASE_ERROR.getMessage()); |
131 | 131 |
|
132 | | - // then |
133 | | - em.clear(); |
134 | | - |
135 | 132 | Save after = saveRepository.findById(save.getId()).orElse(null); |
136 | 133 | assertThat(after).isNotNull(); |
137 | 134 | assertThat(after.getUpdatedAt()).isEqualTo(beforeUpdatedAt); |
|
0 commit comments