1
+ package me .oldboy .integration .controllers .api_user_details_scenario ;
2
+
3
+ import lombok .SneakyThrows ;
4
+ import me .oldboy .config .test_data_source .TestContainerInit ;
5
+ import me .oldboy .integration .annotation .IT ;
6
+ import org .junit .jupiter .api .BeforeEach ;
7
+ import org .junit .jupiter .api .Test ;
8
+ import org .springframework .beans .factory .annotation .Autowired ;
9
+ import org .springframework .security .test .context .support .WithUserDetails ;
10
+ import org .springframework .test .web .servlet .MockMvc ;
11
+ import org .springframework .test .web .servlet .setup .MockMvcBuilders ;
12
+ import org .springframework .web .context .WebApplicationContext ;
13
+
14
+ import static me .oldboy .test_constant .TestConstantFields .EXIST_EMAIL ;
15
+ import static org .hamcrest .Matchers .containsString ;
16
+ import static org .springframework .security .test .web .servlet .setup .SecurityMockMvcConfigurers .springSecurity ;
17
+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
18
+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .content ;
19
+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
20
+
21
+ @ IT
22
+ class AccountControllerIT extends TestContainerInit {
23
+
24
+ @ Autowired
25
+ private WebApplicationContext webApplicationContext ;
26
+ private MockMvc mockMvc ;
27
+
28
+ @ BeforeEach
29
+ void setUp (){
30
+ mockMvc = MockMvcBuilders .webAppContextSetup (webApplicationContext )
31
+ .apply (springSecurity ())
32
+ .build ();
33
+ }
34
+
35
+ @ Test
36
+ @ SneakyThrows
37
+ @ WithUserDetails (value = EXIST_EMAIL , userDetailsServiceBeanName = "clientDetailsService" )
38
+ void getAccountDetails_ShouldReturnOk_AndAccountRecord_ForCurrentClient_Test () {
39
+ mockMvc .perform (get ("/api/myAccount" ))
40
+ .andExpect (status ().isOk ())
41
+ .andExpect (content ().string (containsString ("accountNumber" )))
42
+ .andExpect (content ().string (containsString ("accountType" )))
43
+ .andExpect (content ().string (containsString ("branchAddress" )))
44
+ .andExpect (content ().string (containsString ("createDt" )));
45
+ }
46
+
47
+ @ Test
48
+ @ SneakyThrows
49
+ void getAccountDetails_ShouldReturn_401_NotAuthClient_Test () {
50
+ mockMvc .perform (get ("/api/myAccount" ))
51
+ .andExpect (status ().is4xxClientError ())
52
+ .andExpect (content ().string ("" ));
53
+ }
54
+ }
0 commit comments