I have a simple junit test that verifies the response of a servlet endpoint.
Problem: I want to obtain the response as java object Person
, and not as string/json/xml representation.
Is that possible?
@RestController
public class PersonController {
@GetMapping("/person")
public PersonRsp getPerson(int id) {
//...
return rsp;
}
}
@RunWith(SpringRunner.class)
@WebMvcTest(value = PersonController.class)
public class PersonControllerTest {
@Autowired
private MockMvc mvc;
@Test
public void test() {
MvcResult rt = mvc.perform(get("/person")
.param("id", "123")
.andExpect(status().isOk())
.andReturn();
//TODO how to cast the result to (Person) p?
}
}