Merge pull request #17661 from sothawo

* pr/17661:
  Polish "Allow for custom EntityMapper bean"
  Allow for custom EntityMapper bean

Closes gh-17661
pull/17761/head
Stephane Nicoll 5 years ago
commit b8bda1c03d

@ -67,6 +67,7 @@ abstract class ElasticsearchDataConfiguration {
}
@Bean
@ConditionalOnMissingBean
EntityMapper entityMapper(SimpleElasticsearchMappingContext mappingContext) {
return new DefaultEntityMapper(mappingContext);
}

@ -28,6 +28,7 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.testsupport.testcontainers.DisabledWithoutDockerTestcontainers;
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;
@ -44,6 +45,7 @@ import static org.mockito.Mockito.mock;
* @author Phillip Webb
* @author Artur Konczak
* @author Brian Clozel
* @author Peter-Josef Meisch
*/
@DisabledWithoutDockerTestcontainers
class ElasticsearchDataAutoConfigurationTests {
@ -90,6 +92,11 @@ class ElasticsearchDataAutoConfigurationTests {
.hasSingleBean(ElasticsearchConverter.class));
}
@Test
void defaultEntityMapperRegistered() {
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(EntityMapper.class));
}
@Test
void customTransportTemplateShouldBeUsed() {
this.contextRunner.withUserConfiguration(CustomTransportTemplate.class).run((context) -> assertThat(context)
@ -109,6 +116,12 @@ 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 {
@ -139,4 +152,14 @@ class ElasticsearchDataAutoConfigurationTests {
}
@Configuration(proxyBeanMethods = false)
static class CustomEntityMapper {
@Bean
EntityMapper elasticsearchEntityMapper() {
return mock(ElasticsearchEntityMapper.class);
}
}
}

Loading…
Cancel
Save