From a2c12127d09f2d457157e00521c564e18b014652 Mon Sep 17 00:00:00 2001 From: minsub Date: Thu, 19 Oct 2023 11:55:20 +0900 Subject: [PATCH] =?UTF-8?q?doc=20:=20Tag=20Entity=20API=20=EB=AA=85?= =?UTF-8?q?=EC=84=B8=EC=84=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/asciidoc/tag.adoc | 86 +++++++++++++++++++ .../tag/controller/TagControllerTest.java | 66 +++++++++++--- 2 files changed, 140 insertions(+), 12 deletions(-) create mode 100644 src/docs/asciidoc/tag.adoc diff --git a/src/docs/asciidoc/tag.adoc b/src/docs/asciidoc/tag.adoc new file mode 100644 index 0000000..eb3dd34 --- /dev/null +++ b/src/docs/asciidoc/tag.adoc @@ -0,0 +1,86 @@ += TAG 차량 특징 카드 API +:doctype: book +:icons: font +:source-highlighter: highlightjs +:toc: left +:toclevels: 3 + +== 차량 특징 카드 조회 +=== 1. 차량에 등록된 차량 특징 카드가 존재하지 않을 경우, 오류를 반환한다 +==== HTTP Request +include::{snippets}/Tag/List/Failure/Case1/http-request.adoc[] + +Path Variable +include::{snippets}/Tag/List/Failure/Case1/path-parameters.adoc[] + +==== HTTP Response +include::{snippets}/Tag/List/Failure/Case1/http-response.adoc[] +include::{snippets}/Tag/List/Failure/Case1/response-fields.adoc[] + +=== 2. 차량에 등록된 차량 특징 카드 조회에 성공한다 +==== HTTP Request +include::{snippets}/Tag/List/Success/http-request.adoc[] + +Path Variable +include::{snippets}/Tag/List/Success/path-parameters.adoc[] + +==== HTTP Response +include::{snippets}/Tag/List/Success/http-response.adoc[] +include::{snippets}/Tag/List/Success/response-fields.adoc[] + +== 차량 특징 카드 삭제 +=== 1. 유효하지 않은 tagId를 입력 받은 경우, 오류를 반환한다 +==== HTTP Request +include::{snippets}/Tag/Delete/Failure/Case1/http-request.adoc[] + +Query String +include::{snippets}/Tag/Delete/Failure/Case1/query-parameters.adoc[] + +Path Variable +include::{snippets}/Tag/Delete/Failure/Case1/path-parameters.adoc[] + +==== HTTP Response +include::{snippets}/Tag/Delete/Failure/Case1/http-response.adoc[] +include::{snippets}/Tag/Delete/Failure/Case1/response-fields.adoc[] + +=== 2. 유효하지 않은 carId를 입력 받은 경우, 오류를 반환한다 +==== HTTP Request +include::{snippets}/Tag/Delete/Failure/Case2/http-request.adoc[] + +Query String +include::{snippets}/Tag/Delete/Failure/Case2/query-parameters.adoc[] + +Path Variable +include::{snippets}/Tag/Delete/Failure/Case2/path-parameters.adoc[] + +==== HTTP Response +include::{snippets}/Tag/Delete/Failure/Case2/http-response.adoc[] +include::{snippets}/Tag/Delete/Failure/Case2/response-fields.adoc[] + +=== 3. Tag와 Car Entity가 서로 연관된 관계가 아닐 경우, 오류를 반환한다 +==== HTTP Request +include::{snippets}/Tag/Delete/Failure/Case3/http-request.adoc[] + +Query String +include::{snippets}/Tag/Delete/Failure/Case3/query-parameters.adoc[] + +Path Variable +include::{snippets}/Tag/Delete/Failure/Case3/path-parameters.adoc[] + +==== HTTP Response +include::{snippets}/Tag/Delete/Failure/Case3/http-response.adoc[] +include::{snippets}/Tag/Delete/Failure/Case3/response-fields.adoc[] + +=== 4. 차량 특징 카드 삭제에 성공한다 +==== HTTP Request +include::{snippets}/Tag/Delete/Success/http-request.adoc[] + +Query String +include::{snippets}/Tag/Delete/Success/query-parameters.adoc[] + +Path Variable +include::{snippets}/Tag/Delete/Success/path-parameters.adoc[] + +==== HTTP Response +include::{snippets}/Tag/Delete/Success/http-response.adoc[] +include::{snippets}/Tag/Delete/Success/response-fields.adoc[] \ No newline at end of file diff --git a/src/test/java/com/example/cargive/tag/controller/TagControllerTest.java b/src/test/java/com/example/cargive/tag/controller/TagControllerTest.java index 25f7dff..d3dbe75 100644 --- a/src/test/java/com/example/cargive/tag/controller/TagControllerTest.java +++ b/src/test/java/com/example/cargive/tag/controller/TagControllerTest.java @@ -63,7 +63,8 @@ public void throwExceptionByEmptyList() throws Exception { responseFields( fieldWithPath("status").type(JsonFieldType.NUMBER).description("HTTP 상태 코드"), fieldWithPath("code").type(JsonFieldType.STRING).description("커스텀 상태 코드"), - fieldWithPath("message").type(JsonFieldType.STRING).description("상태 메시지")) + fieldWithPath("message").type(JsonFieldType.STRING).description("상태 메시지") + ) ) ); @@ -73,7 +74,8 @@ public void throwExceptionByEmptyList() throws Exception { @DisplayName("차량에 등록된 차량 특징 카드 조회에 성공한다") public void successToGetList() throws Exception { // given - List response = new ArrayList<>(); + List response = getResponseList(); + doReturn(response) .when(tagService) .getTagList(anyLong()); @@ -91,7 +93,14 @@ public void successToGetList() throws Exception { "Tag/List/Success", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()), - pathParameters(parameterWithName("carId").description("차량 ID")) + pathParameters(parameterWithName("carId").description("차량 ID")), + responseFields( + fieldWithPath("status").type(JsonFieldType.NUMBER).description("HTTP 상태 코드"), + fieldWithPath("code").type(JsonFieldType.STRING).description("커스텀 상태 코드"), + fieldWithPath("message").type(JsonFieldType.STRING).description("상태 메시지"), + fieldWithPath("result[0].id").type(JsonFieldType.NUMBER).description("차량 특징 카드 Id"), + fieldWithPath("result[0].name").type(JsonFieldType.STRING).description("차량 특징") + ) ) ); } @@ -117,7 +126,7 @@ public void throwExceptionByInvalidTagId() throws Exception { // when MockHttpServletRequestBuilder request = RestDocumentationRequestBuilders .delete(BASE_URL, errorTagId) - .param("carId", String.valueOf(carId)); + .queryParam("carId", String.valueOf(carId)); // then final BaseResponseStatus expectException = BaseResponseStatus.TAG_NOT_FOUND_ERROR; @@ -136,7 +145,12 @@ public void throwExceptionByInvalidTagId() throws Exception { "Tag/Delete/Failure/Case1", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()), - pathParameters(parameterWithName("tagId").description("차량 특징 카드 ID")), + pathParameters( + parameterWithName("tagId").description("차량 특징 카드 ID") + ), + queryParameters( + parameterWithName("carId").description("차량 Id") + ), responseFields( fieldWithPath("status").type(JsonFieldType.NUMBER).description("HTTP 상태 코드"), fieldWithPath("code").type(JsonFieldType.STRING).description("커스텀 상태 코드"), @@ -156,7 +170,7 @@ public void throwExceptionByInvalidCarId() throws Exception { // when MockHttpServletRequestBuilder request = RestDocumentationRequestBuilders .delete(BASE_URL, tagId) - .param("carId", String.valueOf(errorCarId)); + .queryParam("carId", String.valueOf(errorCarId)); // then final BaseResponseStatus expectException = BaseResponseStatus.CAR_NOT_FOUND_ERROR; @@ -175,7 +189,12 @@ public void throwExceptionByInvalidCarId() throws Exception { "Tag/Delete/Failure/Case2", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()), - pathParameters(parameterWithName("tagId").description("차량 특징 카드 ID")), + pathParameters( + parameterWithName("tagId").description("차량 특징 카드 ID") + ), + queryParameters( + parameterWithName("carId").description("차량 Id") + ), responseFields( fieldWithPath("status").type(JsonFieldType.NUMBER).description("HTTP 상태 코드"), fieldWithPath("code").type(JsonFieldType.STRING).description("커스텀 상태 코드"), @@ -195,7 +214,7 @@ public void throwExceptionByInvalidMember() throws Exception { // when MockHttpServletRequestBuilder request = RestDocumentationRequestBuilders .delete(BASE_URL, tagId) - .param("carId", String.valueOf(carId)); + .queryParam("carId", String.valueOf(carId)); // then final BaseResponseStatus expectException = BaseResponseStatus.CAR_NOT_MATCH_ERROR; @@ -214,7 +233,12 @@ public void throwExceptionByInvalidMember() throws Exception { "Tag/Delete/Failure/Case3", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()), - pathParameters(parameterWithName("tagId").description("차량 특징 카드 ID")), + pathParameters( + parameterWithName("tagId").description("차량 특징 카드 ID") + ), + queryParameters( + parameterWithName("carId").description("차량 Id") + ), responseFields( fieldWithPath("status").type(JsonFieldType.NUMBER).description("HTTP 상태 코드"), fieldWithPath("code").type(JsonFieldType.STRING).description("커스텀 상태 코드"), @@ -234,7 +258,7 @@ public void successToDelete() throws Exception { // when MockHttpServletRequestBuilder request = RestDocumentationRequestBuilders .delete(BASE_URL, tagId) - .param("carId", String.valueOf(carId)); + .queryParam("carId", String.valueOf(carId)); // then mockMvc.perform(request) @@ -245,9 +269,27 @@ public void successToDelete() throws Exception { "Tag/Delete/Success", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()), - pathParameters(parameterWithName("tagId").description("차량 특징 카드 ID")) + pathParameters( + parameterWithName("tagId").description("차량 특징 카드 ID") + ), + queryParameters( + parameterWithName("carId").description("차량 Id") + ), + responseFields( + fieldWithPath("status").type(JsonFieldType.NUMBER).description("HTTP 상태 코드"), + fieldWithPath("code").type(JsonFieldType.STRING).description("커스텀 상태 코드"), + fieldWithPath("message").type(JsonFieldType.STRING).description("상태 메시지") + ) ) ); } + } + private List getResponseList() { + List responseList = new ArrayList<>(); + + responseList.add(new TagResponse(1L, "Tag")); + + return responseList; } -} + + } \ No newline at end of file