Search in sources :

Example 16 with SimpleElasticsearchMappingContext

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

the class DefaultRoutingResolverUnitTest method setUp.

@BeforeEach
void setUp() {
    mappingContext = new SimpleElasticsearchMappingContext();
    mappingContext.setApplicationContext(applicationContext);
    routingResolver = new DefaultRoutingResolver(mappingContext);
}
Also used : SimpleElasticsearchMappingContext(org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 17 with SimpleElasticsearchMappingContext

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

the class ReactiveAuditingEntityCallbackTests method setUp.

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

Example 18 with SimpleElasticsearchMappingContext

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

the class MappingElasticsearchConverterUnitTests method shouldNotWriteTypeHintsIfNotConfigured.

// #1454
@Test
@DisplayName("should not write type hints if configured")
void shouldNotWriteTypeHintsIfNotConfigured() throws JSONException {
    ((SimpleElasticsearchMappingContext) mappingElasticsearchConverter.getMappingContext()).setWriteTypeHints(false);
    PersonWithCars person = new PersonWithCars();
    person.setId("42");
    person.setName("Smith");
    Car car1 = new Car();
    car1.setModel("Ford Mustang");
    Car car2 = new ElectricCar();
    car2.setModel("Porsche Taycan");
    person.setCars(Arrays.asList(car1, car2));
    String expected = // 
    "{\n" + // 
    "  \"id\": \"42\",\n" + // 
    "  \"name\": \"Smith\",\n" + // 
    "  \"cars\": [\n" + // 
    "    {\n" + // 
    "      \"model\": \"Ford Mustang\"\n" + // 
    "    },\n" + // 
    "    {\n" + // 
    "      \"model\": \"Porsche Taycan\"\n" + // 
    "    }\n" + // 
    "  ]\n" + // 
    "}\n";
    Document document = Document.create();
    mappingElasticsearchConverter.write(person, document);
    assertEquals(expected, document.toJson(), true);
}
Also used : SimpleElasticsearchMappingContext(org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext) GeoJsonLineString(org.springframework.data.elasticsearch.core.geo.GeoJsonLineString) GeoJsonMultiLineString(org.springframework.data.elasticsearch.core.geo.GeoJsonMultiLineString) Document(org.springframework.data.elasticsearch.core.document.Document) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 19 with SimpleElasticsearchMappingContext

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

the class MappingElasticsearchConverterUnitTests method shouldWriteTypeHintsIfConfigured.

// #1454
@Test
@DisplayName("should write type hints if configured")
void shouldWriteTypeHintsIfConfigured() throws JSONException {
    ((SimpleElasticsearchMappingContext) mappingElasticsearchConverter.getMappingContext()).setWriteTypeHints(true);
    PersonWithCars person = new PersonWithCars();
    person.setId("42");
    person.setName("Smith");
    Car car1 = new Car();
    car1.setModel("Ford Mustang");
    Car car2 = new ElectricCar();
    car2.setModel("Porsche Taycan");
    person.setCars(Arrays.asList(car1, car2));
    String expected = // 
    "{\n" + "  \"_class\": \"org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverterUnitTests$PersonWithCars\",\n" + // 
    "  \"id\": \"42\",\n" + // 
    "  \"name\": \"Smith\",\n" + // 
    "  \"cars\": [\n" + // 
    "    {\n" + // 
    "      \"model\": \"Ford Mustang\"\n" + // 
    "    },\n" + // 
    "    {\n" + "      \"_class\": \"org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverterUnitTests$ElectricCar\",\n" + // 
    "      \"model\": \"Porsche Taycan\"\n" + // 
    "    }\n" + // 
    "  ]\n" + // 
    "}\n";
    Document document = Document.create();
    mappingElasticsearchConverter.write(person, document);
    assertEquals(expected, document.toJson(), true);
}
Also used : SimpleElasticsearchMappingContext(org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext) GeoJsonLineString(org.springframework.data.elasticsearch.core.geo.GeoJsonLineString) GeoJsonMultiLineString(org.springframework.data.elasticsearch.core.geo.GeoJsonMultiLineString) Document(org.springframework.data.elasticsearch.core.document.Document) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 20 with SimpleElasticsearchMappingContext

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

the class PropertyValueConvertersUnitTests method propertyValueConverters.

static Stream<Arguments> propertyValueConverters() {
    SimpleElasticsearchMappingContext context = new SimpleElasticsearchMappingContext();
    SimpleElasticsearchPersistentEntity<?> persistentEntity = context.getRequiredPersistentEntity(NoConverterForThisClass.class);
    ElasticsearchPersistentProperty persistentProperty = persistentEntity.getRequiredPersistentProperty("property");
    List<PropertyValueConverter> converters = new ArrayList<>();
    converters.add(new DatePropertyValueConverter(persistentProperty, Collections.singletonList(ElasticsearchDateConverter.of(DateFormat.basic_date))));
    converters.add(new DateRangePropertyValueConverter(persistentProperty, Collections.singletonList(ElasticsearchDateConverter.of(DateFormat.basic_date))));
    converters.add(new NumberRangePropertyValueConverter(persistentProperty));
    converters.add(new TemporalPropertyValueConverter(persistentProperty, Collections.singletonList(ElasticsearchDateConverter.of(DateFormat.basic_date))));
    converters.add(new TemporalRangePropertyValueConverter(persistentProperty, Collections.singletonList(ElasticsearchDateConverter.of(DateFormat.basic_date))));
    return converters.stream().map(propertyValueConverter -> arguments(Named.of(propertyValueConverter.getClass().getSimpleName(), propertyValueConverter)));
}
Also used : SimpleElasticsearchMappingContext(org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext) PropertyValueConverter(org.springframework.data.elasticsearch.core.mapping.PropertyValueConverter) ElasticsearchPersistentProperty(org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty) ArrayList(java.util.ArrayList)

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