No meu caso, fiz em Inglês:
- AppointmentScheduleData -> DadosAgendamentoConsulta
- AppointmentDetailsData -> DadosDetalhamentoConsulta
Erros:
Could not autowire. No beans of 'JacksonTester<AppointmentScheduleData>' type found.
Could not autowire. No beans of 'JacksonTester<AppointmentDetailsData>' type found.
Código:
@SpringBootTest
@AutoConfigureMockMvc
class AppointmentControllerTest {
@Autowired
private MockMvc mvc;
@Autowired
private JacksonTester<AppointmentScheduleData> jsonEntry;
@Autowired
private JacksonTester<AppointmentDetailsData> jsonReturn;
private String url = "/appointment";
@Test
@WithMockUser
@DisplayName("Devolve codigo 400 quando ocorre informacoes invalidas")
void schedule_scene1() throws Exception {
var response = mvc.perform(post(url))
.andReturn().getResponse();
assertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST.value());
}
@Test
@WithMockUser
@DisplayName("Devolve codigo 200 quando ocorre informacoes validas")
void schedule_scene2() throws Exception {
var date = LocalDateTime.now().plusHours(1);
var specialty = Specialty.ORTOPEDIA;
var response = mvc.perform(
post(urlTemplate)
.contentType(MediaType.APPLICATION_JSON)
.content(jsonEntry.write(
new AppointmentScheduleData(2l,5l, date, specialty )
).getJson())
)
.andReturn().getResponse();
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
var jsonWaited = jsonReturn.write(
new AppointmentDetailsData(null, 2l, 5l, date)
).getJson();
assertThat(response.getContentAsString()).isEqualTo(jsonWaited);
}