Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jupiter-tools/spring-test-elasticsearch

Tools to start Elasticsearch in docker containers for tests with Spring
https://github.com/jupiter-tools/spring-test-elasticsearch

Last synced: 15 days ago
JSON representation

Tools to start Elasticsearch in docker containers for tests with Spring

Awesome Lists containing this project

README

        

# Spring Test Elasticsearch

image:https://codecov.io/gh/jupiter-tools/spring-test-elasticsearch/branch/master/graph/badge.svg["", link="https://codecov.io/gh/jupiter-tools/spring-test-elasticsearch"]

Tools to write integration tests of Spring Framework with the Elasticsearch.

## How to write integration tests on Spring Boot with Elasticsearch in docker

Add this library in dependencies:

[source,xml]
----

com.jupiter-tools
spring-test-elasticsearch
0.1

----

Now, you can start the Elasticsearch cluster in a docker container(TestContainers) by the using of `@ElasticsearchTestContainer` annotation in tests:

[source,java]
----
@ElasticsearchTestContainer
@SpringBootTest
class SpTestElasticTestAppApplicationTests {

@Autowired
private ElasticsearchTemplate elasticsearchTemplate;

@BeforeAll
static void setUp() {
// populate a data set in index
}

@Test
void findTest() {
var query = GetQuery.getById("100123");
Foo foo = elasticsearchTemplate.queryForObject(query, Foo.class);
assertThat(foo).isNotNull();
}
}
----