Commit a1cf665f authored by P.J. Meisch's avatar P.J. Meisch Committed by Stephane Nicoll

Allow for custom EntityMapper bean

See gh-17661
parent e419aab0
...@@ -48,6 +48,7 @@ import org.springframework.web.reactive.function.client.WebClient; ...@@ -48,6 +48,7 @@ import org.springframework.web.reactive.function.client.WebClient;
* their order of execution. * their order of execution.
* *
* @author Brian Clozel * @author Brian Clozel
* @author Peter-Josef Meisch
*/ */
abstract class ElasticsearchDataConfiguration { abstract class ElasticsearchDataConfiguration {
...@@ -67,6 +68,7 @@ abstract class ElasticsearchDataConfiguration { ...@@ -67,6 +68,7 @@ abstract class ElasticsearchDataConfiguration {
} }
@Bean @Bean
@ConditionalOnMissingBean
EntityMapper entityMapper(SimpleElasticsearchMappingContext mappingContext) { EntityMapper entityMapper(SimpleElasticsearchMappingContext mappingContext) {
return new DefaultEntityMapper(mappingContext); return new DefaultEntityMapper(mappingContext);
} }
......
...@@ -28,6 +28,7 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner; ...@@ -28,6 +28,7 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.testsupport.testcontainers.DisabledWithoutDockerTestcontainers; import org.springframework.boot.testsupport.testcontainers.DisabledWithoutDockerTestcontainers;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; 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.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.EntityMapper; import org.springframework.data.elasticsearch.core.EntityMapper;
...@@ -90,6 +91,11 @@ class ElasticsearchDataAutoConfigurationTests { ...@@ -90,6 +91,11 @@ class ElasticsearchDataAutoConfigurationTests {
.hasSingleBean(ElasticsearchConverter.class)); .hasSingleBean(ElasticsearchConverter.class));
} }
@Test
void defaultEntityMapperRegistered() {
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(EntityMapper.class));
}
@Test @Test
void customTransportTemplateShouldBeUsed() { void customTransportTemplateShouldBeUsed() {
this.contextRunner.withUserConfiguration(CustomTransportTemplate.class).run((context) -> assertThat(context) this.contextRunner.withUserConfiguration(CustomTransportTemplate.class).run((context) -> assertThat(context)
...@@ -109,6 +115,12 @@ class ElasticsearchDataAutoConfigurationTests { ...@@ -109,6 +115,12 @@ class ElasticsearchDataAutoConfigurationTests {
.contains("reactiveElasticsearchTemplate")); .contains("reactiveElasticsearchTemplate"));
} }
@Test
void customEntityMapperShouldeBeUsed() {
this.contextRunner.withUserConfiguration(CustomEntityMapper.class).run((context) -> assertThat(context)
.getBeanNames(EntityMapper.class).containsExactly("elasticsearchEntityMapper"));
}
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
static class CustomTransportTemplate { static class CustomTransportTemplate {
...@@ -139,4 +151,14 @@ class ElasticsearchDataAutoConfigurationTests { ...@@ -139,4 +151,14 @@ class ElasticsearchDataAutoConfigurationTests {
} }
@Configuration(proxyBeanMethods = false)
static class CustomEntityMapper {
@Bean
EntityMapper elasticsearchEntityMapper() {
return mock(ElasticsearchEntityMapper.class);
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment