From a30907a9ea304354cd3b85d677d092e4329a9d77 Mon Sep 17 00:00:00 2001 From: Harry9656 Date: Fri, 22 Mar 2024 00:32:58 +0100 Subject: [PATCH] JAVA-31544: migrate spring-boot-testing and spring-boot-testing-2 to sb3 (#16182) --- spring-boot-modules/pom.xml | 4 +-- .../spring-boot-testing-2/pom.xml | 22 +++++++++---- .../baeldung/webservice/ProductEndpoint.java | 12 ++++--- .../generated/GetProductRequest.java | 32 +++++++++---------- .../generated/GetProductResponse.java | 32 +++++++++---------- .../webservice/generated/ObjectFactory.java | 8 ++++- .../webservice/generated/Product.java | 32 +++++++++---------- .../webservice/generated/package-info.java | 2 +- .../KeycloakTestContainers.java | 3 +- .../ProductEndpointIntegrationTest.java | 2 ++ .../spring-boot-testing/pom.xml | 4 +-- .../embeddedRedis/TestRedisConfiguration.java | 13 +++++--- .../UserRepositoryIntegrationTest.java | 21 ++++++------ 13 files changed, 103 insertions(+), 84 deletions(-) diff --git a/spring-boot-modules/pom.xml b/spring-boot-modules/pom.xml index 114286978e..3be66dc168 100644 --- a/spring-boot-modules/pom.xml +++ b/spring-boot-modules/pom.xml @@ -78,8 +78,8 @@ spring-boot-swagger-jwt spring-boot-swagger-keycloak spring-boot-swagger-springfox - - + spring-boot-testing + spring-boot-testing-2 spring-boot-testing-spock spring-boot-vue spring-boot-actuator diff --git a/spring-boot-modules/spring-boot-testing-2/pom.xml b/spring-boot-modules/spring-boot-testing-2/pom.xml index f684d7ce97..48a7c90b0a 100644 --- a/spring-boot-modules/spring-boot-testing-2/pom.xml +++ b/spring-boot-modules/spring-boot-testing-2/pom.xml @@ -78,14 +78,21 @@ ${testcontainers-redis-junit-jupiter.version} test + + io.rest-assured + rest-assured + ${rest-assured.version} + test + + - org.jvnet.jaxb2.maven2 - maven-jaxb2-plugin - ${maven-jaxb2-plugin.version} + org.jvnet.jaxb + jaxb-maven-plugin + 4.0.0 xjc @@ -107,11 +114,12 @@ com.baeldung.boot.Application - 3.1.3 - 1.17.2 - 1.10.0 + 4.0.10 + 1.19.7 + 3.3.0 1.4.6 - 0.15.1 + 0.15.3 + 5.4.0 \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/webservice/ProductEndpoint.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/webservice/ProductEndpoint.java index c3ba5c04a8..16b976b152 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/webservice/ProductEndpoint.java +++ b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/webservice/ProductEndpoint.java @@ -1,21 +1,23 @@ package com.baeldung.webservice; -import com.baeldung.webservice.generated.GetProductRequest; -import com.baeldung.webservice.generated.GetProductResponse; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.ws.server.endpoint.annotation.Endpoint; import org.springframework.ws.server.endpoint.annotation.PayloadRoot; import org.springframework.ws.server.endpoint.annotation.RequestPayload; import org.springframework.ws.server.endpoint.annotation.ResponsePayload; +import com.baeldung.webservice.generated.GetProductRequest; +import com.baeldung.webservice.generated.GetProductResponse; + @Endpoint public class ProductEndpoint { private static final String NAMESPACE_URI = "http://baeldung.com/spring-boot-web-service"; - @Autowired - private ProductRepository productRepository; + private final ProductRepository productRepository; + public ProductEndpoint(ProductRepository productRepository) { + this.productRepository = productRepository; + } @PayloadRoot(namespace = NAMESPACE_URI, localPart = "getProductRequest") @ResponsePayload diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/webservice/generated/GetProductRequest.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/webservice/generated/GetProductRequest.java index d04302456b..f6b48af278 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/webservice/generated/GetProductRequest.java +++ b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/webservice/generated/GetProductRequest.java @@ -1,11 +1,11 @@ package com.baeldung.webservice.generated; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlElement; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; /** @@ -13,17 +13,17 @@ import javax.xml.bind.annotation.XmlType; * *

The following schema fragment specifies the expected content contained within this class. * - *

- * <complexType>
- *   <complexContent>
- *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *       <sequence>
- *         <element name="id" type="{http://www.w3.org/2001/XMLSchema}string"/>
- *       </sequence>
- *     </restriction>
- *   </complexContent>
- * </complexType>
- * 
+ *
{@code
+ * 
+ *   
+ *     
+ *       
+ *         
+ *       
+ *     
+ *   
+ * 
+ * }
* * */ diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/webservice/generated/GetProductResponse.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/webservice/generated/GetProductResponse.java index f8fcaa094f..a2360d83eb 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/webservice/generated/GetProductResponse.java +++ b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/webservice/generated/GetProductResponse.java @@ -1,11 +1,11 @@ package com.baeldung.webservice.generated; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlElement; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; /** @@ -13,17 +13,17 @@ import javax.xml.bind.annotation.XmlType; * *

The following schema fragment specifies the expected content contained within this class. * - *

- * <complexType>
- *   <complexContent>
- *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *       <sequence>
- *         <element name="product" type="{http://baeldung.com/spring-boot-web-service}product"/>
- *       </sequence>
- *     </restriction>
- *   </complexContent>
- * </complexType>
- * 
+ *
{@code
+ * 
+ *   
+ *     
+ *       
+ *         
+ *       
+ *     
+ *   
+ * 
+ * }
* * */ diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/webservice/generated/ObjectFactory.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/webservice/generated/ObjectFactory.java index 015ecc3f0a..e5877dd20b 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/webservice/generated/ObjectFactory.java +++ b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/webservice/generated/ObjectFactory.java @@ -1,7 +1,7 @@ package com.baeldung.webservice.generated; -import javax.xml.bind.annotation.XmlRegistry; +import jakarta.xml.bind.annotation.XmlRegistry; /** @@ -32,6 +32,8 @@ public class ObjectFactory { /** * Create an instance of {@link GetProductRequest } * + * @return + * the new instance of {@link GetProductRequest } */ public GetProductRequest createGetProductRequest() { return new GetProductRequest(); @@ -40,6 +42,8 @@ public class ObjectFactory { /** * Create an instance of {@link GetProductResponse } * + * @return + * the new instance of {@link GetProductResponse } */ public GetProductResponse createGetProductResponse() { return new GetProductResponse(); @@ -48,6 +52,8 @@ public class ObjectFactory { /** * Create an instance of {@link Product } * + * @return + * the new instance of {@link Product } */ public Product createProduct() { return new Product(); diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/webservice/generated/Product.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/webservice/generated/Product.java index 5957aa44b4..f1d62d1489 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/webservice/generated/Product.java +++ b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/webservice/generated/Product.java @@ -1,10 +1,10 @@ package com.baeldung.webservice.generated; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlType; +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlElement; +import jakarta.xml.bind.annotation.XmlType; /** @@ -12,18 +12,18 @@ import javax.xml.bind.annotation.XmlType; * *

The following schema fragment specifies the expected content contained within this class. * - *

- * <complexType name="product">
- *   <complexContent>
- *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *       <sequence>
- *         <element name="id" type="{http://www.w3.org/2001/XMLSchema}string"/>
- *         <element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/>
- *       </sequence>
- *     </restriction>
- *   </complexContent>
- * </complexType>
- * 
+ *
{@code
+ * 
+ *   
+ *     
+ *       
+ *         
+ *         
+ *       
+ *     
+ *   
+ * 
+ * }
* * */ diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/webservice/generated/package-info.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/webservice/generated/package-info.java index 298ae9374b..fa8f2aeec5 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/webservice/generated/package-info.java +++ b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/webservice/generated/package-info.java @@ -1,2 +1,2 @@ -@javax.xml.bind.annotation.XmlSchema(namespace = "http://baeldung.com/spring-boot-web-service", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) +@jakarta.xml.bind.annotation.XmlSchema(namespace = "http://baeldung.com/spring-boot-web-service", elementFormDefault = jakarta.xml.bind.annotation.XmlNsForm.QUALIFIED) package com.baeldung.webservice.generated; diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/keycloaktestcontainers/KeycloakTestContainers.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/keycloaktestcontainers/KeycloakTestContainers.java index 2a50a646c5..d68fae9cb5 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/keycloaktestcontainers/KeycloakTestContainers.java +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/keycloaktestcontainers/KeycloakTestContainers.java @@ -4,8 +4,6 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.Collections; -import javax.annotation.PostConstruct; - import org.apache.http.client.utils.URIBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -23,6 +21,7 @@ import org.springframework.web.reactive.function.client.WebClient; import dasniko.testcontainers.keycloak.KeycloakContainer; import io.restassured.RestAssured; +import jakarta.annotation.PostConstruct; @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) public abstract class KeycloakTestContainers { diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/webservice/ProductEndpointIntegrationTest.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/webservice/ProductEndpointIntegrationTest.java index edd15090b8..0d58cfde17 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/webservice/ProductEndpointIntegrationTest.java +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/webservice/ProductEndpointIntegrationTest.java @@ -15,6 +15,7 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.webservices.server.WebServiceServerTest; import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.ComponentScan; import org.springframework.core.io.ClassPathResource; import org.springframework.ws.test.server.MockWebServiceClient; import org.springframework.xml.transform.StringSource; @@ -22,6 +23,7 @@ import org.springframework.xml.transform.StringSource; import com.baeldung.webservice.generated.Product; @WebServiceServerTest +@ComponentScan("com.baeldung.webservice") class ProductEndpointIntegrationTest { private static final Map NAMESPACE_MAPPING = createMapping(); diff --git a/spring-boot-modules/spring-boot-testing/pom.xml b/spring-boot-modules/spring-boot-testing/pom.xml index 7643183fcb..28ce90d8ec 100644 --- a/spring-boot-modules/spring-boot-testing/pom.xml +++ b/spring-boot-modules/spring-boot-testing/pom.xml @@ -50,7 +50,7 @@ - it.ozimov + com.github.codemonstur embedded-redis ${embedded-redis.version} test @@ -114,7 +114,7 @@ 2.2.4 2.4-M1-groovy-4.0 3.0.0 - 0.7.2 + 1.4.2 \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/boot/embeddedRedis/TestRedisConfiguration.java b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/boot/embeddedRedis/TestRedisConfiguration.java index 10e5d56857..f0ac4be194 100644 --- a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/boot/embeddedRedis/TestRedisConfiguration.java +++ b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/boot/embeddedRedis/TestRedisConfiguration.java @@ -1,18 +1,21 @@ package com.baeldung.boot.embeddedRedis; -import com.baeldung.boot.embeddedRedis.configuration.RedisProperties; +import java.io.IOException; + import org.springframework.boot.test.context.TestConfiguration; -import redis.embedded.RedisServer; + +import com.baeldung.boot.embeddedRedis.configuration.RedisProperties; import jakarta.annotation.PostConstruct; import jakarta.annotation.PreDestroy; +import redis.embedded.RedisServer; @TestConfiguration public class TestRedisConfiguration { private final RedisServer redisServer; - public TestRedisConfiguration(final RedisProperties redisProperties) { + public TestRedisConfiguration(final RedisProperties redisProperties) throws IOException { this.redisServer = new RedisServer(redisProperties.getRedisPort()); //Uncomment below if running on windows and can't start redis server // this.redisServer = RedisServer.builder().setting("maxheap 200m").port(6379).setting("bind localhost").build(); @@ -20,12 +23,12 @@ public class TestRedisConfiguration { } @PostConstruct - public void postConstruct() { + public void postConstruct() throws IOException { redisServer.start(); } @PreDestroy - public void preDestroy() { + public void preDestroy() throws IOException { redisServer.stop(); } } diff --git a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/boot/embeddedRedis/domain/repository/UserRepositoryIntegrationTest.java b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/boot/embeddedRedis/domain/repository/UserRepositoryIntegrationTest.java index 9577ccf0e8..331801cc0a 100644 --- a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/boot/embeddedRedis/domain/repository/UserRepositoryIntegrationTest.java +++ b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/boot/embeddedRedis/domain/repository/UserRepositoryIntegrationTest.java @@ -1,26 +1,25 @@ package com.baeldung.boot.embeddedRedis.domain.repository; -import com.baeldung.boot.embeddedRedis.TestRedisConfiguration; -import com.baeldung.boot.embeddedRedis.domain.User; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.util.UUID; -import static org.junit.Assert.assertNotNull; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import com.baeldung.boot.embeddedRedis.TestRedisConfiguration; +import com.baeldung.boot.embeddedRedis.domain.User; + -@RunWith(SpringRunner.class) @SpringBootTest(classes = TestRedisConfiguration.class) -public class UserRepositoryIntegrationTest { +class UserRepositoryIntegrationTest { @Autowired private UserRepository userRepository; @Test - public void shouldSaveUser_toRedis() { + void shouldSaveUser_toRedis() { final UUID id = UUID.randomUUID(); final User user = new User(id, "name");