@@ -50,7 +50,7 @@ class ApplicationConfiguration {
|
||||
|
||||
// Save data sample
|
||||
|
||||
List<Conference> documents = Arrays.asList(
|
||||
var documents = Arrays.asList(
|
||||
Conference.builder().date("2014-11-06").name("Spring eXchange 2014 - London")
|
||||
.keywords(Arrays.asList("java", "spring")).location(new GeoPoint(51.500152D, -0.126236D)).build(), //
|
||||
Conference.builder().date("2014-12-07").name("Scala eXchange 2014 - London")
|
||||
|
||||
@@ -54,16 +54,16 @@ class ElasticsearchOperationsTest {
|
||||
@Test
|
||||
void textSearch() throws ParseException {
|
||||
|
||||
String expectedDate = "2014-10-29";
|
||||
String expectedWord = "java";
|
||||
CriteriaQuery query = new CriteriaQuery(
|
||||
var expectedDate = "2014-10-29";
|
||||
var expectedWord = "java";
|
||||
var query = new CriteriaQuery(
|
||||
new Criteria("keywords").contains(expectedWord).and(new Criteria("date").greaterThanEqual(expectedDate)));
|
||||
|
||||
SearchHits<Conference> result = operations.search(query, Conference.class, IndexCoordinates.of("conference-index"));
|
||||
var result = operations.search(query, Conference.class, IndexCoordinates.of("conference-index"));
|
||||
|
||||
assertThat(result).hasSize(3);
|
||||
|
||||
for (SearchHit<Conference> conference : result) {
|
||||
for (var conference : result) {
|
||||
assertThat(conference.getContent().getKeywords()).contains(expectedWord);
|
||||
assertThat(format.parse(conference.getContent().getDate())).isAfter(format.parse(expectedDate));
|
||||
}
|
||||
@@ -72,11 +72,11 @@ class ElasticsearchOperationsTest {
|
||||
@Test
|
||||
void geoSpatialSearch() {
|
||||
|
||||
GeoPoint startLocation = new GeoPoint(50.0646501D, 19.9449799D);
|
||||
String range = "330mi"; // or 530km
|
||||
CriteriaQuery query = new CriteriaQuery(new Criteria("location").within(startLocation, range));
|
||||
var startLocation = new GeoPoint(50.0646501D, 19.9449799D);
|
||||
var range = "330mi"; // or 530km
|
||||
var query = new CriteriaQuery(new Criteria("location").within(startLocation, range));
|
||||
|
||||
SearchHits<Conference> result = operations.search(query, Conference.class, IndexCoordinates.of("conference-index"));
|
||||
var result = operations.search(query, Conference.class, IndexCoordinates.of("conference-index"));
|
||||
|
||||
assertThat(result).hasSize(2);
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ class ApplicationConfiguration {
|
||||
// just ignore it
|
||||
}
|
||||
|
||||
List<Conference> documents = Arrays.asList(
|
||||
var documents = Arrays.asList(
|
||||
Conference.builder().date("2014-11-06").name("Spring eXchange 2014 - London")
|
||||
.keywords(Arrays.asList("java", "spring")).location(new GeoPoint(51.500152D, -0.126236D)).build(), //
|
||||
Conference.builder().date("2014-12-07").name("Scala eXchange 2014 - London")
|
||||
|
||||
@@ -50,9 +50,9 @@ class ReactiveElasticsearchOperationsTest {
|
||||
@Test
|
||||
void textSearch() {
|
||||
|
||||
String expectedDate = "2014-10-29";
|
||||
String expectedWord = "java";
|
||||
CriteriaQuery query = new CriteriaQuery(
|
||||
var expectedDate = "2014-10-29";
|
||||
var expectedWord = "java";
|
||||
var query = new CriteriaQuery(
|
||||
new Criteria("keywords").contains(expectedWord).and("date").greaterThanEqual(expectedDate));
|
||||
|
||||
operations.search(query, Conference.class) //
|
||||
|
||||
@@ -46,8 +46,8 @@ class ReactiveElasticsearchRepositoryTest {
|
||||
@Test
|
||||
void textSearch() {
|
||||
|
||||
String expectedDate = "2014-10-29";
|
||||
String expectedWord = "java";
|
||||
var expectedDate = "2014-10-29";
|
||||
var expectedWord = "java";
|
||||
|
||||
repository.findAllByKeywordsContainsAndDateAfter(expectedWord, expectedDate) //
|
||||
.as(StepVerifier::create) //
|
||||
|
||||
@@ -15,15 +15,12 @@
|
||||
*/
|
||||
package example.springdata.elasticsearch.util;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
|
||||
import org.junit.jupiter.api.extension.ExecutionCondition;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
import org.junit.platform.commons.support.AnnotationSupport;
|
||||
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
@@ -37,7 +34,7 @@ class ElasticsearchAvailableCondition implements ExecutionCondition {
|
||||
@Override
|
||||
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext extensionContext) {
|
||||
|
||||
Optional<EnabledOnElasticsearch> annotation = AnnotationSupport.findAnnotation(extensionContext.getElement(),
|
||||
var annotation = AnnotationSupport.findAnnotation(extensionContext.getElement(),
|
||||
EnabledOnElasticsearch.class);
|
||||
|
||||
return annotation.map(EnabledOnElasticsearch::url) //
|
||||
@@ -47,10 +44,10 @@ class ElasticsearchAvailableCondition implements ExecutionCondition {
|
||||
|
||||
private static ConditionEvaluationResult checkServerRunning(String url) {
|
||||
|
||||
RestTemplate template = new RestTemplate();
|
||||
var template = new RestTemplate();
|
||||
|
||||
try {
|
||||
ResponseEntity<byte[]> entity = template.exchange(url, HttpMethod.HEAD, null, byte[].class);
|
||||
var entity = template.exchange(url, HttpMethod.HEAD, null, byte[].class);
|
||||
return ConditionEvaluationResult
|
||||
.enabled("Successfully connected to Elasticsearch server: " + entity.getStatusCode());
|
||||
} catch (RuntimeException e) {
|
||||
|
||||
Reference in New Issue
Block a user