ViewResolver
@WebMvcTest(UserController.class)
public class UserControllerTest {
@Test
void createUser_XML() throws Exception {
String userJson = "{\"username\":\"keesun\",\"password\":1234}";
mockMvc.perform(post("/users/create")
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_XML)
.content(userJson))
.andExpect(status().isOk())
.andExpect(xpath("/User/username").string("keesun"))
.andExpect(xpath("/User/password").string("1234"));
}
}<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.9.6</version>
</dependency>Last updated