JAVA-29179 Upgrade spring-data-cassandra-2 to Spring Boot 3 (#16066)

This commit is contained in:
timis1 2024-03-09 16:46:05 +02:00 committed by GitHub
parent 830c5608d8
commit 375015808d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 46 additions and 45 deletions

View File

@ -11,9 +11,9 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<artifactId>parent-boot-3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-2</relativePath>
<relativePath>../../parent-boot-3</relativePath>
</parent>
<dependencies>
@ -63,7 +63,7 @@
<dependency>
<groupId>com.datastax.oss</groupId>
<artifactId>java-driver-mapper-runtime</artifactId>
<version>4.15.0</version>
<version>4.17.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
@ -99,10 +99,11 @@
</build>
<properties>
<org.springframework.data.version>3.4.15</org.springframework.data.version>
<testcontainers.version>1.19.0</testcontainers.version>
<system.stubs.version>1.1.0</system.stubs.version>
<org.springframework.data.version>4.1.9</org.springframework.data.version>
<testcontainers.version>1.19.5</testcontainers.version>
<system.stubs.version>2.1.5</system.stubs.version>
<junit.jupiter.version>5.9.3</junit.jupiter.version>
<start-class>org.baeldung.springcassandra.SpringCassandraApplication</start-class>
</properties>
</project>

View File

@ -1,4 +1,4 @@
spring.data.cassandra.keyspace-name=${CASSANDRA_KEYSPACE_NAME}
spring.data.cassandra.contact-points=${CASSANDRA_CONTACT_POINTS}
spring.data.cassandra.port=${CASSANDRA_PORT}
spring.data.cassandra.local-datacenter=datacenter1
spring.cassandra.keyspace-name=${CASSANDRA_KEYSPACE_NAME}
spring.cassandra.contact-points=${CASSANDRA_CONTACT_POINTS}
spring.cassandra.port=${CASSANDRA_PORT}
spring.cassandra.local-datacenter=datacenter1

View File

@ -14,6 +14,8 @@ import org.testcontainers.containers.CassandraContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
@ -30,14 +32,14 @@ class ProductRepositoryNestedLiveTest {
private static final String KEYSPACE_NAME = "mynamespace";
@Container
private static final CassandraContainer cassandra = (CassandraContainer) new CassandraContainer("cassandra:3.11.2")
private static final CassandraContainer<?> cassandra = new CassandraContainer<>("cassandra:3.11.2")
.withExposedPorts(9042);
@BeforeAll
static void setupCassandraConnectionProperties() {
System.setProperty("spring.data.cassandra.keyspace-name", KEYSPACE_NAME);
System.setProperty("spring.data.cassandra.contact-points", cassandra.getHost());
System.setProperty("spring.data.cassandra.port", String.valueOf(cassandra.getMappedPort(9042)));
System.setProperty("spring.cassandra.keyspace-name", KEYSPACE_NAME);
System.setProperty("spring.cassandra.contact-points", cassandra.getHost());
System.setProperty("spring.cassandra.port", String.valueOf(cassandra.getMappedPort(9042)));
createKeyspace(cassandra.getCluster());
}
@ -72,9 +74,9 @@ class ProductRepositoryNestedLiveTest {
Product product3 = new Product(productId3, "Banana", "Banana v1", 5.5);
Product product4 = new Product(productId3, "Banana v2", "Banana v2", 15.5);
productRepository.saveAll(List.of(product1, product2, product3, product4));
productRepository.saveAll(Arrays.asList(product1, product2, product3, product4));
List<Product> existingProducts = productRepository.findByProductIds(List.of(productId1, productId2));
List<Product> existingProducts = productRepository.findByProductIds(Arrays.asList(productId1, productId2));
assertEquals(2, existingProducts.size());
assertTrue(existingProducts.contains(product1));
assertTrue(existingProducts.contains(product2));
@ -89,10 +91,10 @@ class ProductRepositoryNestedLiveTest {
Product product3 = new Product(productId2, "Banana", "Banana v1", 5.5);
Product product4 = new Product(productId2, "Banana v2", "Banana v2", 15.5);
productRepository.saveAll(List.of(product1, product2, product3, product4));
productRepository.saveAll(Arrays.asList(product1, product2, product3, product4));
List<Product> existingProducts = productRepository.findByProductIdAndNames(productId1,
List.of(product1.getProductName(), product2.getProductName()));
Arrays.asList(product1.getProductName(), product2.getProductName()));
assertEquals(2, existingProducts.size());
assertTrue(existingProducts.contains(product1));
assertTrue(existingProducts.contains(product2));
@ -107,10 +109,11 @@ class ProductRepositoryNestedLiveTest {
Product product3 = new Product(productId2, "Banana", "Banana v1", 5.5);
Product product4 = new Product(productId2, "Banana v2", "Banana v2", 15.5);
productRepository.saveAll(List.of(product1, product2, product4));
productRepository.saveAll(Arrays.asList(product1, product2, product4));
List<Product> existingProducts = productRepository.findByProductIdAndNames(productId1,
List.of(product3.getProductName()));
Collections.singletonList(product3.getProductName())
);
assertEquals(0, existingProducts.size());
}
}

View File

@ -25,13 +25,13 @@ public class MapperLiveTest {
private static final String KEYSPACE_NAME = "baeldung";
@Container
private static final CassandraContainer cassandra = (CassandraContainer) new CassandraContainer("cassandra:3.11.2").withExposedPorts(9042);
private static final CassandraContainer<?> cassandra = new CassandraContainer<>("cassandra:3.11.2").withExposedPorts(9042);
@BeforeAll
static void setupCassandraConnectionProperties() {
System.setProperty("spring.data.cassandra.keyspace-name", KEYSPACE_NAME);
System.setProperty("spring.data.cassandra.contact-points", cassandra.getHost());
System.setProperty("spring.data.cassandra.port", String.valueOf(cassandra.getMappedPort(9042)));
System.setProperty("spring.cassandra.keyspace-name", KEYSPACE_NAME);
System.setProperty("spring.cassandra.contact-points", cassandra.getHost());
System.setProperty("spring.cassandra.port", String.valueOf(cassandra.getMappedPort(9042)));
setupCassandra(new InetSocketAddress(cassandra.getHost(), cassandra.getMappedPort(9042)), cassandra.getLocalDatacenter());
}
@ -92,5 +92,4 @@ public class MapperLiveTest {
.all();
Assertions.assertEquals(1, retrievedUsers.size());
}
}

View File

@ -14,6 +14,7 @@ import org.testcontainers.containers.CassandraContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
@ -28,14 +29,14 @@ class CassandraNestedLiveTest {
private static final String KEYSPACE_NAME = "test";
@Container
private static final CassandraContainer cassandra = (CassandraContainer) new CassandraContainer("cassandra:3.11.2")
private static final CassandraContainer<?> cassandra = new CassandraContainer<>("cassandra:3.11.2")
.withExposedPorts(9042);
@BeforeAll
static void setupCassandraConnectionProperties() {
System.setProperty("spring.data.cassandra.keyspace-name", KEYSPACE_NAME);
System.setProperty("spring.data.cassandra.contact-points", cassandra.getContainerIpAddress());
System.setProperty("spring.data.cassandra.port", String.valueOf(cassandra.getMappedPort(9042)));
System.setProperty("spring.cassandra.keyspace-name", KEYSPACE_NAME);
System.setProperty("spring.cassandra.contact-points", cassandra.getContainerIpAddress());
System.setProperty("spring.cassandra.port", String.valueOf(cassandra.getMappedPort(9042)));
createKeyspace(cassandra.getCluster());
}
@ -70,7 +71,7 @@ class CassandraNestedLiveTest {
carRepository.save(newCar);
List<Car> savedCars = carRepository.findAllById(List.of(carId));
List<Car> savedCars = carRepository.findAllById(Collections.singletonList(carId));
assertThat(savedCars.get(0)).isEqualTo(newCar);
}
@ -82,7 +83,7 @@ class CassandraNestedLiveTest {
existingCar.setModel("X-Trail");
carRepository.save(existingCar);
List<Car> savedCars = carRepository.findAllById(List.of(carId));
List<Car> savedCars = carRepository.findAllById(Collections.singletonList(carId));
assertThat(savedCars.get(0).getModel()).isEqualTo("X-Trail");
}
@ -93,10 +94,8 @@ class CassandraNestedLiveTest {
carRepository.delete(existingCar);
List<Car> savedCars = carRepository.findAllById(List.of(carId));
assertThat(savedCars.isEmpty()).isTrue();
List<Car> savedCars = carRepository.findAllById(Collections.singletonList(carId));
assertThat(savedCars).isEmpty();
}
}
}

