Метод контроллера не проходит интеграционный тест не могу понять где ошибся в написание теста
class ResourceAnswerControllerTest extends BaseTest {
private final String username = "[email protected]";
private final String password = "password";
@Autowired
private MockMvc mockMvc;
@MockBean
AnswerDtoService answerDtoService;
@Test
@SneakyThrows
@DataSet(value ={"answer_controller.yml"},cleanBefore = true, cleanAfter = true)
void getAllAnswer() throws Exception {
String token = getToken(username,password);
this.mockMvc.perform(get("api/user/question/{questionId}/answer").header("Authorization", "Bearer " + token)).andDo(print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.question_id", equalTo(1)))
.andExpect(jsonPath("$.user_id", equalTo(1)));
verify(answerDtoService, times(1)).getAllAnswersDtoByQuestionId(1L,1L);
}
}
@RestController
@RequestMapping("api/user/question/{questionId}/answer")
public class ResourceAnswerController {
private final AnswerDtoService answerDtoService;
private final QuestionService questionService;
public ResourceAnswerController(AnswerDtoService answerDtoService, QuestionService questionService) {
this.answerDtoService = answerDtoService;
this.questionService = questionService;
}
@Operation(
summary = "Получение списка ответов",
description = "Получение списка DTO ответов по уникальному идентификатору (Id) вопроса"
)
@ApiResponses({
@ApiResponse(responseCode = "200",
description = "Запрос успешно выполнен"),
@ApiResponse(responseCode = "400",
description = "Список ответов по данному уникальному идентификатору (Id) не найден")
})
@GetMapping
public ResponseEntity<List<AnswerDto>> getAllAnswer(@PathVariable("questionId") Long questionId, @AuthenticationPrincipal User user) {
if (questionService.existsById(questionId)) {
return new ResponseEntity<>(answerDtoService.getAllAnswersDtoByQuestionId(questionId, user.getId()), HttpStatus.OK);
} else {
throw new ResponseStatusException(HttpStatus.NOT_FOUND);
}
}
}
DatSet
question:
- id: 1
description: "description"
is_deleted: false
last_redaction_date: "[DAY,NOW]"
persist_date: "[DAY,NOW]"
title: "title"
user_id: 1
answer:
- id: 1
date_accept_time: "[DAY,NOW]"
html_body: "htmlBody"
is_deleted: false
is_deleted_by_moderator: false
is_helpful: false
persist_date: "[DAY,NOW]"
update_date: "[DAY,NOW]"
question_id: 1
user_id: 1
user_entity:
- id: 1
about: "about"
city: "city"
email: "[email protected]"
full_name: "full_name"
image_link: "image_link"
is_deleted: false
is_enabled: true
last_redaction_date: "[DAY,NOW]"
link_github: "link_github"
link_site: "link_site"
link_vk: "link_vk"
nickname: "nickname"
password: "password"
persist_date: "[DAY,NOW]"
role_id: 1
role:
- id: 1
name: "ROLE_USER
"
