강의

멘토링

로드맵

Inflearn brand logo image

인프런 커뮤니티 질문&답변

강낭콩님의 프로필 이미지
강낭콩

작성한 질문수

스프링 기반 REST API 개발

스프링 REST Docs 적용

JUnit5에서 prettyPrint() 적용하기

작성

·

696

3

@ExtendWith({RestDocumentationExtension.class, SpringExtension.class})
@SpringBootTest
class EventControllerTest {

private MockMvc mockMvc;

@Autowired
private ObjectMapper objectMapper;

@Autowired
private WebApplicationContext context;

@Autowired
private EventRepository eventRepository;

@BeforeEach
void init(RestDocumentationContextProvider restDocumentation) {
this.mockMvc = MockMvcBuilders
.webAppContextSetup(this.context)
.addFilters(new CharacterEncodingFilter("UTF-8", true))
.apply(documentationConfiguration(restDocumentation)
.operationPreprocessors()
.withRequestDefaults(modifyUris().host("yoonjoy.me").removePort(), prettyPrint())
.withResponseDefaults(modifyUris().host("yoonjoy.me").removePort(), prettyPrint()))
.alwaysDo(print())
.build();
}


추가로 addFilters에 UTF-8 설정을 통해 responseBody에서 한글이 깨지는 것을 막고,

modifyUris을 통해 호스트 url localhost을 원하는 문자로 바꿀 수 있습니다.

답변 1

0

백기선님의 프로필 이미지
백기선
지식공유자

와 좋은 팁 감사합니다!

강낭콩님의 프로필 이미지
강낭콩

작성한 질문수

질문하기