Skip to content

Commit

Permalink
refactor: extract json file from test content [#351]
Browse files Browse the repository at this point in the history
  • Loading branch information
kho903 committed Feb 13, 2022
1 parent ad1e556 commit 4736670
Show file tree
Hide file tree
Showing 19 changed files with 101 additions and 102 deletions.
4 changes: 3 additions & 1 deletion spring/src/test/java/com/bancow/bancowback/TestSupport.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand All @@ -299,7 +288,7 @@ void deleteFaqList() throws Exception {
headerWithName("TOKEN").description("해당 로그인 유저의 토큰값")
),
requestFields(
fieldWithPath("idList").description("삭제할 항목")
fieldWithPath("id_list").description("삭제할 항목")
),
responseFields(
fieldWithPath("data").description("결과 데이터"),
Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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\": \"[email protected]\",\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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand All @@ -299,7 +288,7 @@ void deleteNoticeList() throws Exception {
headerWithName("TOKEN").description("해당 로그인 유저의 토큰값")
),
requestFields(
fieldWithPath("idList").description("삭제할 항목")
fieldWithPath("id_list").description("삭제할 항목")
),
responseFields(
fieldWithPath("data").description("결과 데이터"),
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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\": \"[email protected]\",\n"
+ " \"title\": \"투자 문의 입니다.\",\n"
+ " \"message\": \"이메일 혹은 전화로 연락 부탁드립니다.\"\n"
+ "}"
)
.content(readJson("/json/qna/addQna.json"))
.accept(MediaType.APPLICATION_JSON)
)
.andExpect(status().isOk())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,7 @@ void registerManager() throws Exception {
mockMvc.perform(
post("/api/register")
.contentType(MediaType.APPLICATION_JSON)
.content(
"{\n"
+ " \"email\": \"[email protected]\",\n"
+ " \"username\": \"김지훈\",\n"
+ " \"password\": \"passwordAndPassword2\",\n"
+ " \"password2\": \"passwordAndPassword2\"\n"
+ "}"
)
.content(readJson("json/manager/registerManger.json"))
)
.andExpect(status().isOk())
.andDo(
Expand Down Expand Up @@ -73,12 +66,7 @@ void login() throws Exception {
mockMvc.perform(
post("/api/login")
.contentType(MediaType.APPLICATION_JSON)
.content(
"{\n"
+ " \"email\": \"[email protected]\",\n"
+ " \"password\": \"q1w2e3r4\"\n"
+ "}"
)
.content(readJson("json/manager/login.json"))
)
.andExpect(status().isOk())
.andDo(
Expand Down Expand Up @@ -251,10 +239,7 @@ void findManager() throws Exception {
mockMvc.perform(
post("/api/findmanager")
.contentType(MediaType.APPLICATION_JSON)
.content("{\n"
+ "\"email\": \"[email protected]\",\n"
+ "\"username\": \"가나다\"\n"
+ "}")
.content(readJson("json/manager/findManager.json"))
)
.andExpect(status().isOk())
.andDo(
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
6 changes: 6 additions & 0 deletions spring/src/test/resources/json/faq/addFaq.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"faq_category": "AUCTION",
"title": "FAQ 제목입니다.",
"message": "FAQ 내용입니다.",
"status": false
}
3 changes: 3 additions & 0 deletions spring/src/test/resources/json/faq/deleteFaqList.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"id_list" : [1,2]
}
7 changes: 7 additions & 0 deletions spring/src/test/resources/json/faq/updateFaq.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"id": "1",
"faq_category": "AUCTION",
"title": "수정된 FAQ 제목입니다.",
"message": "수정된 FAQ 내용입니다.",
"status": false
}
10 changes: 10 additions & 0 deletions spring/src/test/resources/json/farmQna/addFarmQna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"farm_qna_name": "김철수",
"phone_number": "010-3991-7102",
"email": "[email protected]",
"farm_name": "속초농장",
"farm_address": "강원도 속초시 교동 밤골3길",
"cow_num": "100",
"feed_name": "먹이이름입니다.",
"available_date": "2022-02-20"
}
4 changes: 4 additions & 0 deletions spring/src/test/resources/json/manager/changePassword.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"password1": "newPassword6403",
"password2": "newPassword6403"
}
5 changes: 5 additions & 0 deletions spring/src/test/resources/json/manager/findManager.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"email": "[email protected]",
"username": "김지훈"
}

5 changes: 5 additions & 0 deletions spring/src/test/resources/json/manager/login.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"email": "[email protected]",
"password": "q1w2e3r4"
}

6 changes: 6 additions & 0 deletions spring/src/test/resources/json/manager/registerManger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"email": "[email protected]",
"username": "김지훈",
"password": "passwordAndPassword2",
"password2": "passwordAndPassword2"
}
6 changes: 6 additions & 0 deletions spring/src/test/resources/json/notice/addNotice.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"notice_category": "INSPECTION",
"title": "공지사항 제목입니다.",
"message": "공지사항 내용입니다.",
"status": false
}
3 changes: 3 additions & 0 deletions spring/src/test/resources/json/notice/deleteNoticeList.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"id_list": [1,2]
}
7 changes: 7 additions & 0 deletions spring/src/test/resources/json/notice/updateNotice.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"id": "1",
"notice_category": "INSPECTION",
"title": "수정된 공지사항 제목입니다.",
"message": "수정된 공지사항 내용입니다.",
"status": false
}
8 changes: 8 additions & 0 deletions spring/src/test/resources/json/qna/addQna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"category": "INVESTMENT",
"qna_name": "KimJiHun",
"phone_number": "010-1234-5678",
"email": "[email protected]",
"title": "투자 문의 입니다.",
"message": "이메일 혹은 전화로 연락 부탁드립니다."
}

0 comments on commit 4736670

Please sign in to comment.