요청의 타입을 걸러서 처리하려 할 때

@Controller
@RequestMapping("/hello")
public class SampleController {

	@RequestMapping(value = "/hello", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
	@ResponseBody
	public String hello() {
		return "hello";
	}
}

반대로 요청에서 응답의 타입을 거르고 싶은 경우 accept 헤더를 사용한다.

@RunWith(SpringRunner.class)
@WebMvcTest
public class SampleControllerTest {

	@Autowired
	MockMvc mockMvc;

	@Test
	public void hello() throws Exception {
		mockMvc.perform(get("/hello")
					.contentType(MediaType.APPLICATION_JSON)
					.accept(MediaType.TEXT_PLAIN))
				.andDo(print())
				.andExpect(status().isOk())
				.andExpect(content().string("hello"));
	}
}