728x90
Accept header값에 따라 응답이 달라짐 > 해당하는 view에 맞게 Return
xml로 응답을 받고 싶은 경우 > xpath사용
예시
@RunWith(SpringRunner.class)
@WebMvcTest(UserController.class)
public class UserControllerTest {
@Autowired
MockMvc mockMvc;
@Test
public void createUser_XML() throws Exception {
String userJson = "{\"username\":\"sangguk\", \"password\":\"1234\"}";
mockMvc.perform(post("/users/create")
.contentType(MediaType.APPLICATION_JSON_UTF8)
.accept(MediaType.APPLICATION_XML)
.content(userJson))
.andExpect(status().isOk())
.andExpect(xpath("/User/username").string("sangguk"))
.andExpect(xpath("/User/password").string("1234"));
}
}
728x90
'Spring Boot' 카테고리의 다른 글
Thymeleaf (0) | 2022.02.28 |
---|---|
Spring 정적 리소스 맵핑 (0) | 2022.02.27 |
HttpMessageConverters (0) | 2022.02.20 |
Spring boot 단위 테스트 (0) | 2022.02.20 |
Spring boot 통합 Test (0) | 2022.02.20 |
댓글