Я делаю яички из моего Rest API, но я не могу проверить «вставку» контроллера.
Мой контроллер
@PostMapping(value = ["/api/clients/lp"])
override fun insert(@Valid @RequestBody model: LegalPersonModel): ResponseEntity<Any> {
service.insert(service.modelToEntity(model))
return ResponseEntity.ok().body(HttpStatus.CREATED)
}
Мой тест
val lp = LegalPerson(1L, 1L, true, "Test Fantasy", "Test LTDA",
"test@com", "40.492.967/0001-52", "Test S", "Test M",
LocalDate.of(2017, 10, 21), 1L, listOf(1L, 22L))
@Test
fun insert() {
Mockito.doReturn(lp).`when`(service)!!.insert(lp)
mockMvc?.perform(MockMvcRequestBuilders.post("/api/clients/lp")
.contentType(MediaType.APPLICATION_JSON_UTF8)
.contentType(ObjectMapper().registerModule(JavaTimeModule()).let {
it.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
it.writeValueAsString(lp)
}))
?.andExpect(MockMvcResultMatchers.status().isCreated)
?.andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
}
Ошибка:
org.springframework.http.InvalidMediaTypeException: Invalid mime type "{"id":1,"companyId":1,"active":true,"tradeName":"Test Fantasy","companyName":"Test LTDA","email":"test@com","cnpj":"40.492.967/0001-52","stateRegistration":"Test S","municipalRegistration":"Test M","openingDate":"2017-10-21","address":1,"phones":[1,22]}": Invalid token character '{' in token "{"id":1,"companyId":1,"active":true,"tradeName":"Test Fantasy","companyName":"Test LTDA","email":"test@com","cnpj":"40.492.967"