From 4736670ba14775b062279df9c3c9f3ebcdc144a3 Mon Sep 17 00:00:00 2001 From: kho903 Date: Mon, 14 Feb 2022 01:38:43 +0900 Subject: [PATCH] refactor: extract json file from test content [#351] --- .../com/bancow/bancowback/TestSupport.java | 4 +- .../faq/controller/FaqControllerTest.java | 38 +++++------------ .../controller/FarmQnaControllerTest.java | 11 +---- .../controller/NoticeControllerTest.java | 42 ++++++------------- .../qna/controller/QnaControllerTest.java | 11 +---- .../controller/ManagerControllerTest.java | 26 ++---------- .../chart/controller/ChartControllerTest.java | 1 - .../src/test/resources/json/faq/addFaq.json | 6 +++ .../resources/json/faq/deleteFaqList.json | 3 ++ .../test/resources/json/faq/updateFaq.json | 7 ++++ .../resources/json/farmQna/addFarmQna.json | 10 +++++ .../json/manager/changePassword.json | 4 ++ .../resources/json/manager/findManager.json | 5 +++ .../test/resources/json/manager/login.json | 5 +++ .../json/manager/registerManger.json | 6 +++ .../test/resources/json/notice/addNotice.json | 6 +++ .../json/notice/deleteNoticeList.json | 3 ++ .../resources/json/notice/updateNotice.json | 7 ++++ .../src/test/resources/json/qna/addQna.json | 8 ++++ 19 files changed, 101 insertions(+), 102 deletions(-) create mode 100644 spring/src/test/resources/json/faq/addFaq.json create mode 100644 spring/src/test/resources/json/faq/deleteFaqList.json create mode 100644 spring/src/test/resources/json/faq/updateFaq.json create mode 100644 spring/src/test/resources/json/farmQna/addFarmQna.json create mode 100644 spring/src/test/resources/json/manager/changePassword.json create mode 100644 spring/src/test/resources/json/manager/findManager.json create mode 100644 spring/src/test/resources/json/manager/login.json create mode 100644 spring/src/test/resources/json/manager/registerManger.json create mode 100644 spring/src/test/resources/json/notice/addNotice.json create mode 100644 spring/src/test/resources/json/notice/deleteNoticeList.json create mode 100644 spring/src/test/resources/json/notice/updateNotice.json create mode 100644 spring/src/test/resources/json/qna/addQna.json diff --git a/spring/src/test/java/com/bancow/bancowback/TestSupport.java b/spring/src/test/java/com/bancow/bancowback/TestSupport.java index c064f7e3..d6e86cd1 100644 --- a/spring/src/test/java/com/bancow/bancowback/TestSupport.java +++ b/spring/src/test/java/com/bancow/bancowback/TestSupport.java @@ -1,8 +1,8 @@ package com.bancow.bancowback; -import io.micrometer.core.instrument.util.IOUtils; import java.io.IOException; import java.nio.charset.StandardCharsets; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; @@ -24,6 +24,8 @@ import com.bancow.bancowback.domain.manager.repository.ManagerRepository; import com.bancow.bancowback.domain.manager.service.ManagerService; +import io.micrometer.core.instrument.util.IOUtils; + @SpringBootTest @AutoConfigureMockMvc diff --git a/spring/src/test/java/com/bancow/bancowback/domain/main/faq/controller/FaqControllerTest.java b/spring/src/test/java/com/bancow/bancowback/domain/main/faq/controller/FaqControllerTest.java index 60b4a1d2..d3964df7 100644 --- a/spring/src/test/java/com/bancow/bancowback/domain/main/faq/controller/FaqControllerTest.java +++ b/spring/src/test/java/com/bancow/bancowback/domain/main/faq/controller/FaqControllerTest.java @@ -213,14 +213,7 @@ void addFaq() throws Exception { post("/api/faq/add") .header("TOKEN", token.getToken()) .contentType(MediaType.APPLICATION_JSON) - .content( - "{" - + " \"faq_category\": \"AUCTION\",\n" - + " \"title\": \"FAQ 제목입니다..\",\n" - + " \"message\": \"FAQ 내용입니다.\",\n" - + " \"status\": false\n" - + "}" - ) + .content(readJson("json/faq/addFaq.json")) .accept(MediaType.APPLICATION_JSON) ) .andExpect(status().isOk()) @@ -282,14 +275,10 @@ void deleteFaqList() throws Exception { Manager manager = adminManagerLogin(); Token token = tokenRepository.findByManager(manager).get(); mockMvc.perform( - delete("/api/faq/delete") - .header("TOKEN", token.getToken()) - .contentType(MediaType.APPLICATION_JSON) - .content( - "{" - + " \"idList\": [1]\n" - + "}" - ) + delete("/api/faq/delete") + .header("TOKEN", token.getToken()) + .contentType(MediaType.APPLICATION_JSON) + .content(readJson("json/faq/deleteFaqList.json")) .accept(MediaType.APPLICATION_JSON) ) .andExpect(status().isOk()) @@ -299,7 +288,7 @@ void deleteFaqList() throws Exception { headerWithName("TOKEN").description("해당 로그인 유저의 토큰값") ), requestFields( - fieldWithPath("idList").description("삭제할 항목") + fieldWithPath("id_list").description("삭제할 항목") ), responseFields( fieldWithPath("data").description("결과 데이터"), @@ -320,17 +309,10 @@ void updateFaq() throws Exception { Token token = tokenRepository.findByManager(manager).get(); mockMvc.perform( - patch("/api/faq/update", 1) - .header("TOKEN", token.getToken()) - .contentType(MediaType.APPLICATION_JSON) - .content( - "{" - + " \"id\": \"1\",\n" - + " \"faq_category\": \"AUCTION\",\n" - + " \"title\": \"수정된 FAQ 제목입니다.\",\n" - + " \"message\": \"수정된 FAQ 내용입니다.\",\n" - + " \"status\": false\n" - + "}") + patch("/api/faq/update", 1) + .header("TOKEN", token.getToken()) + .contentType(MediaType.APPLICATION_JSON) + .content(readJson("json/faq/updateFaq.json")) .accept(MediaType.APPLICATION_JSON) ) .andExpect(status().isOk()) diff --git a/spring/src/test/java/com/bancow/bancowback/domain/main/farmqna/controller/FarmQnaControllerTest.java b/spring/src/test/java/com/bancow/bancowback/domain/main/farmqna/controller/FarmQnaControllerTest.java index cc6bc16d..af1dd4c6 100644 --- a/spring/src/test/java/com/bancow/bancowback/domain/main/farmqna/controller/FarmQnaControllerTest.java +++ b/spring/src/test/java/com/bancow/bancowback/domain/main/farmqna/controller/FarmQnaControllerTest.java @@ -27,16 +27,7 @@ void addFarmQna() throws Exception { mockMvc.perform( post("/api/farmqna/add") .contentType(MediaType.APPLICATION_JSON) - .content("{\n" - + " \"farm_qna_name\": \"김철수\",\n" - + " \"phone_number\": \"010-3991-7102\",\n" - + " \"email\": \"gmldnr2222@naver.com\",\n" - + " \"farm_name\": \"속초농장\",\n" - + " \"farm_address\": \"강원도 속초시 교동 밤골3길\",\n" - + " \"cow_num\": \"100\",\n" - + " \"feed_name\": \"먹이이름입니다.\",\n" - + " \"available_date\": \"2022-02-20\"\n" - + "}") + .content(readJson("json/farmQna/addFarmQna.json")) .accept(MediaType.APPLICATION_JSON) ) .andExpect(status().isOk()) diff --git a/spring/src/test/java/com/bancow/bancowback/domain/main/notice/controller/NoticeControllerTest.java b/spring/src/test/java/com/bancow/bancowback/domain/main/notice/controller/NoticeControllerTest.java index 68fc80b2..1dd59296 100644 --- a/spring/src/test/java/com/bancow/bancowback/domain/main/notice/controller/NoticeControllerTest.java +++ b/spring/src/test/java/com/bancow/bancowback/domain/main/notice/controller/NoticeControllerTest.java @@ -213,14 +213,7 @@ void addNotice() throws Exception { post("/api/notice/add") .header("TOKEN", token.getToken()) .contentType(MediaType.APPLICATION_JSON) - .content( - "{" - + " \"notice_category\": \"INSPECTION\",\n" - + " \"title\": \"공지사항 제목입니다..\",\n" - + " \"message\": \"공지사항 내용입니다.\",\n" - + " \"status\": false\n" - + "}" - ) + .content(readJson("json/notice/addNotice.json")) .accept(MediaType.APPLICATION_JSON) ) .andExpect(status().isOk()) @@ -282,14 +275,10 @@ void deleteNoticeList() throws Exception { Manager manager = adminManagerLogin(); Token token = tokenRepository.findByManager(manager).get(); mockMvc.perform( - delete("/api/notice/delete") - .header("TOKEN", token.getToken()) - .contentType(MediaType.APPLICATION_JSON) - .content( - "{" - + " \"idList\": [1]\n" - + "}" - ) + delete("/api/notice/delete") + .header("TOKEN", token.getToken()) + .contentType(MediaType.APPLICATION_JSON) + .content(readJson("json/notice/deleteNoticeList.json")) .accept(MediaType.APPLICATION_JSON) ) .andExpect(status().isOk()) @@ -299,7 +288,7 @@ void deleteNoticeList() throws Exception { headerWithName("TOKEN").description("해당 로그인 유저의 토큰값") ), requestFields( - fieldWithPath("idList").description("삭제할 항목") + fieldWithPath("id_list").description("삭제할 항목") ), responseFields( fieldWithPath("data").description("결과 데이터"), @@ -320,19 +309,12 @@ void updateNotice() throws Exception { Token token = tokenRepository.findByManager(manager).get(); mockMvc.perform( - patch("/api/notice/update", 1) - .header("TOKEN", token.getToken()) - .contentType(MediaType.APPLICATION_JSON) - .content( - "{" - + " \"id\": \"1\",\n" - + " \"notice_category\": \"INSPECTION\",\n" - + " \"title\": \"수정된 공지사항 제목입니다.\",\n" - + " \"message\": \"수정된 공지사항 내용입니다.\",\n" - + " \"status\": false\n" - + "}") - .accept(MediaType.APPLICATION_JSON) - ) + patch("/api/notice/update", 1) + .header("TOKEN", token.getToken()) + .contentType(MediaType.APPLICATION_JSON) + .content(readJson("json/notice/updateNotice.json")) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().isOk()) .andDo( restDocs.document( diff --git a/spring/src/test/java/com/bancow/bancowback/domain/main/qna/controller/QnaControllerTest.java b/spring/src/test/java/com/bancow/bancowback/domain/main/qna/controller/QnaControllerTest.java index bda6860e..a0cde573 100644 --- a/spring/src/test/java/com/bancow/bancowback/domain/main/qna/controller/QnaControllerTest.java +++ b/spring/src/test/java/com/bancow/bancowback/domain/main/qna/controller/QnaControllerTest.java @@ -185,16 +185,7 @@ void addQna() throws Exception { mockMvc.perform( post("/api/qna/add") .contentType(MediaType.APPLICATION_JSON) - .content( - "{" - + " \"category\": \"INVESTMENT\",\n" - + " \"qna_name\": \"KimJiHun\",\n" - + " \"phone_number\": \"010-1234-5678\",\n" - + " \"email\": \"gmldnr2222@naver.com\",\n" - + " \"title\": \"투자 문의 입니다.\",\n" - + " \"message\": \"이메일 혹은 전화로 연락 부탁드립니다.\"\n" - + "}" - ) + .content(readJson("/json/qna/addQna.json")) .accept(MediaType.APPLICATION_JSON) ) .andExpect(status().isOk()) diff --git a/spring/src/test/java/com/bancow/bancowback/domain/manager/controller/ManagerControllerTest.java b/spring/src/test/java/com/bancow/bancowback/domain/manager/controller/ManagerControllerTest.java index 34c81438..dfe8d6c1 100644 --- a/spring/src/test/java/com/bancow/bancowback/domain/manager/controller/ManagerControllerTest.java +++ b/spring/src/test/java/com/bancow/bancowback/domain/manager/controller/ManagerControllerTest.java @@ -38,14 +38,7 @@ void registerManager() throws Exception { mockMvc.perform( post("/api/register") .contentType(MediaType.APPLICATION_JSON) - .content( - "{\n" - + " \"email\": \"gmldnr2222@naver.com\",\n" - + " \"username\": \"김지훈\",\n" - + " \"password\": \"passwordAndPassword2\",\n" - + " \"password2\": \"passwordAndPassword2\"\n" - + "}" - ) + .content(readJson("json/manager/registerManger.json")) ) .andExpect(status().isOk()) .andDo( @@ -73,12 +66,7 @@ void login() throws Exception { mockMvc.perform( post("/api/login") .contentType(MediaType.APPLICATION_JSON) - .content( - "{\n" - + " \"email\": \"smtptestkk@gmail.com\",\n" - + " \"password\": \"q1w2e3r4\"\n" - + "}" - ) + .content(readJson("json/manager/login.json")) ) .andExpect(status().isOk()) .andDo( @@ -251,10 +239,7 @@ void findManager() throws Exception { mockMvc.perform( post("/api/findmanager") .contentType(MediaType.APPLICATION_JSON) - .content("{\n" - + "\"email\": \"gmldnr2222@naver.com\",\n" - + "\"username\": \"가나다\"\n" - + "}") + .content(readJson("json/manager/findManager.json")) ) .andExpect(status().isOk()) .andDo( @@ -330,10 +315,7 @@ void changePassword() throws Exception { mockMvc.perform( patch("/api//authentication/findmanager/{token}/change-password", findToken.getToken()) .contentType(MediaType.APPLICATION_JSON) - .content("{" - + "\"password1\" : \"123123\",\n" - + "\"password2\" : \"123123\"\n" - + "}") + .content(readJson("/json/manager/changePassword.json")) ) .andExpect(status().isOk()) .andDo( diff --git a/spring/src/test/java/com/bancow/bancowback/domain/sub/chart/controller/ChartControllerTest.java b/spring/src/test/java/com/bancow/bancowback/domain/sub/chart/controller/ChartControllerTest.java index af493d88..ee964294 100644 --- a/spring/src/test/java/com/bancow/bancowback/domain/sub/chart/controller/ChartControllerTest.java +++ b/spring/src/test/java/com/bancow/bancowback/domain/sub/chart/controller/ChartControllerTest.java @@ -14,7 +14,6 @@ import com.bancow.bancowback.domain.common.util.token.entity.Token; import com.bancow.bancowback.domain.common.util.token.repository.TokenRepository; import com.bancow.bancowback.domain.manager.entity.Manager; -import com.bancow.bancowback.domain.sub.chart.entity.KoreanCowCategory; class ChartControllerTest extends TestSupport { diff --git a/spring/src/test/resources/json/faq/addFaq.json b/spring/src/test/resources/json/faq/addFaq.json new file mode 100644 index 00000000..93db8a2e --- /dev/null +++ b/spring/src/test/resources/json/faq/addFaq.json @@ -0,0 +1,6 @@ +{ + "faq_category": "AUCTION", + "title": "FAQ 제목입니다.", + "message": "FAQ 내용입니다.", + "status": false +} \ No newline at end of file diff --git a/spring/src/test/resources/json/faq/deleteFaqList.json b/spring/src/test/resources/json/faq/deleteFaqList.json new file mode 100644 index 00000000..37e8bb45 --- /dev/null +++ b/spring/src/test/resources/json/faq/deleteFaqList.json @@ -0,0 +1,3 @@ +{ + "id_list" : [1,2] +} \ No newline at end of file diff --git a/spring/src/test/resources/json/faq/updateFaq.json b/spring/src/test/resources/json/faq/updateFaq.json new file mode 100644 index 00000000..f9a86c5c --- /dev/null +++ b/spring/src/test/resources/json/faq/updateFaq.json @@ -0,0 +1,7 @@ +{ + "id": "1", + "faq_category": "AUCTION", + "title": "수정된 FAQ 제목입니다.", + "message": "수정된 FAQ 내용입니다.", + "status": false +} \ No newline at end of file diff --git a/spring/src/test/resources/json/farmQna/addFarmQna.json b/spring/src/test/resources/json/farmQna/addFarmQna.json new file mode 100644 index 00000000..122f366a --- /dev/null +++ b/spring/src/test/resources/json/farmQna/addFarmQna.json @@ -0,0 +1,10 @@ +{ + "farm_qna_name": "김철수", + "phone_number": "010-3991-7102", + "email": "gmldnr2222@naver.com", + "farm_name": "속초농장", + "farm_address": "강원도 속초시 교동 밤골3길", + "cow_num": "100", + "feed_name": "먹이이름입니다.", + "available_date": "2022-02-20" +} \ No newline at end of file diff --git a/spring/src/test/resources/json/manager/changePassword.json b/spring/src/test/resources/json/manager/changePassword.json new file mode 100644 index 00000000..59d7fc11 --- /dev/null +++ b/spring/src/test/resources/json/manager/changePassword.json @@ -0,0 +1,4 @@ +{ + "password1": "newPassword6403", + "password2": "newPassword6403" +} \ No newline at end of file diff --git a/spring/src/test/resources/json/manager/findManager.json b/spring/src/test/resources/json/manager/findManager.json new file mode 100644 index 00000000..110efeef --- /dev/null +++ b/spring/src/test/resources/json/manager/findManager.json @@ -0,0 +1,5 @@ +{ + "email": "smtptestkk@gmail.com", + "username": "김지훈" +} + diff --git a/spring/src/test/resources/json/manager/login.json b/spring/src/test/resources/json/manager/login.json new file mode 100644 index 00000000..10b5c9fb --- /dev/null +++ b/spring/src/test/resources/json/manager/login.json @@ -0,0 +1,5 @@ +{ +"email": "smtptestkk@gmail.com", +"password": "q1w2e3r4" +} + diff --git a/spring/src/test/resources/json/manager/registerManger.json b/spring/src/test/resources/json/manager/registerManger.json new file mode 100644 index 00000000..9bae9fbc --- /dev/null +++ b/spring/src/test/resources/json/manager/registerManger.json @@ -0,0 +1,6 @@ +{ +"email": "gmldnr2222@naver.com", +"username": "김지훈", +"password": "passwordAndPassword2", +"password2": "passwordAndPassword2" +} \ No newline at end of file diff --git a/spring/src/test/resources/json/notice/addNotice.json b/spring/src/test/resources/json/notice/addNotice.json new file mode 100644 index 00000000..d260d6b9 --- /dev/null +++ b/spring/src/test/resources/json/notice/addNotice.json @@ -0,0 +1,6 @@ +{ + "notice_category": "INSPECTION", + "title": "공지사항 제목입니다.", + "message": "공지사항 내용입니다.", + "status": false +} \ No newline at end of file diff --git a/spring/src/test/resources/json/notice/deleteNoticeList.json b/spring/src/test/resources/json/notice/deleteNoticeList.json new file mode 100644 index 00000000..62995d5a --- /dev/null +++ b/spring/src/test/resources/json/notice/deleteNoticeList.json @@ -0,0 +1,3 @@ +{ + "id_list": [1,2] +} \ No newline at end of file diff --git a/spring/src/test/resources/json/notice/updateNotice.json b/spring/src/test/resources/json/notice/updateNotice.json new file mode 100644 index 00000000..cf561187 --- /dev/null +++ b/spring/src/test/resources/json/notice/updateNotice.json @@ -0,0 +1,7 @@ +{ + "id": "1", + "notice_category": "INSPECTION", + "title": "수정된 공지사항 제목입니다.", + "message": "수정된 공지사항 내용입니다.", + "status": false +} \ No newline at end of file diff --git a/spring/src/test/resources/json/qna/addQna.json b/spring/src/test/resources/json/qna/addQna.json new file mode 100644 index 00000000..dbdb15e5 --- /dev/null +++ b/spring/src/test/resources/json/qna/addQna.json @@ -0,0 +1,8 @@ +{ + "category": "INVESTMENT", + "qna_name": "KimJiHun", + "phone_number": "010-1234-5678", + "email": "gmldnr2222@naver.com", + "title": "투자 문의 입니다.", + "message": "이메일 혹은 전화로 연락 부탁드립니다." +} \ No newline at end of file