Search in sources :

Example 21 with SimpleElasticsearchMappingContext

use of org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext in project spring-data-elasticsearch by spring-projects.

the class AuditingEntityCallbackTests method setUp.

@BeforeEach
void setUp() {
    SimpleElasticsearchMappingContext context = new SimpleElasticsearchMappingContext();
    context.getPersistentEntity(Sample.class);
    handler = spy(new IsNewAwareAuditingHandler(PersistentEntities.of(context)));
    callback = new AuditingEntityCallback(() -> handler);
}
Also used : IsNewAwareAuditingHandler(org.springframework.data.auditing.IsNewAwareAuditingHandler) SimpleElasticsearchMappingContext(org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 22 with SimpleElasticsearchMappingContext

use of org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext in project spring-data-elasticsearch by spring-projects.

the class MappingElasticsearchConverterUnitTests method shouldReturnMappingContextWithWhichItWasInitialized.

@Test
public void shouldReturnMappingContextWithWhichItWasInitialized() {
    // given
    MappingContext mappingContext = new SimpleElasticsearchMappingContext();
    MappingElasticsearchConverter converter = new MappingElasticsearchConverter(mappingContext);
    // then
    assertThat(converter.getMappingContext()).isNotNull();
    assertThat(converter.getMappingContext()).isSameAs(mappingContext);
}
Also used : MappingContext(org.springframework.data.mapping.context.MappingContext) SimpleElasticsearchMappingContext(org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext) SimpleElasticsearchMappingContext(org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext) Test(org.junit.jupiter.api.Test)

Example 23 with SimpleElasticsearchMappingContext

use of org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext in project spring-data-elasticsearch by spring-projects.

the class ReactiveAuditingIntegrationTest method shouldEnableAuditingAndSetAuditingDates.

// DATAES-68
@Test
void shouldEnableAuditingAndSetAuditingDates() throws InterruptedException {
    SimpleElasticsearchMappingContext mappingContext = applicationContext.getBean(SimpleElasticsearchMappingContext.class);
    mappingContext.getPersistentEntity(Entity.class);
    ReactiveEntityCallbacks callbacks = ReactiveEntityCallbacks.create(applicationContext);
    Entity entity = new Entity();
    entity.setId("1");
    entity = callbacks.callback(ReactiveBeforeConvertCallback.class, entity, IndexCoordinates.of("index")).block();
    assertThat(entity.getCreated()).isNotNull();
    assertThat(entity.getModified()).isEqualTo(entity.created);
    assertThat(entity.getCreatedBy()).isEqualTo("Auditor 1");
    assertThat(entity.getModifiedBy()).isEqualTo("Auditor 1");
    Thread.sleep(10);
    entity = callbacks.callback(ReactiveBeforeConvertCallback.class, entity, IndexCoordinates.of("index")).block();
    assertThat(entity.getCreated()).isNotNull();
    assertThat(entity.getModified()).isNotEqualTo(entity.created);
    assertThat(entity.getCreatedBy()).isEqualTo("Auditor 1");
    assertThat(entity.getModifiedBy()).isEqualTo("Auditor 2");
}
Also used : ReactiveEntityCallbacks(org.springframework.data.mapping.callback.ReactiveEntityCallbacks) SimpleElasticsearchMappingContext(org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

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