use of org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext in project spring-boot by spring-projects.
the class ElasticsearchDataAutoConfigurationTests method shouldFilterInitialEntityScanWithDocumentAnnotation.
@Test
void shouldFilterInitialEntityScanWithDocumentAnnotation() {
this.contextRunner.withUserConfiguration(EntityScanConfig.class).run((context) -> {
SimpleElasticsearchMappingContext mappingContext = context.getBean(SimpleElasticsearchMappingContext.class);
assertThat(mappingContext.hasPersistentEntityFor(City.class)).isTrue();
});
}
use of org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext in project spring-data-elasticsearch by spring-projects.
the class ElasticsearchConfigurationSupport method elasticsearchMappingContext.
/**
* Creates a {@link SimpleElasticsearchMappingContext} equipped with entity classes scanned from the mapping base
* package.
*
* @see #getMappingBasePackages()
* @return never {@literal null}.
*/
@Bean
public SimpleElasticsearchMappingContext elasticsearchMappingContext(ElasticsearchCustomConversions elasticsearchCustomConversions) {
SimpleElasticsearchMappingContext mappingContext = new SimpleElasticsearchMappingContext();
mappingContext.setInitialEntitySet(getInitialEntitySet());
mappingContext.setSimpleTypeHolder(elasticsearchCustomConversions.getSimpleTypeHolder());
mappingContext.setFieldNamingStrategy(fieldNamingStrategy());
mappingContext.setWriteTypeHints(writeTypeHints());
return mappingContext;
}
use of org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext in project spring-data-elasticsearch by spring-projects.
the class AuditingIntegrationTests method shouldEnableAuditingAndSetAuditingDates.
// DATAES-68
@Test
void shouldEnableAuditingAndSetAuditingDates() throws InterruptedException {
SimpleElasticsearchMappingContext mappingContext = applicationContext.getBean(SimpleElasticsearchMappingContext.class);
mappingContext.getPersistentEntity(Entity.class);
EntityCallbacks callbacks = EntityCallbacks.create(applicationContext);
Entity entity = new Entity();
entity.setId("1");
entity = callbacks.callback(BeforeConvertCallback.class, entity, IndexCoordinates.of("index"));
assertThat(entity.getCreated()).isNotNull();
assertThat(entity.getModified()).isEqualTo(entity.created);
assertThat(entity.getCreatedBy()).isEqualTo("Auditor 1");
assertThat(entity.getModifiedBy()).isEqualTo("Auditor 1");
Thread.sleep(50);
entity = callbacks.callback(BeforeConvertCallback.class, entity, IndexCoordinates.of("index"));
assertThat(entity.getCreated()).isNotNull();
assertThat(entity.getModified()).isNotEqualTo(entity.created);
assertThat(entity.getCreatedBy()).isEqualTo("Auditor 1");
assertThat(entity.getModifiedBy()).isEqualTo("Auditor 2");
}
use of org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext in project spring-data-elasticsearch by spring-projects.
the class RoutingIntegrationTests method shouldCreateACopyOfTheClientWithRefreshPolicy.
@Test
void shouldCreateACopyOfTheClientWithRefreshPolicy() {
// given
AbstractElasticsearchTemplate sourceTemplate = (AbstractElasticsearchTemplate) operations;
SimpleElasticsearchMappingContext mappingContext = new SimpleElasticsearchMappingContext();
DefaultRoutingResolver defaultRoutingResolver = new DefaultRoutingResolver(mappingContext);
// when
ElasticsearchOperations operationsCopy = this.operations.withRouting(defaultRoutingResolver);
AbstractElasticsearchTemplate copyTemplate = (AbstractElasticsearchTemplate) operationsCopy;
// then
assertThat(sourceTemplate.getRefreshPolicy()).isEqualTo(copyTemplate.getRefreshPolicy());
}
use of org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext in project spring-data-elasticsearch by spring-projects.
the class ElasticsearchEntityInformationCreatorImplTests method before.
@BeforeEach
public void before() {
SimpleElasticsearchMappingContext context = new SimpleElasticsearchMappingContext();
Set<Class<?>> entites = new HashSet<>();
entites.add(EntityNoId.class);
context.setInitialEntitySet(entites);
entityInfoCreator = new ElasticsearchEntityInformationCreatorImpl(context);
}
Aggregations