Search in sources :

Example 16 with Document

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

the class MappingElasticsearchConverterUnitTests method shouldWriteNullValueIfConfigured.

// DATAES-920
@Test
@DisplayName("should write null value if configured")
void shouldWriteNullValueIfConfigured() throws JSONException {
    EntityWithNullField entity = new EntityWithNullField();
    entity.setId("42");
    String expected = // 
    "{\n" + // 
    "  \"id\": \"42\",\n" + // 
    "  \"saved\": null\n" + // 
    "}\n";
    Document document = Document.create();
    mappingElasticsearchConverter.write(entity, document);
    assertEquals(expected, document.toJson(), 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 17 with Document

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

the class MappingElasticsearchConverterUnitTests method writeToMap.

private Map<String, Object> writeToMap(Object source) {
    Document sink = Document.create();
    mappingElasticsearchConverter.write(source, sink);
    return sink;
}
Also used : Document(org.springframework.data.elasticsearch.core.document.Document)

Example 18 with Document

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

the class MappingElasticsearchConverterUnitTests method readGenericMapMap.

// DATAES-530
@Test
public void readGenericMapMap() {
    Document source = Document.create();
    source.put("objectMap", Collections.singletonMap("inventory", Collections.singletonMap("glock19", gunAsMap)));
    Skynet target = mappingElasticsearchConverter.read(Skynet.class, source);
    assertThat(target.getObjectMap()).containsEntry("inventory", Collections.singletonMap("glock19", gun));
}
Also used : Document(org.springframework.data.elasticsearch.core.document.Document) Test(org.junit.jupiter.api.Test)

Example 19 with Document

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

the class MappingElasticsearchConverterUnitTests method readGenericListList.

// DATAES-530
@Test
public void readGenericListList() {
    Document source = Document.create();
    source.put("objectList", Collections.singletonList(Arrays.asList(t800AsMap, gunAsMap)));
    Skynet target = mappingElasticsearchConverter.read(Skynet.class, source);
    assertThat(target.getObjectList()).containsExactly(Arrays.asList(t800, gun));
}
Also used : Document(org.springframework.data.elasticsearch.core.document.Document) Test(org.junit.jupiter.api.Test)

Example 20 with Document

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

the class MappingElasticsearchConverterUnitTests method shouldNotWriteSeqNoPrimaryTermProperty.

// DATAES-799
@Test
void shouldNotWriteSeqNoPrimaryTermProperty() {
    EntityWithSeqNoPrimaryTerm entity = new EntityWithSeqNoPrimaryTerm();
    entity.seqNoPrimaryTerm = new SeqNoPrimaryTerm(1L, 2L);
    Document document = Document.create();
    mappingElasticsearchConverter.write(entity, document);
    assertThat(document).doesNotContainKey("seqNoPrimaryTerm");
}
Also used : SeqNoPrimaryTerm(org.springframework.data.elasticsearch.core.query.SeqNoPrimaryTerm) 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