|
24 | 24 | import org.springframework.data.domain.Pageable; |
25 | 25 | import org.springframework.http.HttpStatus; |
26 | 26 | import org.springframework.http.ResponseEntity; |
| 27 | +import org.springframework.web.client.ResourceAccessException; |
27 | 28 | import org.springframework.web.client.RestTemplate; |
28 | 29 |
|
29 | 30 | import com.gamzabat.algohub.common.DateFormatUtil; |
@@ -272,6 +273,29 @@ void createProblemFailed_6() { |
272 | 273 | .hasFieldOrPropertyWithValue("error", "solved.ac API로부터 예상치 못한 응답을 받았습니다."); |
273 | 274 | } |
274 | 275 |
|
| 276 | + @Test |
| 277 | + @DisplayName("문제 생성 실패 : solved.ac API 타임아웃 발생") |
| 278 | + void createProblemFailed_solvedAcApiTimeout() { |
| 279 | + // given |
| 280 | + CreateProblemRequest request = CreateProblemRequest.builder() |
| 281 | + .link("https://www.acmicpc.net/problem/00") |
| 282 | + .startDate(LocalDate.now().minusDays(7)) |
| 283 | + .endDate(LocalDate.now()) |
| 284 | + .build(); |
| 285 | + |
| 286 | + when(groupRepository.findById(10L)).thenReturn(Optional.of(group)); |
| 287 | + when(groupMemberRepository.findByUserAndStudyGroup(user, group)).thenReturn(Optional.of(groupMember1)); |
| 288 | + |
| 289 | + when(restTemplate.getForEntity(anyString(), eq(String.class))) |
| 290 | + .thenThrow(new ResourceAccessException("I/O error: Read timed out")); |
| 291 | + |
| 292 | + // when, then |
| 293 | + assertThatThrownBy(() -> problemService.createProblem(user, 10L, request)) |
| 294 | + .isInstanceOf(SolvedAcApiErrorException.class) |
| 295 | + .hasFieldOrPropertyWithValue("code", HttpStatus.GATEWAY_TIMEOUT.value()) |
| 296 | + .hasFieldOrPropertyWithValue("error", "solved.ac API 응답이 지연되거나 연결에 실패했습니다. 잠시 후 다시 시도해주세요."); |
| 297 | + } |
| 298 | + |
275 | 299 | @Test |
276 | 300 | @DisplayName("문제 정보 수정 성공") |
277 | 301 | void editProblem() { |
|
0 commit comments