diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataConfiguration.java index 91f2e841118..653796e03e5 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,15 +27,11 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient; -import org.springframework.data.elasticsearch.core.DefaultEntityMapper; -import org.springframework.data.elasticsearch.core.DefaultResultMapper; import org.springframework.data.elasticsearch.core.ElasticsearchOperations; import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate; import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; -import org.springframework.data.elasticsearch.core.EntityMapper; import org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations; import org.springframework.data.elasticsearch.core.ReactiveElasticsearchTemplate; -import org.springframework.data.elasticsearch.core.ResultsMapper; import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter; import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter; import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext; @@ -48,6 +44,7 @@ import org.springframework.web.reactive.function.client.WebClient; * their order of execution. * * @author Brian Clozel + * @author Scott Frederick */ abstract class ElasticsearchDataConfiguration { @@ -66,18 +63,6 @@ abstract class ElasticsearchDataConfiguration { return new SimpleElasticsearchMappingContext(); } - @Bean - @ConditionalOnMissingBean - EntityMapper entityMapper(SimpleElasticsearchMappingContext mappingContext) { - return new DefaultEntityMapper(mappingContext); - } - - @Bean - @ConditionalOnMissingBean - ResultsMapper resultsMapper(SimpleElasticsearchMappingContext mappingContext, EntityMapper entityMapper) { - return new DefaultResultMapper(mappingContext, entityMapper); - } - } @Configuration(proxyBeanMethods = false) @@ -87,9 +72,8 @@ abstract class ElasticsearchDataConfiguration { @Bean @ConditionalOnMissingBean(value = ElasticsearchOperations.class, name = "elasticsearchTemplate") @ConditionalOnBean(RestHighLevelClient.class) - ElasticsearchRestTemplate elasticsearchTemplate(RestHighLevelClient client, ElasticsearchConverter converter, - ResultsMapper resultsMapper) { - return new ElasticsearchRestTemplate(client, converter, resultsMapper); + ElasticsearchRestTemplate elasticsearchTemplate(RestHighLevelClient client, ElasticsearchConverter converter) { + return new ElasticsearchRestTemplate(client, converter); } } @@ -101,10 +85,10 @@ abstract class ElasticsearchDataConfiguration { @Bean @ConditionalOnMissingBean(value = ElasticsearchOperations.class, name = "elasticsearchTemplate") @ConditionalOnBean(Client.class) - ElasticsearchTemplate elasticsearchTemplate(Client client, ElasticsearchConverter converter, - ResultsMapper resultsMapper) { + @Deprecated + ElasticsearchTemplate elasticsearchTemplate(Client client, ElasticsearchConverter converter) { try { - return new ElasticsearchTemplate(client, converter, resultsMapper); + return new ElasticsearchTemplate(client, converter); } catch (Exception ex) { throw new IllegalStateException(ex); @@ -121,9 +105,8 @@ abstract class ElasticsearchDataConfiguration { @ConditionalOnMissingBean(value = ReactiveElasticsearchOperations.class, name = "reactiveElasticsearchTemplate") @ConditionalOnBean(ReactiveElasticsearchClient.class) ReactiveElasticsearchTemplate reactiveElasticsearchTemplate(ReactiveElasticsearchClient client, - ElasticsearchConverter converter, ResultsMapper resultsMapper) { - ReactiveElasticsearchTemplate template = new ReactiveElasticsearchTemplate(client, converter, - resultsMapper); + ElasticsearchConverter converter) { + ReactiveElasticsearchTemplate template = new ReactiveElasticsearchTemplate(client, converter); template.setIndicesOptions(IndicesOptions.strictExpandOpenAndForbidClosed()); template.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); return template; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfigurationTests.java index 1610d8cbbdc..7d9382602a3 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,8 +47,8 @@ import static org.mockito.Mockito.mock; class ElasticsearchAutoConfigurationTests { @Container - public static ElasticsearchContainer elasticsearch = new ElasticsearchContainer().withStartupAttempts(5) - .withStartupTimeout(Duration.ofMinutes(10)); + public static ElasticsearchContainer elasticsearch = new VersionOverridingElasticsearchContainer() + .withStartupAttempts(5).withStartupTimeout(Duration.ofMinutes(10)); private AnnotationConfigApplicationContext context; @@ -76,6 +76,7 @@ class ElasticsearchAutoConfigurationTests { } @Test + @SuppressWarnings("deprecation") void createTransportClient() { this.context = new AnnotationConfigApplicationContext(); TestPropertyValues diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfigurationTests.java index 074af93e03b..b957169c04f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,10 +30,8 @@ import org.springframework.boot.autoconfigure.elasticsearch.rest.RestClientAutoC import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.data.elasticsearch.core.ElasticsearchEntityMapper; import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate; import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; -import org.springframework.data.elasticsearch.core.EntityMapper; import org.springframework.data.elasticsearch.core.ReactiveElasticsearchTemplate; import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter; import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext; @@ -48,12 +46,13 @@ import static org.mockito.Mockito.mock; * @author Artur Konczak * @author Brian Clozel * @author Peter-Josef Meisch + * @author Scott Frederick */ @Testcontainers(disabledWithoutDocker = true) class ElasticsearchDataAutoConfigurationTests { @Container - static ElasticsearchContainer elasticsearch = new ElasticsearchContainer().withStartupAttempts(5) + static ElasticsearchContainer elasticsearch = new VersionOverridingElasticsearchContainer().withStartupAttempts(5) .withStartupTimeout(Duration.ofMinutes(10)); private ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration( @@ -71,6 +70,7 @@ class ElasticsearchDataAutoConfigurationTests { } @Test + @SuppressWarnings("deprecation") void defaultTransportBeansAreRegistered() { this.contextRunner .withPropertyValues( @@ -83,6 +83,7 @@ class ElasticsearchDataAutoConfigurationTests { } @Test + @SuppressWarnings("deprecation") void defaultTransportBeansNotRegisteredIfNoTransportClient() { this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(ElasticsearchTemplate.class)); } @@ -91,16 +92,11 @@ class ElasticsearchDataAutoConfigurationTests { void defaultRestBeansRegistered() { this.contextRunner.run((context) -> assertThat(context).hasSingleBean(ElasticsearchRestTemplate.class) .hasSingleBean(ReactiveElasticsearchTemplate.class).hasSingleBean(ElasticsearchConverter.class) - .hasSingleBean(SimpleElasticsearchMappingContext.class).hasSingleBean(EntityMapper.class) .hasSingleBean(ElasticsearchConverter.class)); } @Test - void defaultEntityMapperRegistered() { - this.contextRunner.run((context) -> assertThat(context).hasSingleBean(EntityMapper.class)); - } - - @Test + @SuppressWarnings("deprecation") void customTransportTemplateShouldBeUsed() { this.contextRunner.withUserConfiguration(CustomTransportTemplate.class).run((context) -> assertThat(context) .getBeanNames(ElasticsearchTemplate.class).hasSize(1).contains("elasticsearchTemplate")); @@ -119,16 +115,11 @@ class ElasticsearchDataAutoConfigurationTests { .contains("reactiveElasticsearchTemplate")); } - @Test - void customEntityMapperShouldeBeUsed() { - this.contextRunner.withUserConfiguration(CustomEntityMapper.class).run((context) -> assertThat(context) - .getBeanNames(EntityMapper.class).containsExactly("elasticsearchEntityMapper")); - } - @Configuration(proxyBeanMethods = false) static class CustomTransportTemplate { @Bean + @SuppressWarnings("deprecation") ElasticsearchTemplate elasticsearchTemplate() { return mock(ElasticsearchTemplate.class); } @@ -155,14 +146,4 @@ class ElasticsearchDataAutoConfigurationTests { } - @Configuration(proxyBeanMethods = false) - static class CustomEntityMapper { - - @Bean - EntityMapper elasticsearchEntityMapper() { - return mock(ElasticsearchEntityMapper.class); - } - - } - } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchRepositoriesAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchRepositoriesAutoConfigurationTests.java index 1dc47256631..dd53c7dff8a 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchRepositoriesAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchRepositoriesAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,8 +48,8 @@ import static org.assertj.core.api.Assertions.assertThat; class ElasticsearchRepositoriesAutoConfigurationTests { @Container - static final ElasticsearchContainer elasticsearch = new ElasticsearchContainer().withStartupAttempts(5) - .withStartupTimeout(Duration.ofMinutes(10)); + static final ElasticsearchContainer elasticsearch = new VersionOverridingElasticsearchContainer() + .withStartupAttempts(5).withStartupTimeout(Duration.ofMinutes(10)); private ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration( diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveElasticsearchRepositoriesAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveElasticsearchRepositoriesAutoConfigurationTests.java index a98e98e8502..cccf59b44aa 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveElasticsearchRepositoriesAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveElasticsearchRepositoriesAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,7 +47,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class ReactiveElasticsearchRepositoriesAutoConfigurationTests { @Container - static ElasticsearchContainer elasticsearch = new ElasticsearchContainer().withStartupAttempts(5) + static ElasticsearchContainer elasticsearch = new VersionOverridingElasticsearchContainer().withStartupAttempts(5) .withStartupTimeout(Duration.ofMinutes(10)); private ApplicationContextRunner contextRunner = new ApplicationContextRunner() diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveRestClientAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveRestClientAutoConfigurationTests.java index 614c598ae7f..1e404f32b90 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveRestClientAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveRestClientAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,7 +47,7 @@ import static org.mockito.Mockito.mock; public class ReactiveRestClientAutoConfigurationTests { @Container - static ElasticsearchContainer elasticsearch = new ElasticsearchContainer().withStartupAttempts(5) + static ElasticsearchContainer elasticsearch = new VersionOverridingElasticsearchContainer().withStartupAttempts(5) .withStartupTimeout(Duration.ofMinutes(10)); private ApplicationContextRunner contextRunner = new ApplicationContextRunner() @@ -83,9 +83,10 @@ public class ReactiveRestClientAutoConfigurationTests { Map source = new HashMap<>(); source.put("a", "alpha"); source.put("b", "bravo"); - IndexRequest index = new IndexRequest("foo", "bar", "1").source(source); - GetRequest getRequest = new GetRequest("foo", "bar", "1"); - GetResult getResult = client.index(index).then(client.get(getRequest)).block(); + IndexRequest indexRequest = new IndexRequest("foo").id("1").source(source); + GetRequest getRequest = new GetRequest("foo").id("1"); + GetResult getResult = client.index(indexRequest).then(client.get(getRequest)).block(); + assertThat(getResult).isNotNull(); assertThat(getResult.isExists()).isTrue(); }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/VersionOverridingElasticsearchContainer.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/VersionOverridingElasticsearchContainer.java new file mode 100644 index 00000000000..441cf1547d0 --- /dev/null +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/VersionOverridingElasticsearchContainer.java @@ -0,0 +1,41 @@ +/* + * Copyright 2012-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.boot.autoconfigure.data.elasticsearch; + +import org.testcontainers.elasticsearch.ElasticsearchContainer; + +/** + * Extension of {@link ElasticsearchContainer} to override default version. + * + * @author Scott Frederick + */ +public class VersionOverridingElasticsearchContainer extends ElasticsearchContainer { + + /** + * Elasticsearch Docker base URL + */ + private static final String ELASTICSEARCH_IMAGE = "docker.elastic.co/elasticsearch/elasticsearch"; + + /** + * Elasticsearch version + */ + protected static final String ELASTICSEARCH_VERSION = "7.5.1"; + + public VersionOverridingElasticsearchContainer() { + super(ELASTICSEARCH_IMAGE + ":" + ELASTICSEARCH_VERSION); + } + +} diff --git a/spring-boot-project/spring-boot-dependencies/build.gradle b/spring-boot-project/spring-boot-dependencies/build.gradle index bd5bf17dd11..366cf08c5c7 100644 --- a/spring-boot-project/spring-boot-dependencies/build.gradle +++ b/spring-boot-project/spring-boot-dependencies/build.gradle @@ -288,7 +288,7 @@ bom { ] } } - library('Elasticsearch', '6.8.5') { + library('Elasticsearch', '7.5.1') { group('org.elasticsearch') { modules = [ 'elasticsearch'