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 3cb15c3

Browse files
Security_part_11_3: add WmkAccountControllerIT.java
1 parent de0521a commit 3cb15c3

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_mock_aouth_scenario;
2+
3+
import lombok.SneakyThrows;
4+
import me.oldboy.config.test_data_source.TestContainerInit;
5+
import me.oldboy.integration.annotation.IT;
6+
import me.oldboy.integration.annotation.WithMockOAuth2User;
7+
import org.junit.jupiter.api.BeforeEach;
8+
import org.junit.jupiter.api.Test;
9+
import org.springframework.beans.factory.annotation.Autowired;
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 WmkAccountControllerIT 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+
@WithMockOAuth2User(username = EXIST_EMAIL, email = EXIST_EMAIL, authorities = {"ROLE_ADMIN"})
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 によって変換されたページ (->オリジナル) /