33import static org .mockito .ArgumentMatchers .*;
44import static org .mockito .BDDMockito .given ;
55import static org .mockito .BDDMockito .willDoNothing ;
6- import static org .springframework .http .MediaType .MULTIPART_FORM_DATA ;
7- import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .delete ;
8- import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .multipart ;
6+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .*;
97import static org .springframework .test .web .servlet .result .MockMvcResultHandlers .print ;
108import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .jsonPath ;
119import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
2422import org .springframework .beans .factory .annotation .Autowired ;
2523import org .springframework .boot .test .mock .mockito .MockBean ;
2624import org .springframework .http .MediaType ;
27- import org .springframework .mock .web .MockHttpServletRequest ;
28- import org .springframework .mock .web .MockMultipartFile ;
2925import org .springframework .test .web .servlet .MockMvc ;
30- import org .springframework .test .web .servlet .request .MockMultipartHttpServletRequestBuilder ;
31- import org .springframework .test .web .servlet .request .RequestPostProcessor ;
3226
3327public class CommunityCommentCommandApiControllerTest extends ControllerTestSupport {
3428
@@ -60,20 +54,13 @@ void createCommunityComment() throws Exception {
6054 .parentCommentId (null )
6155 .build ();
6256
63- MockMultipartFile requestData = new MockMultipartFile (
64- "data" ,
65- "" ,
66- MediaType .APPLICATION_JSON_VALUE ,
67- objectMapper .writeValueAsBytes (requestDto )
68- );
69-
7057 given (createCommunityCommentUseCase .createCommunityComment (any (), any (UUID .class ),
7158 eq (communityBoardId ))).willReturn (communityCommentId );
7259
7360 //when
74- mockMvc .perform (multipart ("/api/community-board/{boardId}/comment" , communityBoardId )
75- .file ( requestData )
76- .contentType (MULTIPART_FORM_DATA )
61+ mockMvc .perform (post ("/api/community-board/{boardId}/comment" , communityBoardId )
62+ .content ( objectMapper . writeValueAsString ( requestDto ) )
63+ .contentType (MediaType . APPLICATION_JSON )
7764 .header ("Authorization" , "Bearer access-token" ))
7865
7966 //then
@@ -92,32 +79,14 @@ void updateCommunityComment_success() throws Exception {
9279 .content ("감사합니다." )
9380 .build ();
9481
95- MockMultipartFile requestData = new MockMultipartFile (
96- "data" ,
97- "" ,
98- MediaType .APPLICATION_JSON_VALUE ,
99- objectMapper .writeValueAsBytes (requestDto )
100- );
101-
10282 willDoNothing ().given (updateCommunityCommentUseCase )
103- .updateCommunityComment (any (), any (),
104- any (UUID .class ), any ());
105-
106- MockMultipartHttpServletRequestBuilder builder =
107- multipart ("/api/community-board/{boardId}/comment/{id}" , communityBoardId , communityCommentId );
108- builder .with (new RequestPostProcessor () {
109- @ Override
110- public MockHttpServletRequest postProcessRequest (MockHttpServletRequest request ) {
111- request .setMethod ("PUT" );
112- return request ;
113- }
114- });
83+ .updateCommunityComment (any (), any (), any (UUID .class ), any ());
11584
11685 //when
117- mockMvc .perform (builder
118- . file ( requestData )
119- .contentType (MULTIPART_FORM_DATA )
120- .header ("Authorization" , "Bearer access-token" ))
86+ mockMvc .perform (put ( "/api/community-board/{boardId}/comment/{id}" , communityBoardId , communityCommentId )
87+ . content ( objectMapper . writeValueAsString ( requestDto ) )
88+ .contentType (MediaType . APPLICATION_JSON )
89+ .header ("Authorization" , "Bearer access-token" ))
12190
12291 //then
12392 .andExpect (status ().isOk ())
0 commit comments