ysk(0soo)
Lifealong
ysk(0soo)
전체 방문자
오늘
어제
  • 분류 전체보기 (238)
    • Java (50)
      • whiteship-java-study (11)
      • Java (28)
      • time (6)
    • Spring (68)
      • JPA (15)
      • Spring (1)
      • SpringBoot (1)
      • SpringMVC (6)
      • Spring Security (22)
      • Jdbc (1)
      • RestDocs (14)
      • log (6)
    • Kotlin (3)
    • Web (2)
      • nginx (1)
    • Database (14)
      • MySQL (5)
      • PostgreSQL (1)
      • SQL (1)
      • Redis (4)
    • C, C++ (0)
    • Git (1)
    • Docker (2)
    • Cloud (3)
      • AWS (3)
    • 도서, 강의 (0)
      • t5 (0)
    • 기타 (7)
      • 프로그래밍 (1)
    • 끄적끄적 (0)
    • CS (14)
      • 운영체제(OS) (2)
      • 자료구조(Data Structure) (9)
    • 하루한개 (12)
      • 우아한 테크코스-10분테코톡 (12)
    • 스터디 (12)
      • 클린 아키텍처- 로버트마틴 (2)
      • JPA 프로그래밍 스터디 (10)
    • 테스트 (34)
      • JUnit (19)
      • nGrinder (2)
      • JMeter (0)
    • Infra (3)
    • 프로그래머스 백엔드 데브코스 3기 (0)
    • 디자인 패턴 (3)
    • Issue (4)
    • system (1)
      • grafana (0)
      • Prometheus (0)

블로그 메뉴

  • 홈
  • 태그
  • 방명록
  • github

공지사항

인기 글

태그

  • 가상 스레드 예외 핸들링
  • junit5
  • 인가(Authorization) 처리
  • tree
  • nGrinder
  • 동일성
  • java
  • nginx basic auth
  • StructuredConcorrency
  • 구조화된 동시성
  • 가상 스레드
  • AccessDecisionManager
  • querydsl
  • scope value
  • jpa
  • 트랜잭션
  • DataJpaTest
  • UserDetailsService
  • FilterSecurityInterceptor
  • restdocs enum
  • VirtualThread Springboot
  • LocalDateTime
  • mysql
  • 동시성 제어
  • node exporter basic auth
  • 동등성
  • AuthenticationException
  • restdocs custom
  • 정규표현식
  • AccessDecisionVoter 커스텀

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
ysk(0soo)

Lifealong

테스트/JUnit

MockMvc 테스트 body가 '<no character encoding set>' 인경우

2023. 1. 24. 23:42

@WebMvc 테스트 중 Request Body 데이터가 나오지 않는 상황이 발생.

MockHttpServletRequest:
      HTTP Method = POST
      Request URI = /api/v1/items
       Parameters = {_csrf=[89d3f355-ea84-4108-b910-eebcb6795735]}
          Headers = [Content-Type:"application/json", Accept:"application/json", Content-Length:"505"]
             Body = <no character encoding set> // 
    Session Attrs = {}

Handler:
         Type = com.prgrms.bdbks.domain.item.api.ItemController
         Method = com.prgrms.bdbks.domain.item.api.ItemController#createItem(ItemCreateRequest)
Body = <no character encoding set>

RequestBuilder 속성에 characterEncoding(StandardCharsets.UTF_8) 또는 .characterEncoding("utf-8") 를 추가해주면 된다

mockMvc.perform(post(BASE_REQUEST_URI)
                .with(csrf())
                .contentType(MediaType.APPLICATION_JSON)
                .accept(MediaType.APPLICATION_JSON)

                .characterEncoding(StandardCharsets.UTF_8) // here

                .content(objectMapper.writeValueAsString(request)
                )
            ).andDo(print())
            .andExpect(status().isCreated());
저작자표시 비영리 (새창열림)

'테스트 > JUnit' 카테고리의 다른 글

Mockito Verify, Mock Object 검증, 호출 횟수 검증  (0) 2023.01.25
MockMvc 테스트시 201 created URI를 검증하는 방법  (0) 2023.01.24
JUnit5 생성자 주입 방법과 원리  (0) 2022.12.16
Junit5 의존성 주입 에러@Autowired ParameterResolutionException 과 해결방법  (0) 2022.12.16
Junit5 AssertJ List 정렬 테스트 ( Check if list is sorted in junit)  (0) 2022.12.15
    '테스트/JUnit' 카테고리의 다른 글
    • Mockito Verify, Mock Object 검증, 호출 횟수 검증
    • MockMvc 테스트시 201 created URI를 검증하는 방법
    • JUnit5 생성자 주입 방법과 원리
    • Junit5 의존성 주입 에러@Autowired ParameterResolutionException 과 해결방법
    ysk(0soo)
    ysk(0soo)
    백엔드 개발을 좋아합니다. java kotlin spring, infra 에 관심이 많습니다. email : kim206gh@naver.com github : https://github.com/devysk

    티스토리툴바