[에러]
JUnit Test 하는 과정에서 문서 snippet으로 되는 내용 중 response에 포함된 필드를 설명하는 부분.
responseFields(
List.of(
fieldWithPath("libraryId").type(JsonFieldType.NUMBER).description("소속 도서관 ID"),
fieldWithPath("bookId").type(JsonFieldType.NUMBER).description("검색한 도서 ID"),
fieldWithPath("libraryBookId").type(JsonFieldType.NUMBER).description("도서관에 보관중인 책 ID"),
fieldWithPath("bookTitle").type(JsonFieldType.STRING).description("검색한 도서 이름"),
fieldWithPath("bookAuthor").type(JsonFieldType.STRING).description("검색한 도서 저자"),
fieldWithPath("bookPublisher").type(JsonFieldType.STRING).description("검색한 도서 출판사"),
fieldWithPath("bookStatus").type(JsonFieldType.STRING).description("검색한 도서의 대여 가능 여부"),
fieldWithPath("url").type(JsonFieldType.STRING).description("url")
)
)
위의 코드 부분에서 아래와 같은 에러가 발생했다.
메세지 내용을 보면 페이로드의 "pageinfo" 부분이 문서화 되지 않았다 라고 나온다.
만일 JUnit Test 코드를 작성하는 대상 메서드가 반환하는 response가 pageinfo를 포함하는 경우라면,
대상 메서드가 실제로 반환하는 response의 모든 필드를 설명하는 responseFields() 메서드에서
실제 모든 필드를 언급해주어야 한다. 하지만 기존의 Test 코드에서는 pageinfo 부분이 누락되어 있었다.
[원인]
실제 메서드가 반환하는 결과 데이터를 포함하는 ResultActions 객체에 사용하는 메서드 중
.andDo(document()) 메서드 안에서 응답 데이터 안의 모든 필드를 설명하는
responseFields() 메서드에서 실제 response에 있는 "pageinfo" 필드에 대한 설명을 누락함.
[해결]
fieldWithPath() 메서드로 pageinfo 필드에 대한 설명을 추가.
responseFields(
List.of(
fieldWithPath("data[].libraryId").type(JsonFieldType.NUMBER).description("소속 도서관 ID"),
fieldWithPath("data[].bookId").type(JsonFieldType.NUMBER).description("검색한 도서 ID"),
fieldWithPath("data[].libraryBookId").type(JsonFieldType.NUMBER).description("도서관에 보관중인 책 ID"),
fieldWithPath("data[].bookTitle").type(JsonFieldType.STRING).description("검색한 도서 이름"),
fieldWithPath("data[].bookAuthor").type(JsonFieldType.STRING).description("검색한 도서 저자"),
fieldWithPath("data[].bookPublisher").type(JsonFieldType.STRING).description("검색한 도서 출판사"),
fieldWithPath("data[].bookStatus").type(JsonFieldType.STRING).description("검색한 도서의 대여 가능 여부"),
fieldWithPath("data[].url").type(JsonFieldType.STRING).description("url"),
fieldWithPath("pageinfo").type(JsonFieldType.OBJECT).description("페이지 정보"),
fieldWithPath("pageinfo.page").description("리스트의 현재 페이지"),
fieldWithPath("pageinfo.size").description("페이지당 최대 표시 수"),
fieldWithPath("pageinfo.totalElements").description("모든 페이지의 총 표시 수"),
fieldWithPath("pageinfo.totalPages").description("총 페이지 수 ")
)
)
'마주쳤던 이슈 기록' 카테고리의 다른 글
#10. Docker - java.net.UnknownHostException: mysql (0) | 2023.06.01 |
---|---|
#9. Docker build - error from sender: context canceled (0) | 2023.05.29 |
#7. 로그인 이후 response Header에 JWT 미전달 (0) | 2023.05.18 |
#6. 유저의 행동 횟수 조건 reset = Spring Data JPA 자동메서드 (0) | 2023.05.11 |
#5 Mapper: Dto -> Entity 변환 시 Null 에러 (0) | 2023.05.09 |