View File

@ -20,14 +20,14 @@ class CassandraSimpleLiveTest {
private static final String KEYSPACE_NAME = "test";
@Container
private static final CassandraContainer cassandra = (CassandraContainer) new CassandraContainer("cassandra:3.11.2")
private static final CassandraContainer<?> cassandra = new CassandraContainer<>("cassandra:3.11.2")
.withExposedPorts(9042);
@BeforeAll
static void setupCassandraConnectionProperties() {
System.setProperty("spring.data.cassandra.keyspace-name", KEYSPACE_NAME);
System.setProperty("spring.data.cassandra.contact-points", cassandra.getContainerIpAddress());
System.setProperty("spring.data.cassandra.port", String.valueOf(cassandra.getMappedPort(9042)));
System.setProperty("spring.cassandra.keyspace-name", KEYSPACE_NAME);
System.setProperty("spring.cassandra.contact-points", cassandra.getContainerIpAddress());
System.setProperty("spring.cassandra.port", String.valueOf(cassandra.getMappedPort(9042)));
createKeyspace(cassandra.getCluster());
}
@ -43,5 +43,4 @@ class CassandraSimpleLiveTest {
void givenCassandraContainer_whenSpringContextIsBootstrapped_thenContainerIsRunningWithNoExceptions() {
assertThat(cassandra.isRunning()).isTrue();
}
}

View File

@ -1,5 +1,5 @@
spring.data.cassandra.keyspace-name=${CASSANDRA_KEYSPACE_NAME}
spring.data.cassandra.contact-points=${CASSANDRA_CONTACT_POINTS}
spring.data.cassandra.port=${CASSANDRA_PORT}
spring.data.cassandra.local-datacenter=datacenter1
spring.data.cassandra.schema-action=create_if_not_exists
spring.cassandra.keyspace-name=${CASSANDRA_KEYSPACE_NAME}
spring.cassandra.contact-points=${CASSANDRA_CONTACT_POINTS}
spring.cassandra.port=${CASSANDRA_PORT}
spring.cassandra.local-datacenter=datacenter1
spring.cassandra.schema-action=create_if_not_exists