Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1e0e5e7

Browse files
Security_part_11_3: add AccountControllerIT.java
1 parent 4d03518 commit 1e0e5e7

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /