MockMvc 의 result 를 받아서 처리

.perform()에 .andReturn(); 를 추가하고  MvcResult 로 받음

 

MvcResult result = 
this.mockMvc.perform(
post("/users/regist")
.param("name", "Joe")
.param("age", "56")
.andDo(print())
.andExpect(status().isOk())
.andReturn();
String content = result.getResponse().getContentAsString();

ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally
UserRegistResult user = mapper.readValue(content, UserRegistResult.class);

System.err.println("JSon Result=" + mapper.defaultPrettyPrintingWriter().writeValueAsString(user));

assertTrue(user.getResult().equals("ok"));