From d2e7eab43e7131ef822135d01b949c927d5e0b34 Mon Sep 17 00:00:00 2001 From: Harry9656 Date: Fri, 19 Apr 2024 08:22:40 +0200 Subject: [PATCH] [JAVA-33568] Fix spring-security-web-boot-3 integration tests (#16441) --- .../ResourceEndpointIntegrationTest.java | 26 +++++++++---------- .../cachecontrol/SpringContextTest.java | 9 +++---- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/spring-security-modules/spring-security-web-boot-3/src/test/java/com/baeldung/cachecontrol/ResourceEndpointIntegrationTest.java b/spring-security-modules/spring-security-web-boot-3/src/test/java/com/baeldung/cachecontrol/ResourceEndpointIntegrationTest.java index eb27a8ccaf..e6b745ae22 100644 --- a/spring-security-modules/spring-security-web-boot-3/src/test/java/com/baeldung/cachecontrol/ResourceEndpointIntegrationTest.java +++ b/spring-security-modules/spring-security-web-boot-3/src/test/java/com/baeldung/cachecontrol/ResourceEndpointIntegrationTest.java @@ -1,43 +1,41 @@ package com.baeldung.cachecontrol; -import io.restassured.http.ContentType; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.server.LocalServerPort; -import org.springframework.test.context.junit4.SpringRunner; - import static io.restassured.RestAssured.given; -@RunWith(SpringRunner.class) +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.server.LocalServerPort; + +import io.restassured.http.ContentType; + @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = AppRunner.class) -public class ResourceEndpointIntegrationTest { +class ResourceEndpointIntegrationTest { @LocalServerPort private int serverPort; @Test - public void whenGetRequestForUser_shouldRespondWithDefaultCacheHeaders() { + void whenGetRequestForUser_shouldRespondWithDefaultCacheHeaders() { given().when().get(getBaseUrl() + "/default/users/Michael").then().headers("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate").header("Pragma", "no-cache"); } @Test - public void whenGetRequestForUser_shouldRespondMaxAgeCacheControl() { + void whenGetRequestForUser_shouldRespondMaxAgeCacheControl() { given().when().get(getBaseUrl() + "/users/Michael").then().header("Cache-Control", "max-age=60"); } @Test - public void givenServiceEndpoint_whenGetRequestForUser_shouldResponseWithCacheControlMaxAge() { + void givenServiceEndpoint_whenGetRequestForUser_shouldResponseWithCacheControlMaxAge() { given().when().get(getBaseUrl() + "/users/Michael").then().contentType(ContentType.JSON).and().statusCode(200).and().header("Cache-Control", "max-age=60"); } @Test - public void givenServiceEndpoint_whenGetRequestForNotCacheableContent_shouldResponseWithCacheControlNoCache() { + void givenServiceEndpoint_whenGetRequestForNotCacheableContent_shouldResponseWithCacheControlNoCache() { given().when().get(getBaseUrl() + "/timestamp").then().contentType(ContentType.JSON).and().statusCode(200).and().header("Cache-Control", "no-store"); } @Test - public void givenServiceEndpoint_whenGetRequestForPrivateUser_shouldResponseWithSecurityDefaultCacheControl() { + void givenServiceEndpoint_whenGetRequestForPrivateUser_shouldResponseWithSecurityDefaultCacheControl() { given().when().get(getBaseUrl() + "/private/users/Michael").then().contentType(ContentType.JSON).and().statusCode(200).and().header("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate"); } diff --git a/spring-security-modules/spring-security-web-boot-3/src/test/java/com/baeldung/cachecontrol/SpringContextTest.java b/spring-security-modules/spring-security-web-boot-3/src/test/java/com/baeldung/cachecontrol/SpringContextTest.java index 342aacfc4c..9d4853dc5a 100644 --- a/spring-security-modules/spring-security-web-boot-3/src/test/java/com/baeldung/cachecontrol/SpringContextTest.java +++ b/spring-security-modules/spring-security-web-boot-3/src/test/java/com/baeldung/cachecontrol/SpringContextTest.java @@ -1,15 +1,12 @@ package com.baeldung.cachecontrol; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringRunner.class) @SpringBootTest(classes = AppRunner.class) -public class SpringContextTest { +class SpringContextTest { @Test - public void whenSpringContextIsBootstrapped_thenNoExceptions() { + void whenSpringContextIsBootstrapped_thenNoExceptions() { } }