티스토리 뷰

카테고리 없음

[Junit5] MockMvc UTF 8 설정하기

주인장 진빼이

mvc 멤버변수는 MockMvcBuilders를 통해 생성하자.

 

    private MockMvc mvc;
    
    @Autowired
    private WebApplicationContext ctx;

    @BeforeEach
    public void setup() {
        this.mvc = MockMvcBuilders.webAppContextSetup(ctx)
                .addFilters(new CharacterEncodingFilter("UTF-8", true))  // 필터 추가
                .alwaysDo(print())
                .build();
    }
MockHttpServletResponse:
           Status = 200
    Error message = null
          Headers = [Content-Type:"text/plain;charset=UTF-8", Content-Length:"14"]
     Content type = text/plain;charset=UTF-8
             Body = Optional.empty
    Forwarded URL = null
   Redirected URL = null
          Cookies = []

정상적으로 UTF-8을 확인할 수 있다.

댓글
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함