@Test
@WithMockUser(username = "test@gmail.com", roles = "USER")
@DisplayName("야타 게시글 업데이트")
void updateYata() throws Exception {

    //given
    long yataId = 1L;
    YataDto.Patch patch = createYataPatchDto();

    String json = gson.toJson(patch); //json으로 보낼 patch요청


    Yata expected = YataFactory.createYata();

    YataDto.Response response = createYataResponseDto(expected);

    given(mapper.yataPatchToYata(any())).willReturn(new Yata());
    given(yataService.updateYata(anyLong(), any(), any())).willReturn(new Yata());
    given(mapper.yataToYataResponse(any())).willReturn(response);
    //when

    ResultActions resultActions = mockMvc.perform(
            patch(BASE_URL + "/{yataId}", yataId)
                    .contentType(MediaType.APPLICATION_JSON)
                    .with(csrf()) //csrf토큰 생성
                    .content(json));


    //then
    resultActions.andExpect(status().isOk())
            .andExpect(jsonPath("$.data.title").value(response.getTitle()))
            .andExpect(jsonPath("$.data.specifics").value(response.getSpecifics()))
            .andExpect(jsonPath("$.data.amount").value(response.getAmount()))
            .andExpect(jsonPath("$.data.carModel").value(response.getCarModel()))
            .andDo(print());

    resultActions.andDo(document("yata-update",
            getRequestPreProcessor(),
            getResponsePreProcessor(),
            pathParameters(
                    parameterWithName("yataId").description("야타 ID")
            ),
            requestFields(
                    fieldWithPath("title").type(JsonFieldType.STRING).description("제목"),
                    fieldWithPath("specifics").type(JsonFieldType.STRING).description("특이사항"),
                    fieldWithPath("amount").type(JsonFieldType.NUMBER).description("가격"),
                    fieldWithPath("carModel").type(JsonFieldType.STRING).description("차종"),
                    fieldWithPath("maxPeople").type(JsonFieldType.NUMBER).description("최대인원"),
                    fieldWithPath("maxWaitingTime").type(JsonFieldType.NUMBER).description("최대대기시간"),
                    fieldWithPath("strPoint.longitude").type(JsonFieldType.NUMBER).description("출발지 경도"),
                    fieldWithPath("strPoint.latitude").type(JsonFieldType.NUMBER).description("출발지 위도"),
                    fieldWithPath("strPoint.address").type(JsonFieldType.STRING).description("출발지 주소"),
                    fieldWithPath("destination.longitude").type(JsonFieldType.NUMBER).description("도착지 경도"),
                    fieldWithPath("destination.latitude").type(JsonFieldType.NUMBER).description("도착지 위도"),
                    fieldWithPath("destination.address").type(JsonFieldType.STRING).description("도착지 주소"),
                    fieldWithPath("departureTime").type(JsonFieldType.STRING).description("출발시간"),
                    fieldWithPath("timeOfArrival").type(JsonFieldType.STRING).description("도착시간")),
            responseFields(
                    fieldWithPath("data").type(JsonFieldType.OBJECT).description("야타 게시글 정보"),
                    fieldWithPath("data.yataId").type(JsonFieldType.NUMBER).description("야타 ID"),
                    fieldWithPath("data.departureTime").type(JsonFieldType.STRING).description("출발 시간"),
                    fieldWithPath("data.timeOfArrival").type(JsonFieldType.STRING).description("도착 시간"),
                    fieldWithPath("data.title").type(JsonFieldType.STRING).description("야타 제목"),
                    fieldWithPath("data.specifics").type(JsonFieldType.STRING).description("야타 특이사항"),
                    fieldWithPath("data.maxWaitingTime").type(JsonFieldType.NUMBER).description("최대 대기 시간"),
                    fieldWithPath("data.maxPeople").type(JsonFieldType.NUMBER).description("최대 인원"),
                    fieldWithPath("data.amount").type(JsonFieldType.NUMBER).description("요금"),
                    fieldWithPath("data.carModel").type(JsonFieldType.STRING).description("차량 모델"),
                            fieldWithPath("data.strPoint").type(JsonFieldType.OBJECT).description("출발지"),
                            fieldWithPath("data.strPoint.longitude").type(JsonFieldType.NUMBER).description("출발지 경도"),
                            fieldWithPath("data.strPoint.latitude").type(JsonFieldType.NUMBER).description("출발지 위도"),
                            fieldWithPath("data.strPoint.address").type(JsonFieldType.STRING).description("출발지 주소"),
                            fieldWithPath("data.destination").type(JsonFieldType.OBJECT).description("도착지"),
                            fieldWithPath("data.destination.longitude").type(JsonFieldType.NUMBER).description("도착지 경도"),
                            fieldWithPath("data.destination.latitude").type(JsonFieldType.NUMBER).description("도착지 위도"),
                            fieldWithPath("data.destination.address").type(JsonFieldType.STRING).description("도착지 주소"),
                    fieldWithPath("data.postStatus").type(JsonFieldType.STRING).description("야타 게시글 상태"),
                    fieldWithPath("data.yataStatus").type(JsonFieldType.STRING).description("야타 상태"),
                    fieldWithPath("data.email").type(JsonFieldType.STRING).description("이메일")
            )));
}

 

 

urlTemplate not found. If you are using MockMvc did you use RestDocumentationRequestBuilders to build the request?

 

 

RestDocumentationRequestBuilders.

추가

 

ResultActions resultActions = mockMvc.perform(RestDocumentationRequestBuilders.
        patch(BASE_URL + "/{yataId}", yataId)
                .contentType(MediaType.APPLICATION_JSON)
                .with(csrf()) //csrf토큰 생성
                .content(json));

통과!

복사했습니다!