committed by
Greg L. Turnquist
parent
b043239eb2
commit
13c0dea55c
@@ -1 +0,0 @@
|
||||
#spring.elasticsearch.rest.uris=http://localhost:9200
|
||||
12
elasticsearch/example/src/main/resources/log4j2.xml
Normal file
12
elasticsearch/example/src/main/resources/log4j2.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<Configuration status="INFO">
|
||||
<Appenders>
|
||||
<Console name="LogToConsole" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="info">
|
||||
<AppenderRef ref="LogToConsole"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
@@ -17,8 +17,6 @@ package example.springdata.elasticsearch.conference;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import example.springdata.elasticsearch.util.EnabledOnElasticsearch;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
@@ -27,12 +25,17 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||
import org.springframework.data.elasticsearch.core.SearchHit;
|
||||
import org.springframework.data.elasticsearch.core.SearchHits;
|
||||
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||
import org.springframework.data.elasticsearch.core.query.Criteria;
|
||||
import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
|
||||
import org.springframework.test.context.DynamicPropertyRegistry;
|
||||
import org.springframework.test.context.DynamicPropertySource;
|
||||
|
||||
import org.testcontainers.elasticsearch.ElasticsearchContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
import org.testcontainers.utility.DockerImageName;
|
||||
|
||||
/**
|
||||
* Test case to show Spring Data Elasticsearch functionality.
|
||||
@@ -43,13 +46,25 @@ import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
|
||||
* @author Prakhar Gupta
|
||||
*/
|
||||
@SpringBootTest(classes = ApplicationConfiguration.class)
|
||||
@EnabledOnElasticsearch
|
||||
@Testcontainers
|
||||
class ElasticsearchOperationsTest {
|
||||
|
||||
private static final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
@Autowired
|
||||
ElasticsearchOperations operations;
|
||||
@Container //
|
||||
private static ElasticsearchContainer container = new ElasticsearchContainer(
|
||||
DockerImageName.parse("docker.elastic.co/elasticsearch/elasticsearch:7.17.2")) //
|
||||
.withPassword("foobar") //
|
||||
.withReuse(true);
|
||||
|
||||
@DynamicPropertySource
|
||||
static void setProperties(DynamicPropertyRegistry registry) {
|
||||
registry.add("spring.elasticsearch.uris", () -> "http://" + container.getHttpHostAddress());
|
||||
registry.add("spring.elasticsearch.username", () -> "elastic");
|
||||
registry.add("spring.elasticsearch.password", () -> "foobar");
|
||||
}
|
||||
|
||||
@Autowired ElasticsearchOperations operations;
|
||||
|
||||
@Test
|
||||
void textSearch() throws ParseException {
|
||||
|
||||
Reference in New Issue
Block a user