2424
2525import java .util .List ;
2626
27- import static org .springframework .security .test .web .servlet .request .SecurityMockMvcRequestPostProcessors .user ;
2827import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
2928import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .put ;
3029import static org .springframework .test .web .servlet .result .MockMvcResultHandlers .print ;
3534@ AutoConfigureMockMvc
3635@ Transactional
3736@ ActiveProfiles ("test" )
38- @ WithMockUser
37+ @ WithMockUser ( username = "[email protected] " ) 3938@ Import ({TestElasticsearchConfiguration .class , TestRedisConfiguration .class })
4039class NotificationControllerTest {
4140
@@ -115,7 +114,6 @@ private void setupTestData() {
115114 @ DisplayName ("전체 알림 목록 조회 - 성공" )
116115 void getNotifications_Success () throws Exception {
117116 mockMvc .perform (get ("/notifications" )
118- .with (user (String .valueOf (testMember .getId ())))
119117 .param ("page" , "0" )
120118 .param ("size" , "10" )
121119 .contentType (MediaType .APPLICATION_JSON ))
@@ -135,7 +133,6 @@ void getNotifications_Success() throws Exception {
135133 @ DisplayName ("읽지 않은 알림만 조회 - 성공" )
136134 void getNotifications_UnreadOnly_Success () throws Exception {
137135 mockMvc .perform (get ("/notifications" )
138- .with (user (String .valueOf (testMember .getId ())))
139136 .param ("page" , "0" )
140137 .param ("size" , "10" )
141138 .param ("isRead" , "false" )
@@ -153,7 +150,6 @@ void getNotifications_UnreadOnly_Success() throws Exception {
153150 @ DisplayName ("읽은 알림만 조회 - 성공" )
154151 void getNotifications_ReadOnly_Success () throws Exception {
155152 mockMvc .perform (get ("/notifications" )
156- .with (user (String .valueOf (testMember .getId ())))
157153 .param ("page" , "0" )
158154 .param ("size" , "10" )
159155 .param ("isRead" , "true" )
@@ -170,7 +166,6 @@ void getNotifications_ReadOnly_Success() throws Exception {
170166 @ DisplayName ("페이징 처리 확인" )
171167 void getNotifications_Paging_Success () throws Exception {
172168 mockMvc .perform (get ("/notifications" )
173- .with (user (String .valueOf (testMember .getId ())))
174169 .param ("page" , "0" )
175170 .param ("size" , "2" )
176171 .contentType (MediaType .APPLICATION_JSON ))
@@ -188,7 +183,6 @@ void markAsRead_Success() throws Exception {
188183 Long notificationId = unreadNotification1 .getId ();
189184
190185 mockMvc .perform (put ("/notifications/{id}/read" , notificationId )
191- .with (user (String .valueOf (testMember .getId ())))
192186 .contentType (MediaType .APPLICATION_JSON ))
193187 .andDo (print ())
194188 .andExpect (status ().isOk ())
@@ -208,7 +202,6 @@ void markAsRead_NotFound() throws Exception {
208202 Long nonExistentId = 999999L ;
209203
210204 mockMvc .perform (put ("/notifications/{id}/read" , nonExistentId )
211- .with (user (String .valueOf (testMember .getId ())))
212205 .contentType (MediaType .APPLICATION_JSON ))
213206 .andDo (print ())
214207 .andExpect (status ().isNotFound ())
@@ -220,7 +213,6 @@ void markAsRead_NotFound() throws Exception {
220213 @ DisplayName ("모든 알림 읽음 처리 - 성공" )
221214 void markAllAsRead_Success () throws Exception {
222215 mockMvc .perform (put ("/notifications/read-all" )
223- .with (user (String .valueOf (testMember .getId ())))
224216 .contentType (MediaType .APPLICATION_JSON ))
225217 .andDo (print ())
226218 .andExpect (status ().isOk ())
@@ -240,7 +232,6 @@ void markAllAsRead_AlreadyRead() throws Exception {
240232 notificationRepository .markAllAsRead (testMember .getId ());
241233
242234 mockMvc .perform (put ("/notifications/read-all" )
243- .with (user (String .valueOf (testMember .getId ())))
244235 .contentType (MediaType .APPLICATION_JSON ))
245236 .andDo (print ())
246237 .andExpect (status ().isOk ())
@@ -253,7 +244,6 @@ void markAllAsRead_AlreadyRead() throws Exception {
253244 @ DisplayName ("읽지 않은 알림 개수 조회 - 성공" )
254245 void getUnreadCount_Success () throws Exception {
255246 mockMvc .perform (get ("/notifications/unread-count" )
256- .with (user (String .valueOf (testMember .getId ())))
257247 .contentType (MediaType .APPLICATION_JSON ))
258248 .andDo (print ())
259249 .andExpect (status ().isOk ())
@@ -266,7 +256,6 @@ void getUnreadCount_Success() throws Exception {
266256 @ DisplayName ("알림 응답 데이터 구조 검증" )
267257 void getNotifications_ResponseStructure () throws Exception {
268258 mockMvc .perform (get ("/notifications" )
269- .with (user (String .valueOf (testMember .getId ())))
270259 .param ("page" , "0" )
271260 .param ("size" , "10" )
272261 .contentType (MediaType .APPLICATION_JSON ))
@@ -285,7 +274,6 @@ void getNotifications_ResponseStructure() throws Exception {
285274 @ DisplayName ("알림 내용과 타입 검증" )
286275 void getNotifications_ContentValidation () throws Exception {
287276 mockMvc .perform (get ("/notifications" )
288- .with (user (String .valueOf (testMember .getId ())))
289277 .param ("page" , "0" )
290278 .param ("size" , "10" )
291279 .contentType (MediaType .APPLICATION_JSON ))
@@ -306,7 +294,6 @@ void getNotifications_ContentValidation() throws Exception {
306294 @ DisplayName ("잘못된 페이지 파라미터" )
307295 void getNotifications_InvalidPageParameter () throws Exception {
308296 mockMvc .perform (get ("/notifications" )
309- .with (user (String .valueOf (testMember .getId ())))
310297 .param ("page" , "-1" )
311298 .param ("size" , "10" )
312299 .contentType (MediaType .APPLICATION_JSON ))
@@ -334,7 +321,6 @@ void getNotifications_OnlyOwnNotifications() throws Exception {
334321
335322 // 현재 테스트 멤버의 알림만 조회됨
336323 mockMvc .perform (get ("/notifications" )
337- .with (user (String .valueOf (testMember .getId ())))
338324 .param ("page" , "0" )
339325 .param ("size" , "10" )
340326 .contentType (MediaType .APPLICATION_JSON ))
0 commit comments