11package com .somemore .domains .recruitboard .controller ;
22
3+ import static com .somemore .domains .recruitboard .domain .RecruitStatus .CLOSED ;
4+ import static com .somemore .domains .recruitboard .domain .VolunteerCategory .OTHER ;
5+ import static com .somemore .support .fixture .LocalDateTimeFixture .createStartDateTime ;
6+ import static org .mockito .ArgumentMatchers .any ;
7+ import static org .mockito .BDDMockito .given ;
8+ import static org .mockito .BDDMockito .willDoNothing ;
9+ import static org .springframework .http .MediaType .APPLICATION_JSON ;
10+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .delete ;
11+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .patch ;
12+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .post ;
13+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .put ;
14+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .jsonPath ;
15+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
16+
317import com .somemore .domains .location .dto .request .LocationCreateRequestDto ;
418import com .somemore .domains .recruitboard .domain .RecruitStatus ;
519import com .somemore .domains .recruitboard .dto .request .RecruitBoardCreateRequestDto ;
923import com .somemore .domains .recruitboard .usecase .CreateRecruitBoardUseCase ;
1024import com .somemore .domains .recruitboard .usecase .DeleteRecruitBoardUseCase ;
1125import com .somemore .domains .recruitboard .usecase .UpdateRecruitBoardUseCase ;
12- import com .somemore .global .imageupload .usecase .ImageUploadUseCase ;
1326import com .somemore .support .ControllerTestSupport ;
1427import com .somemore .support .annotation .MockUser ;
15- import com .somemore .support .annotation .WithMockCustomUser ;
16- import org .junit .jupiter .api .DisplayName ;
17- import org .junit .jupiter .api .Test ;
18- import org .springframework .boot .test .mock .mockito .MockBean ;
19- import org .springframework .http .MediaType ;
20- import org .springframework .mock .web .MockHttpServletRequest ;
21- import org .springframework .mock .web .MockMultipartFile ;
22- import org .springframework .test .web .servlet .request .MockMultipartHttpServletRequestBuilder ;
23- import org .springframework .test .web .servlet .request .RequestPostProcessor ;
24-
2528import java .math .BigDecimal ;
2629import java .time .LocalDateTime ;
2730import java .util .UUID ;
28-
29- import static com .somemore .domains .recruitboard .domain .RecruitStatus .CLOSED ;
30- import static com .somemore .domains .recruitboard .domain .VolunteerCategory .OTHER ;
31- import static com .somemore .support .fixture .LocalDateTimeFixture .createStartDateTime ;
32- import static org .mockito .ArgumentMatchers .any ;
33- import static org .mockito .ArgumentMatchers .anyString ;
34- import static org .mockito .BDDMockito .given ;
35- import static org .mockito .BDDMockito .willDoNothing ;
36- import static org .springframework .http .MediaType .MULTIPART_FORM_DATA ;
37- import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .*;
38- import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .jsonPath ;
39- import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
31+ import org .junit .jupiter .api .DisplayName ;
32+ import org .junit .jupiter .api .Test ;
33+ import org .springframework .boot .test .mock .mockito .MockBean ;
4034
4135class RecruitBoardCommandApiControllerTest extends ControllerTestSupport {
4236
@@ -49,8 +43,6 @@ class RecruitBoardCommandApiControllerTest extends ControllerTestSupport {
4943 @ MockBean
5044 private DeleteRecruitBoardUseCase deleteRecruitBoardUseCase ;
5145
52- @ MockBean
53- private ImageUploadUseCase imageUploadUseCase ;
5446
5547 @ Test
5648 @ DisplayName ("봉사 활동 모집글 등록 성공 테스트" )
@@ -66,7 +58,7 @@ void createRecruitBoard_success() throws Exception {
6658 .longitude (BigDecimal .valueOf (127.010842267696 ))
6759 .build ();
6860
69- RecruitBoardCreateRequestDto dto = RecruitBoardCreateRequestDto .builder ()
61+ RecruitBoardCreateRequestDto requestDto = RecruitBoardCreateRequestDto .builder ()
7062 .title ("봉사 모집글 작성" )
7163 .content ("봉사 하실분을 모집합니다. <br>" )
7264 .region ("지역" )
@@ -79,37 +71,21 @@ void createRecruitBoard_success() throws Exception {
7971 .location (location )
8072 .build ();
8173
82- MockMultipartFile imageFile = new MockMultipartFile (
83- "img_file" ,
84- "test-image.jpg" ,
85- MediaType .IMAGE_JPEG_VALUE ,
86- "test image content" .getBytes ()
87- );
88-
89- MockMultipartFile requestData = new MockMultipartFile (
90- "data" ,
91- "" ,
92- MediaType .APPLICATION_JSON_VALUE ,
93- objectMapper .writeValueAsBytes (dto )
94- );
95-
96- String mockImageUrl = "http://example.com/image/test-image.jpg" ;
97- long mockRecruitBoardId = 1L ;
74+ String requestBody = objectMapper .writeValueAsString (requestDto );
75+ long boardId = 1L ;
9876
99- given (imageUploadUseCase .uploadImage (any ())).willReturn (mockImageUrl );
100- given (createRecruitBoardUseCase .createRecruitBoard (any (), any (UUID .class ),
101- anyString ())).willReturn (mockRecruitBoardId );
77+ given (createRecruitBoardUseCase .createRecruitBoard (any (), any (UUID .class )))
78+ .willReturn (boardId );
10279
10380 // when
104- mockMvc .perform (multipart ("/api/recruit-board" )
105- .file (requestData )
106- .file (imageFile )
107- .contentType (MULTIPART_FORM_DATA )
81+ mockMvc .perform (post ("/api/recruit-board" )
82+ .content (requestBody )
83+ .contentType (APPLICATION_JSON )
10884 .header ("Authorization" , "Bearer access-token" ))
10985 // then
11086 .andExpect (status ().isOk ())
11187 .andExpect (jsonPath ("$.code" ).value (201 ))
112- .andExpect (jsonPath ("$.data" ).value (mockRecruitBoardId ))
88+ .andExpect (jsonPath ("$.data" ).value (boardId ))
11389 .andExpect (jsonPath ("$.message" ).value ("봉사 활동 모집글 등록 성공" ));
11490 }
11591
@@ -133,40 +109,15 @@ void updateRecruitBoard() throws Exception {
133109 .admitted (true )
134110 .build ();
135111
136- MockMultipartFile imageFile = new MockMultipartFile (
137- "img_file" ,
138- "test-image.jpg" ,
139- MediaType .IMAGE_JPEG_VALUE ,
140- "test image content" .getBytes ()
141- );
142-
143- MockMultipartFile requestData = new MockMultipartFile (
144- "data" ,
145- "" ,
146- MediaType .APPLICATION_JSON_VALUE ,
147- objectMapper .writeValueAsBytes (requestDto )
148- );
149-
150- String mockImageUrl = "http://example.com/image/test-image.jpg" ;
151-
152- given (imageUploadUseCase .uploadImage (any ())).willReturn (mockImageUrl );
153112 willDoNothing ().given (updateRecruitBoardUseCase )
154- .updateRecruitBoard (any (), any (), any (UUID .class ), anyString () );
113+ .updateRecruitBoard (any (), any (), any (UUID .class ));
155114
156- MockMultipartHttpServletRequestBuilder builder = multipart ("/api/recruit-board/{id}" , 1 );
157- builder .with (new RequestPostProcessor () {
158- @ Override
159- public MockHttpServletRequest postProcessRequest (MockHttpServletRequest request ) {
160- request .setMethod ("PUT" );
161- return request ;
162- }
163- });
115+ String requestBody = objectMapper .writeValueAsString (requestDto );
164116
165117 // when
166- mockMvc .perform (builder
167- .file (requestData )
168- .file (imageFile )
169- .contentType (MULTIPART_FORM_DATA )
118+ mockMvc .perform (put ("/api/recruit-board/{id}" , 1 )
119+ .content (requestBody )
120+ .contentType (APPLICATION_JSON )
170121 .header ("Authorization" , "Bearer access-token" ))
171122 //then
172123 .andExpect (status ().isOk ())
@@ -195,7 +146,7 @@ void updateRecruitBoardLocation() throws Exception {
195146 // when
196147 mockMvc .perform (put ("/api/recruit-board/{id}/location" , 1L )
197148 .content (requestBody )
198- .contentType (MediaType . APPLICATION_JSON )
149+ .contentType (APPLICATION_JSON )
199150 .header ("Authorization" , "Bearer access-token" ))
200151 // then
201152 .andExpect (status ().isOk ())
@@ -219,7 +170,7 @@ void updateRecruitBoardStatus() throws Exception {
219170 // when
220171 mockMvc .perform (patch ("/api/recruit-board/{id}" , 1L )
221172 .content (requestBody )
222- .contentType (MediaType . APPLICATION_JSON )
173+ .contentType (APPLICATION_JSON )
223174 .header ("Authorization" , "Bearer access-token" ))
224175 //then
225176 .andExpect (status ().isOk ())
0 commit comments