작성
·
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을 원하는 문자로 바꿀 수 있습니다.