inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

스프링 기반 REST API 개발

스프링 REST Docs 적용

JUnit5에서 prettyPrint() 적용하기

740

강낭콩

작성한 질문수 42

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

spring rest-api java

답변 1

0

백기선

와 좋은 팁 감사합니다!

Spring 시큐리티 관련해서 WebSecurityConfigurationAdapter

0

103

1

junit5 사용하시는 분들

0

118

1

자바 빈 스펙을 준수하는지 체크하는 테스트

0

288

2

REST API 개발 중 비즈니스 로직 적용 부분의 JSON 에러

0

296

1

스프링 부트 3버전에서의 실습

0

216

1

java.lang.AssertionError: Status

0

589

2

spring doc 관련 파일 생성 관련 배포 관련 질문 드립니다.

0

305

1

섹션2 201응답받기 부분 테스트 404에러 질문입니다

0

770

1

강의 자료가 404입니다 확인 부탁 드려요!

0

502

1

연동 DB문의

0

404

1

이벤트 Repository강의 중 Event 클래스에 private Integer Id; 위치 질문

0

551

1

(Mac) postgressql 관련하여 port kill 해도 다시 살아나는 경우

0

402

0

maven으로 생성한 docs파일(index.html)에서의 not found 오류 질문

0

662

1

테스트 오류 질문드립니다.

0

535

1

docs 요청값이 반영이 안되네요... (해결)

-1

412

1

psql 적용 후 에러

0

854

2

mvn package 시 다음과 같은 에러가 나시면

0

794

2

Event에 Account manager를 추가했으면 문서화 필요

0

295

1

2년 훨씬 전 부터 Restlet-> Talend API 로 바뀌었습니다~

1

493

1

asciidoc 추가 스니펫 에러 해결법

0

419

1

_links 는 현재 fieldWithPath 를 해주지 않아도 됩니다.

0

461

3

깃랩 처음 사용자를 위한 index.adoc raw 보는 법

0

354

1

eclipse 쓰시는 분을 위한 maven-resources-plugin 팁

0

360

1

부트 + jupiter 인 경우 설정법

0

364

1