Search in sources :

Example 21 with Document

use of org.springframework.data.elasticsearch.core.document.Document in project spring-data-elasticsearch by spring-projects.

the class MappingElasticsearchConverterUnitTests method shouldWriteEntityWithListOfGeoPoints.

// DATAES-857
@Test
void shouldWriteEntityWithListOfGeoPoints() throws JSONException {
    GeoPointListEntity entity = new GeoPointListEntity();
    entity.setId("42");
    List<GeoPoint> locations = Arrays.asList(new GeoPoint(12.34, 23.45), new GeoPoint(34.56, 45.67));
    entity.setLocations(locations);
    String expected = // 
    "{\n" + // 
    "  \"id\": \"42\",\n" + // 
    "  \"locations\": [\n" + // 
    "    {\n" + // 
    "      \"lat\": 12.34,\n" + // 
    "      \"lon\": 23.45\n" + // 
    "    },\n" + // 
    "    {\n" + // 
    "      \"lat\": 34.56,\n" + // 
    "      \"lon\": 45.67\n" + // 
    "    }\n" + // 
    "  ]\n" + // 
    "}";
    Document document = Document.create();
    mappingElasticsearchConverter.write(entity, document);
    String json = document.toJson();
    assertEquals(expected, json, false);
}
Also used : GeoPoint(org.springframework.data.elasticsearch.core.geo.GeoPoint) 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)

Example 22 with Document

use of org.springframework.data.elasticsearch.core.document.Document in project spring-data-elasticsearch by spring-projects.

the class MappingElasticsearchConverterUnitTests method readsNestedObjectEntity.

// DATAES-530
@Test
public void readsNestedObjectEntity() {
    Document source = Document.create();
    source.put("object", t800AsMap);
    Skynet target = mappingElasticsearchConverter.read(Skynet.class, source);
    assertThat(target.getObject()).isEqualTo(t800);
}
Also used : Document(org.springframework.data.elasticsearch.core.document.Document) Test(org.junit.jupiter.api.Test)

Example 23 with Document

use of org.springframework.data.elasticsearch.core.document.Document in project spring-data-elasticsearch by spring-projects.

the class MappingElasticsearchConverterUnitTests method shouldReadEntityWithListOfGeoPoints.

// DATAES-857
@Test
void shouldReadEntityWithListOfGeoPoints() {
    String json = // 
    "{\n" + // 
    "  \"id\": \"42\",\n" + // 
    "  \"locations\": [\n" + // 
    "    {\n" + // 
    "      \"lat\": 12.34,\n" + // 
    "      \"lon\": 23.45\n" + // 
    "    },\n" + // 
    "    {\n" + // 
    "      \"lat\": 34.56,\n" + // 
    "      \"lon\": 45.67\n" + // 
    "    }\n" + // 
    "  ]\n" + // 
    "}";
    Document document = Document.parse(json);
    GeoPointListEntity entity = mappingElasticsearchConverter.read(GeoPointListEntity.class, document);
    assertThat(entity.id).isEqualTo("42");
    assertThat(entity.locations).containsExactly(new GeoPoint(12.34, 23.45), new GeoPoint(34.56, 45.67));
}
Also used : GeoPoint(org.springframework.data.elasticsearch.core.geo.GeoPoint) 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)

Example 24 with Document

use of org.springframework.data.elasticsearch.core.document.Document in project spring-data-elasticsearch by spring-projects.

the class MappingElasticsearchConverterUnitTests method shouldWriteListOfLocalDate.

// DATAES-924
@Test
@DisplayName("should write list of LocalDate")
void shouldWriteListOfLocalDate() throws JSONException {
    LocalDatesEntity entity = new LocalDatesEntity();
    entity.setId("4711");
    entity.setDates(Arrays.asList(LocalDate.of(2020, 9, 15), LocalDate.of(2019, 5, 1)));
    String expected = // 
    "{\n" + // 
    "  \"id\": \"4711\",\n" + // 
    "  \"dates\": [\"15.09.2020\", \"01.05.2019\"]\n" + // 
    "}\n";
    Document document = Document.create();
    mappingElasticsearchConverter.write(entity, document);
    String json = document.toJson();
    assertEquals(expected, json, false);
}
Also used : 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 25 with Document

use of org.springframework.data.elasticsearch.core.document.Document in project spring-data-elasticsearch by spring-projects.

the class MappingElasticsearchConverterUnitTests method shouldReadLocalDate.

// DATAES-716
@Test
void shouldReadLocalDate() {
    Document document = Document.create();
    document.put("id", "4711");
    document.put("first-name", "John");
    document.put("last-name", "Doe");
    document.put("birth-date", "22.08.2000");
    document.put("gender", "MAN");
    Person person = mappingElasticsearchConverter.read(Person.class, document);
    assertThat(person.getId()).isEqualTo("4711");
    assertThat(person.getBirthDate()).isEqualTo(LocalDate.of(2000, 8, 22));
    assertThat(person.getGender()).isEqualTo(Gender.MAN);
}
Also used : Document(org.springframework.data.elasticsearch.core.document.Document) Test(org.junit.jupiter.api.Test)

Aggregations

Document (org.springframework.data.elasticsearch.core.document.Document)58 Test (org.junit.jupiter.api.Test)48 GeoJsonLineString (org.springframework.data.elasticsearch.core.geo.GeoJsonLineString)15 GeoJsonMultiLineString (org.springframework.data.elasticsearch.core.geo.GeoJsonMultiLineString)15 DisplayName (org.junit.jupiter.api.DisplayName)7 HashMap (java.util.HashMap)6 ArrayList (java.util.ArrayList)5 LinkedHashMap (java.util.LinkedHashMap)5 SpringIntegrationTest (org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)5 GetResult (org.elasticsearch.index.get.GetResult)4 SearchDocument (org.springframework.data.elasticsearch.core.document.SearchDocument)4 Object (java.lang.Object)2 GetResponse (org.elasticsearch.action.get.GetResponse)2 UpdateRequest (org.elasticsearch.action.update.UpdateRequest)2 MappingMetadata (org.elasticsearch.cluster.metadata.MappingMetadata)2 BytesArray (org.elasticsearch.common.bytes.BytesArray)2 DocumentField (org.elasticsearch.common.document.DocumentField)2 GeoPoint (org.springframework.data.elasticsearch.core.geo.GeoPoint)2 AliasData (org.springframework.data.elasticsearch.core.index.AliasData)2 Settings (org.springframework.data.elasticsearch.core.index.Settings)2