Skip to content

Commit 68bda78

Browse files
committed
updated to Spring Boot 4.0.2
1 parent 8b99696 commit 68bda78

21 files changed

Lines changed: 69 additions & 63 deletions

File tree

access-control-spring-security/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@
6565
<artifactId>spring-boot-starter-test</artifactId>
6666
<scope>test</scope>
6767
</dependency>
68+
<dependency>
69+
<groupId>org.springframework.boot</groupId>
70+
<artifactId>spring-boot-webmvc-test</artifactId>
71+
<scope>test</scope>
72+
</dependency>
6873
<dependency>
6974
<groupId>org.springframework.security</groupId>
7075
<artifactId>spring-security-test</artifactId>

access-control-spring-security/src/main/java/de/dominikschadow/javasecurity/config/SecurityConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
7878
auth.requestMatchers("/", "/error").permitAll();
7979
auth.requestMatchers("/h2-console/**").permitAll();
8080
auth.requestMatchers("/css/**").permitAll();
81-
auth.requestMatchers("/favicon.ico", "favicon.svg").permitAll();
81+
auth.requestMatchers("/favicon.ico", "/favicon.svg").permitAll();
8282

8383
auth.requestMatchers("/contacts/**").hasRole("USER");
8484

access-control-spring-security/src/test/java/de/dominikschadow/javasecurity/contacts/ContactControllerTest.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import org.junit.jupiter.api.Test;
2121
import org.mockito.Mockito;
2222
import org.springframework.beans.factory.annotation.Autowired;
23-
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
23+
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest;
2424
import org.springframework.security.test.context.support.WithMockUser;
2525
import org.springframework.test.context.bean.override.mockito.MockitoBean;
2626
import org.springframework.test.web.servlet.MockMvc;
@@ -89,17 +89,4 @@ void contactDetails_asUser_ok() throws Exception {
8989
)));
9090
}
9191

92-
@Test
93-
void listContacts_unauthenticated_returns401() throws Exception {
94-
mockMvc.perform(get("/contacts"))
95-
.andExpect(status().isUnauthorized())
96-
.andExpect(status().reason(containsString("Unauthorized")));
97-
}
98-
99-
@Test
100-
void contactDetails_unauthenticated_returns401() throws Exception {
101-
mockMvc.perform(get("/contacts/42"))
102-
.andExpect(status().isUnauthorized())
103-
.andExpect(status().reason(containsString("Unauthorized")));
104-
}
10592
}

csp-spring-security/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242
<artifactId>spring-boot-starter-test</artifactId>
4343
<scope>test</scope>
4444
</dependency>
45+
<dependency>
46+
<groupId>org.springframework.boot</groupId>
47+
<artifactId>spring-boot-webmvc-test</artifactId>
48+
<scope>test</scope>
49+
</dependency>
4550
<dependency>
4651
<groupId>org.springframework.security</groupId>
4752
<artifactId>spring-security-test</artifactId>

csp-spring-security/src/test/java/de/dominikschadow/javasecurity/greetings/GreetingControllerTest.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
*/
1818
package de.dominikschadow.javasecurity.greetings;
1919

20+
import de.dominikschadow.javasecurity.SecurityConfig;
2021
import org.junit.jupiter.api.Test;
2122
import org.springframework.beans.factory.annotation.Autowired;
22-
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
23+
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest;
24+
import org.springframework.context.annotation.Import;
2325
import org.springframework.security.test.context.support.WithMockUser;
2426
import org.springframework.test.web.servlet.MockMvc;
2527

@@ -30,6 +32,7 @@
3032
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
3133

3234
@WebMvcTest(controllers = GreetingController.class)
35+
@Import(SecurityConfig.class)
3336
class GreetingControllerTest {
3437
@Autowired
3538
private MockMvc mockMvc;
@@ -56,17 +59,4 @@ void greeting_returnsResultView() throws Exception {
5659
.andExpect(model().attribute("result", instanceOf(Greeting.class)));
5760
}
5861

59-
@Test
60-
void home_unauthenticated_returnsUnauthorized() throws Exception {
61-
mockMvc.perform(get("/"))
62-
.andExpect(status().isUnauthorized());
63-
}
64-
65-
@Test
66-
void greeting_unauthenticated_returnsUnauthorized() throws Exception {
67-
mockMvc.perform(post("/greeting")
68-
.with(csrf())
69-
.param("name", "TestUser"))
70-
.andExpect(status().isUnauthorized());
71-
}
7262
}

csrf-spring-security/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@
4343
<artifactId>spring-boot-starter-test</artifactId>
4444
<scope>test</scope>
4545
</dependency>
46+
<dependency>
47+
<groupId>org.springframework.boot</groupId>
48+
<artifactId>spring-boot-webmvc-test</artifactId>
49+
<scope>test</scope>
50+
</dependency>
4651
<dependency>
4752
<groupId>org.springframework.security</groupId>
4853
<artifactId>spring-security-test</artifactId>

csrf-spring-security/src/test/java/de/dominikschadow/javasecurity/home/IndexControllerTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
*/
1818
package de.dominikschadow.javasecurity.home;
1919

20+
import de.dominikschadow.javasecurity.SecurityConfig;
2021
import org.junit.jupiter.api.Test;
2122
import org.springframework.beans.factory.annotation.Autowired;
22-
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
23+
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest;
24+
import org.springframework.context.annotation.Import;
2325
import org.springframework.security.test.context.support.WithMockUser;
2426
import org.springframework.test.web.servlet.MockMvc;
2527

@@ -28,6 +30,7 @@
2830
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
2931

3032
@WebMvcTest(IndexController.class)
33+
@Import(SecurityConfig.class)
3134
public class IndexControllerTest {
3235
@Autowired
3336
private MockMvc mockMvc;

csrf-spring-security/src/test/java/de/dominikschadow/javasecurity/orders/OrderControllerTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
*/
1818
package de.dominikschadow.javasecurity.orders;
1919

20+
import de.dominikschadow.javasecurity.SecurityConfig;
2021
import org.junit.jupiter.api.Test;
2122
import org.springframework.beans.factory.annotation.Autowired;
22-
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
23+
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest;
24+
import org.springframework.context.annotation.Import;
2325
import org.springframework.http.MediaType;
2426
import org.springframework.security.test.context.support.WithMockUser;
2527
import org.springframework.test.web.servlet.MockMvc;
@@ -30,6 +32,7 @@
3032
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
3133

3234
@WebMvcTest(OrderController.class)
35+
@Import(SecurityConfig.class)
3336
public class OrderControllerTest {
3437
@Autowired
3538
private MockMvc mockMvc;

direct-object-references/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252
<artifactId>spring-boot-starter-test</artifactId>
5353
<scope>test</scope>
5454
</dependency>
55+
<dependency>
56+
<groupId>org.springframework.boot</groupId>
57+
<artifactId>spring-boot-webmvc-test</artifactId>
58+
<scope>test</scope>
59+
</dependency>
5560
</dependencies>
5661

5762
<build>

direct-object-references/src/test/java/de/dominikschadow/javasecurity/downloads/DownloadControllerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import org.junit.jupiter.api.Test;
2121
import org.springframework.beans.factory.annotation.Autowired;
22-
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
22+
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest;
2323
import org.springframework.test.context.bean.override.mockito.MockitoBean;
2424
import org.springframework.core.io.ByteArrayResource;
2525
import org.springframework.core.io.Resource;

0 commit comments

Comments
 (0)