Я работаю над проектом Spring Boot. Однако, когда используется аннотация @webmvctest , в ObjectMapper нет проблем, но при использовании @autoconfiguremockmvc в ObjectMapper возникает ошибка. В чем проблема?@SpringBootTest
@ExtendWith(SpringExtension.class)
@AutoConfigureMockMvc
class EventControllerTest {
@Autowired MockMvc mockMvc;
@Autowired ObjectMapper objectMapper;
@Test
void createEVent() throws Exception {
Event event = Event.builder()
.id(100)
.name("Spring")
.description("REST API Development with Spring")
.beginEventDateTime(LocalDateTime.of(2021, 10, 30, 12, 00))
.closeEnrollmentDateTime(LocalDateTime.of(2021, 10, 31, 12, 00))
.beginEnrollmentDateTime(LocalDateTime.of(2021, 11, 01, 12, 00))
.endEventDateTime(LocalDateTime.of(2021, 11, 02, 12, 00))
.basePrice(100)
.maxPrice(200)
.limitOfEnrollment(100)
.location("Tokyo")
.free(true)
.offline(false)
.build();
mockMvc.perform(post("/api/event")
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaTypes.HAL_JSON)
.content(objectMapper.writeValueAsString(event)))
.andDo(print())
.andExpect(status().isCreated())
.andExpect(jsonPath("id").exists())
.andExpect(header().exists(HttpHeaders.LOCATION))
.andExpect(header().string(HttpHeaders.CONTENT_TYPE, MediaTypes.HAL_JSON_VALUE))
.andExpect(jsonPath("id").value(Matchers.not(100)))
.andExpect(jsonPath("free").value(Matchers.not(true)));
}
}
Подробнее здесь: https://stackoverflow.com/questions/697 ... -found-ann