2
2
3
3
import static com .ajou .hertz .common .constant .GlobalConstants .*;
4
4
import static org .mockito .BDDMockito .*;
5
+ import static org .springframework .security .test .web .servlet .request .SecurityMockMvcRequestPostProcessors .*;
5
6
import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .*;
6
7
import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .*;
7
8
8
9
import java .lang .reflect .Constructor ;
9
10
import java .time .LocalDate ;
11
+ import java .time .LocalDateTime ;
10
12
import java .util .Set ;
11
13
12
14
import org .junit .jupiter .api .DisplayName ;
17
19
import org .springframework .context .annotation .Import ;
18
20
import org .springframework .data .jpa .mapping .JpaMetamodelMappingContext ;
19
21
import org .springframework .http .MediaType ;
22
+ import org .springframework .security .core .userdetails .UserDetails ;
20
23
import org .springframework .test .context .event .annotation .BeforeTestMethod ;
21
24
import org .springframework .test .web .servlet .MockMvc ;
22
25
26
29
import com .ajou .hertz .common .auth .JwtAuthenticationFilter ;
27
30
import com .ajou .hertz .common .auth .JwtExceptionFilter ;
28
31
import com .ajou .hertz .common .auth .JwtTokenProvider ;
32
+ import com .ajou .hertz .common .auth .UserPrincipal ;
29
33
import com .ajou .hertz .common .config .SecurityConfig ;
30
34
import com .ajou .hertz .domain .user .constant .Gender ;
31
35
import com .ajou .hertz .domain .user .constant .RoleType ;
@@ -71,6 +75,25 @@ public void securitySetUp() throws Exception {
71
75
given (userQueryService .getDtoById (anyLong ())).willReturn (createUserDto ());
72
76
}
73
77
78
+ @ Test
79
+ void 내_정보를_조회한다 () throws Exception {
80
+ // given
81
+ long userId = 1L ;
82
+ UserDto expectedResult = createUserDto (userId );
83
+ given (userQueryService .getDtoById (userId )).willReturn (expectedResult );
84
+
85
+ // when & then
86
+ mvc .perform (
87
+ get ("/v1/users/me" )
88
+ .header (API_MINOR_VERSION_HEADER_NAME , 1 )
89
+ .with (user (createTestUser (userId )))
90
+ )
91
+ .andExpect (status ().isOk ())
92
+ .andExpect (jsonPath ("$.id" ).value (expectedResult .getId ()));
93
+ then (userQueryService ).should ().getDtoById (userId );
94
+ verifyEveryMocksShouldHaveNoMoreInteractions ();
95
+ }
96
+
74
97
@ Test
75
98
void 이메일이_주어지고_주어진_이메일을_사용_중인_회원의_존재_여부를_조회한다 () throws Exception {
76
99
// given
@@ -219,7 +242,8 @@ private SignUpRequest createSignUpRequest() throws Exception {
219
242
private UserDto createUserDto (long id ) throws Exception {
220
243
Constructor <UserDto > userResponseConstructor = UserDto .class .getDeclaredConstructor (
221
244
Long .class , Set .class , String .class , String .class , String .class ,
222
- String .class , LocalDate .class , Gender .class , String .class , String .class
245
+ String .class , LocalDate .class , Gender .class , String .class , String .class ,
246
+ LocalDateTime .class
223
247
);
224
248
userResponseConstructor .setAccessible (true );
225
249
return userResponseConstructor .newInstance (
@@ -232,11 +256,16 @@ private UserDto createUserDto(long id) throws Exception {
232
256
LocalDate .of (2024 , 1 , 1 ),
233
257
Gender .ETC ,
234
258
"01012345678" ,
235
- "https://contack-link"
259
+ "https://contack-link" ,
260
+ LocalDateTime .of (2024 , 1 , 1 , 0 , 0 )
236
261
);
237
262
}
238
263
239
264
private UserDto createUserDto () throws Exception {
240
265
return createUserDto (1L );
241
266
}
267
+
268
+ private UserDetails createTestUser (Long userId ) throws Exception {
269
+ return new UserPrincipal (createUserDto (userId ));
270
+ }
242
271
}
0 commit comments