Search in sources :

Example 1 with SimpleElasticsearchMappingContext

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();
    });
}
Also used : SimpleElasticsearchMappingContext(org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext) Test(org.junit.jupiter.api.Test)

Example 2 with SimpleElasticsearchMappingContext

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;
}
Also used : SimpleElasticsearchMappingContext(org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext) Bean(org.springframework.context.annotation.Bean)

Example 3 with SimpleElasticsearchMappingContext

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");
}
Also used : SimpleElasticsearchMappingContext(org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext) BeforeConvertCallback(org.springframework.data.elasticsearch.core.event.BeforeConvertCallback) EntityCallbacks(org.springframework.data.mapping.callback.EntityCallbacks) Test(org.junit.jupiter.api.Test)

Example 4 with SimpleElasticsearchMappingContext

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());
}
Also used : SimpleElasticsearchMappingContext(org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Example 5 with SimpleElasticsearchMappingContext

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);
}
Also used : SimpleElasticsearchMappingContext(org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext) HashSet(java.util.HashSet) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

SimpleElasticsearchMappingContext (org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext)23 Test (org.junit.jupiter.api.Test)9 BeforeEach (org.junit.jupiter.api.BeforeEach)7 MappingElasticsearchConverter (org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter)6 GenericConversionService (org.springframework.core.convert.support.GenericConversionService)5 GeoJsonLineString (org.springframework.data.elasticsearch.core.geo.GeoJsonLineString)3 GeoJsonMultiLineString (org.springframework.data.elasticsearch.core.geo.GeoJsonMultiLineString)3 ArrayList (java.util.ArrayList)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 DisplayName (org.junit.jupiter.api.DisplayName)2 Document (org.springframework.data.elasticsearch.core.document.Document)2 SpringIntegrationTest (org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)2 BigDecimal (java.math.BigDecimal)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Bean (org.springframework.context.annotation.Bean)1 ConversionService (org.springframework.core.convert.ConversionService)1 Converter (org.springframework.core.convert.converter.Converter)1 IsNewAwareAuditingHandler (org.springframework.data.auditing.IsNewAwareAuditingHandler)1