Closed
Description
I tried to update my example projects to the latest Spring 6.1.x, Spring Boot 3.2 and Java 21.
The Spring Data ElasticSearch example failed, the example source codes is here, https://github.com/hantsy/spring6-sandbox/tree/master/boot-data-elasticsearch
@Document(indexName = "products")
public record Product(@Id String id, String name, BigDecimal price) {
}
And test is like :
@DataElasticsearchTest
@Testcontainers
@Slf4j
public class ElasticsearchIntegrationTests {
@Container
@ServiceConnection
public static ElasticsearchContainer ES_CONTAINER = new ElasticsearchContainer("docker.elastic.co/elasticsearch/elasticsearch:7.17.9");
@Autowired
private ProductRepository productRepository;
@Test
void testDatabaseIsRunning() {
assertThat(ES_CONTAINER.isRunning()).isTrue();
}
@Test
public void testProductRepository() {
var product = productRepository.save(new Product(null, "test", BigDecimal.ONE));
assertThat(product).isNotNull();
assertThat(product.id()).isNotNull();
productRepository.findById(product.id()).ifPresent(
p -> {
log.debug("found product by id: {}", p);
assertThat(p.name()).isEqualTo("test");
}
);
}
}
And got the following error.
2023-09-24T20:38:24.405+08:00 DEBUG 17172 --- [ main] .c.s.DirtiesContextTestExecutionListener : After test method: class [ElasticsearchIntegrationTests], method [testProductRepository], class annotated with @DirtiesContext [false] with mode [null], method annotated with @DirtiesContext [false] with mode [null]
java.lang.AssertionError:
Expecting actual not to be null
at com.example.demo.ElasticsearchIntegrationTests.testProductRepository(ElasticsearchIntegrationTests.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
It means the entity id is not filled as expected
.
This example worked with Spring Boot 3.1.x and Java 17.