JAVA-31544: migrate spring-boot-testing and spring-boot-testing-2 to sb3 (#16182)

This commit is contained in:
Harry9656 2024-03-22 00:32:58 +01:00 committed by GitHub
parent 0248e55803
commit a30907a9ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 103 additions and 84 deletions

View File

@ -78,8 +78,8 @@
<module>spring-boot-swagger-jwt</module>
<module>spring-boot-swagger-keycloak</module>
<module>spring-boot-swagger-springfox</module>
<!-- <module>spring-boot-testing</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<!-- <module>spring-boot-testing-2</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<module>spring-boot-testing</module>
<module>spring-boot-testing-2</module>
<module>spring-boot-testing-spock</module>
<module>spring-boot-vue</module>
<module>spring-boot-actuator</module>

View File

@ -78,14 +78,21 @@
<version>${testcontainers-redis-junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>${rest-assured.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>${maven-jaxb2-plugin.version}</version>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-maven-plugin</artifactId>
<version>4.0.0</version>
<executions>
<execution>
<id>xjc</id>
@ -107,11 +114,12 @@
<properties>
<start-class>com.baeldung.boot.Application</start-class>
<spring-ws-test.version>3.1.3</spring-ws-test.version>
<testcontainers.version>1.17.2</testcontainers.version>
<testcontainers-keycloak.version>1.10.0</testcontainers-keycloak.version>
<spring-ws-test.version>4.0.10</spring-ws-test.version>
<testcontainers.version>1.19.7</testcontainers.version>
<testcontainers-keycloak.version>3.3.0</testcontainers-keycloak.version>
<testcontainers-redis-junit-jupiter.version>1.4.6</testcontainers-redis-junit-jupiter.version>
<maven-jaxb2-plugin.version>0.15.1</maven-jaxb2-plugin.version>
<maven-jaxb2-plugin.version>0.15.3</maven-jaxb2-plugin.version>
<rest-assured.version>5.4.0</rest-assured.version>
</properties>
</project>

View File

@ -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

View File

@ -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;
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType&gt;
* &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;sequence&gt;
* &lt;element name="id" type="{http://www.w3.org/2001/XMLSchema}string"/&gt;
* &lt;/sequence&gt;
* &lt;/restriction&gt;
* &lt;/complexContent&gt;
* &lt;/complexType&gt;
* </pre>
* <pre>{@code
* <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>
* }</pre>
*
*
*/

View File

@ -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;
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType&gt;
* &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;sequence&gt;
* &lt;element name="product" type="{http://baeldung.com/spring-boot-web-service}product"/&gt;
* &lt;/sequence&gt;
* &lt;/restriction&gt;
* &lt;/complexContent&gt;
* &lt;/complexType&gt;
* </pre>
* <pre>{@code
* <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>
* }</pre>
*
*
*/

View File

@ -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();

View File

@ -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;
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="product"&gt;
* &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;sequence&gt;
* &lt;element name="id" type="{http://www.w3.org/2001/XMLSchema}string"/&gt;
* &lt;element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/&gt;
* &lt;/sequence&gt;
* &lt;/restriction&gt;
* &lt;/complexContent&gt;
* &lt;/complexType&gt;
* </pre>
* <pre>{@code
* <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>
* }</pre>
*
*
*/

View File

@ -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;

View File

@ -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 {

View File

@ -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<String, String> NAMESPACE_MAPPING = createMapping();

View File

@ -50,7 +50,7 @@
</dependency>
<!-- Embedded Redis Server -->
<dependency>
<groupId>it.ozimov</groupId>
<groupId>com.github.codemonstur</groupId>
<artifactId>embedded-redis</artifactId>
<version>${embedded-redis.version}</version>
<scope>test</scope>
@ -114,7 +114,7 @@
<git-commit-id-plugin.version>2.2.4</git-commit-id-plugin.version>
<spock.version>2.4-M1-groovy-4.0</spock.version>
<gmavenplus-plugin.version>3.0.0</gmavenplus-plugin.version>
<embedded-redis.version>0.7.2</embedded-redis.version>
<embedded-redis.version>1.4.2</embedded-redis.version>
</properties>
</project>

View File

@ -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();
}
}

View File

@ -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");