ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • ControllerTest - Pageable, SearchDTO
    BackEnd/스프링 2022. 8. 2. 16:21

    응답데이터 

    {
        "content": [
            {
                "id": 1,
                "title": "welcome",
                "content": "hello world",
                "categoryName": "spring",
                "email": "seung90@gmail.com",
                "viewCount": 3
            }
        ],
        "pageable": {
            "sort": {
                "unsorted": true,
                "sorted": false,
                "empty": true
            },
            "pageNumber": 0,
            "pageSize": 20,
            "offset": 0,
            "paged": true,
            "unpaged": false
        },
        "totalPages": 1,
        "totalElements": 1,
        "last": true,
        "numberOfElements": 1,
        "first": true,
        "number": 0,
        "sort": {
            "unsorted": true,
            "sorted": false,
            "empty": true
        },
        "size": 20,
        "empty": false
    }
    @Test
    @DisplayName("게시물 목록 조회")
    @AuthUser(username = "seung90@gmail.com" , password = "q1w2e3r4", role = RoleType.USER)
    public void getList() throws Exception {
        mockMvc.perform(
                        get("/api/boards")
                                .param("page", "0")
                                .param("size", "10")
                                .param("sort", "title,DESC")
                                .param("boardId", "1")
                                .param("title", "welcome")
                                .param("content", "hello world")
                                .param("memberEmail", "seung90@gmail.com")
                                .accept(MediaType.APPLICATION_JSON)
                )
                .andExpect(status().isOk())
                .andExpect(jsonPath("content[0].email").value("seung90@gmail.com"))
                .andDo(restDocs.document(
                        pathParameters(
                                parameterWithName("boardId").description("게시물 번호").optional(),
                                parameterWithName("title").description("제목").optional(),
                                parameterWithName("content").description("내용").optional(),
                                parameterWithName("category").description("카테고리명").optional(),
                                parameterWithName("memberEmail").description("회원 이메일").optional(),
                                parameterWithName("page").description("현재 페이지").optional(),
                                parameterWithName("size").description("게시물 수").optional(),
                                parameterWithName("sort").description("정렬").optional()
                        ),
                        responseHeaders(
                                headerWithName(HttpHeaders.CONTENT_TYPE).description(MediaType.APPLICATION_JSON)
                        ),
                        responseFields(
                                fieldWithPath("content[].id").description("아이디").type(JsonFieldType.NUMBER),
                                fieldWithPath("content[].title").description("타이틀").type(JsonFieldType.STRING),
                                fieldWithPath("content[].content").description("내용").type(JsonFieldType.STRING),
                                fieldWithPath("content[].categoryName").description("카테고리명").type(JsonFieldType.STRING),
                                fieldWithPath("content[].email").description("이메일").type(JsonFieldType.STRING),
                                fieldWithPath("content[].viewCount").description("조회수").type(JsonFieldType.NUMBER),
    
                                fieldWithPath("pageable.sort.unsorted").description("현재 페이지"),
                                fieldWithPath("pageable.sort.sorted").description("게시물 수"),
                                fieldWithPath("pageable.sort.empty").description("정렬"),
    
                                fieldWithPath("sort.unsorted").description("현재 페이지"),
                                fieldWithPath("sort.sorted").description("게시물 수"),
                                fieldWithPath("sort.empty").description("정렬"),
    
                                fieldWithPath("pageable.pageNumber").description("현재페이지"),
                                fieldWithPath("pageable.pageSize").description("페이지수"),
                                fieldWithPath("pageable.offset").description("시작row번호"),
                                fieldWithPath("pageable.paged").description("페이징여부"),
                                fieldWithPath("pageable.unpaged").description("페이징여부"),
    
                                fieldWithPath("numberOfElements").description("현재페이지"),
                                fieldWithPath("totalPages").description("현재페이지"),
                                fieldWithPath("totalElements").description("페이지수"),
                                fieldWithPath("last").description("시작row번호"),
                                fieldWithPath("first").description("페이징여부"),
                                fieldWithPath("number").description("페이징여부"),
                                fieldWithPath("size").description("페이징여부"),
                                fieldWithPath("empty").description("페이징여부")
                        )
                ));
    }
    반응형

    'BackEnd > 스프링' 카테고리의 다른 글

    단위 테스트의 대상  (0) 2022.08.03
    @Profile 대신 @ConditionalOnProperty 을 사용하라  (0) 2022.08.03
    Controller Test - RequestDTO with MultipartFile  (0) 2022.08.01
    @Valid 위치  (0) 2022.07.29
    BDDMokito.given return null  (0) 2022.07.29
Designed by Tistory.