Skip to content

Commit

Permalink
docs: ControllerTest 단 rest docs 템플릿 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
wldns2577 committed Oct 18, 2023
1 parent 4bed2f9 commit 5f51cd0
Show file tree
Hide file tree
Showing 12 changed files with 229 additions and 204 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.springframework.restdocs.payload.JsonFieldType;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;

import static com.example.cargive.common.ApiDocumentUtils.getDocumentRequest;
import static com.example.cargive.common.ApiDocumentUtils.getDocumentResponse;
import static org.mockito.Mockito.*;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.*;
Expand Down Expand Up @@ -60,8 +62,8 @@ public void throwExceptionByInvalidQuestionId() throws Exception {
).andDo(
document(
"Answer/Create/Failure/Case1",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
getDocumentRequest(),
getDocumentResponse(),
responseFields(
fieldWithPath("status").type(JsonFieldType.NUMBER).description("HTTP 상태 코드"),
fieldWithPath("code").type(JsonFieldType.STRING).description("커스텀 상태 코드"),
Expand Down Expand Up @@ -92,8 +94,8 @@ public void successCreateAnswer() throws Exception {
).andDo(
document(
"Answer/Create/Success",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint())
getDocumentRequest(),
getDocumentResponse()
)
);
}
Expand Down Expand Up @@ -136,8 +138,8 @@ public void throwExceptionByInvalidAnswerId() throws Exception {
).andDo(
document(
"Answer/Edit/Failure/Case1",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
getDocumentRequest(),
getDocumentResponse(),
responseFields(
fieldWithPath("status").type(JsonFieldType.NUMBER).description("HTTP 상태 코드"),
fieldWithPath("code").type(JsonFieldType.STRING).description("커스텀 상태 코드"),
Expand Down Expand Up @@ -168,8 +170,9 @@ public void successEditAnswerTest() throws Exception {
).andDo(
document(
"Answer/Edit/Success",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()))
getDocumentRequest(),
getDocumentResponse()
)
);
}
}
Expand Down Expand Up @@ -208,8 +211,8 @@ public void throwExceptionByInvalidAnswerId() throws Exception {
).andDo(
document(
"Answer/Delete/Failure/Case1",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
getDocumentRequest(),
getDocumentResponse(),
responseFields(
fieldWithPath("status").type(JsonFieldType.NUMBER).description("HTTP 상태 코드"),
fieldWithPath("code").type(JsonFieldType.STRING).description("커스텀 상태 코드"),
Expand Down Expand Up @@ -237,8 +240,8 @@ public void successDeleteAnswer() throws Exception {
).andDo(
document(
"Answer/Delete/Success",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint())
getDocumentRequest(),
getDocumentResponse()
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.util.List;

import static com.example.cargive.car.fixture.CarFixture.*;
import static com.example.cargive.common.ApiDocumentUtils.getDocumentRequest;
import static com.example.cargive.common.ApiDocumentUtils.getDocumentResponse;
import static org.mockito.Mockito.*;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.*;
Expand Down Expand Up @@ -68,8 +70,8 @@ public void throwExceptionByEmptyList() throws Exception {
).andDo(
document(
"Car/List/Failure/Case1",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
getDocumentRequest(),
getDocumentResponse(),
responseFields(
fieldWithPath("status").type(JsonFieldType.NUMBER).description("HTTP 상태 코드"),
fieldWithPath("code").type(JsonFieldType.STRING).description("커스텀 상태 코드"),
Expand Down Expand Up @@ -102,8 +104,8 @@ public void successGetCarList() throws Exception {
.andDo(
document(
"Car/List/Success",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
getDocumentRequest(),
getDocumentResponse(),
responseFields(
fieldWithPath("status").type(JsonFieldType.NUMBER).description("HTTP 상태 코드"),
fieldWithPath("code").type(JsonFieldType.STRING).description("커스텀 상태 코드"),
Expand Down Expand Up @@ -167,8 +169,8 @@ public void throwExceptionByInvalidMemberId() throws Exception {
).andDo(
document(
"Car/Create/Failure/Case1",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
getDocumentRequest(),
getDocumentResponse(),
responseFields(
fieldWithPath("status").type(JsonFieldType.NUMBER).description("HTTP 상태 코드"),
fieldWithPath("code").type(JsonFieldType.STRING).description("커스텀 상태 코드"),
Expand Down Expand Up @@ -208,8 +210,8 @@ public void successCreateCar() throws Exception {
).andDo(
document(
"Car/Create/Success",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint())
getDocumentRequest(),
getDocumentResponse()
)
);
}
Expand Down Expand Up @@ -265,8 +267,8 @@ public void throwExceptionByInvalidCarId() throws Exception {
).andDo(
document(
"Car/Edit/Failure/Case1",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
getDocumentRequest(),
getDocumentResponse(),
pathParameters(
parameterWithName("carId").description("차량 Id")
),
Expand Down Expand Up @@ -320,8 +322,8 @@ public void throwExceptionByInvalidMemberId() throws Exception {
).andDo(
document(
"Car/Edit/Failure/Case2",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
getDocumentRequest(),
getDocumentResponse(),
pathParameters(
parameterWithName("carId").description("차량 Id")
),
Expand Down Expand Up @@ -375,8 +377,8 @@ public void throwExceptionByInvalidMember() throws Exception {
).andDo(
document(
"Car/Edit/Failure/Case3",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
getDocumentRequest(),
getDocumentResponse(),
pathParameters(
parameterWithName("carId").description("차량 Id")
),
Expand Down Expand Up @@ -424,8 +426,8 @@ public void successEditCar() throws Exception {
).andDo(
document(
"Car/Edit/Success",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
getDocumentRequest(),
getDocumentResponse(),
pathParameters(
parameterWithName("carId").description("차량 Id")
)
Expand Down Expand Up @@ -470,8 +472,8 @@ public void throwExceptionByInvalidCarId() throws Exception {
).andDo(
document(
"Car/Delete/Failure/Case1",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
getDocumentRequest(),
getDocumentResponse(),
pathParameters(
parameterWithName("carId").description("차량 Id")
),
Expand Down Expand Up @@ -511,8 +513,8 @@ public void throwExceptionByInvalidMemberId() throws Exception{
).andDo(
document(
"Car/Delete/Failure/Case2",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
getDocumentRequest(),
getDocumentResponse(),
pathParameters(
parameterWithName("carId").description("차량 Id")
),
Expand Down Expand Up @@ -552,8 +554,8 @@ public void throwExceptionByInvalidMember() throws Exception {
).andDo(
document(
"Car/Delete/Failure/Case3",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
getDocumentRequest(),
getDocumentResponse(),
pathParameters(
parameterWithName("carId").description("차량 Id")
),
Expand Down Expand Up @@ -586,8 +588,8 @@ public void successDeleteCar() throws Exception {
.andDo(
document(
"Car/Delete/Success",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
getDocumentRequest(),
getDocumentResponse(),
pathParameters(
parameterWithName("carId").description("차량 Id")
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.springframework.restdocs.payload.JsonFieldType;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;

import static com.example.cargive.common.ApiDocumentUtils.getDocumentRequest;
import static com.example.cargive.common.ApiDocumentUtils.getDocumentResponse;
import static org.mockito.Mockito.*;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.*;
Expand Down Expand Up @@ -58,8 +60,8 @@ public void throwExceptionByInvalidMemberId() throws Exception {
).andDo(
document(
"FavoriteCar/Create/Failure/Case1",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
getDocumentRequest(),
getDocumentResponse(),
pathParameters(
parameterWithName("carId").description("차량 Id")
),
Expand Down Expand Up @@ -99,8 +101,8 @@ public void throwExceptionByInvalidCarId() throws Exception {
).andDo(
document(
"FavoriteCar/Create/Failure/Case2",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
getDocumentRequest(),
getDocumentResponse(),
pathParameters(
parameterWithName("carId").description("차량 Id")
),
Expand Down Expand Up @@ -140,8 +142,8 @@ public void throwExceptionByMemberValidation() throws Exception {
).andDo(
document(
"FavoriteCar/Create/Failure/Case3",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
getDocumentRequest(),
getDocumentResponse(),
pathParameters(
parameterWithName("carId").description("차량 Id")
),
Expand Down Expand Up @@ -174,8 +176,8 @@ public void successCreateFavoriteCar() throws Exception {
).andDo(
document(
"FavoriteCar/Create/Success",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
getDocumentRequest(),
getDocumentResponse(),
pathParameters(
parameterWithName("carId").description("차량 Id")
)
Expand Down Expand Up @@ -219,8 +221,8 @@ public void throwExceptionByInvalidMemberId() throws Exception {
).andDo(
document(
"FavoriteCar/Delete/Failure/Case1",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
getDocumentRequest(),
getDocumentResponse(),
pathParameters(
parameterWithName("favoriteCarId").description("차량 즐겨찾기 Id")
),
Expand Down Expand Up @@ -260,8 +262,8 @@ public void throwExceptionByInvalidFavoriteCarId() throws Exception {
).andDo(
document(
"FavoriteCar/Delete/Failure/Case2",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
getDocumentRequest(),
getDocumentResponse(),
pathParameters(
parameterWithName("favoriteCarId").description("차량 즐겨찾기 Id")
),
Expand Down Expand Up @@ -301,8 +303,8 @@ public void throwExceptionByMemberValidation() throws Exception {
).andDo(
document(
"FavoriteCar/Delete/Failure/Case3",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
getDocumentRequest(),
getDocumentResponse(),
pathParameters(
parameterWithName("favoriteCarId").description("차량 즐겨찾기 Id")
),
Expand Down Expand Up @@ -334,8 +336,8 @@ public void successDeleteFavoriteCar() throws Exception {
.andDo(
document(
"FavoriteCar/Delete/Success",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
getDocumentRequest(),
getDocumentResponse(),
pathParameters(
parameterWithName("favoriteCarId").description("차량 즐겨찾기 Id")
)
Expand Down
Loading

0 comments on commit 5f51cd0

Please sign in to comment.