Search in sources :

Example 1 with Document

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

the class DocumentAdaptersUnitTests method shouldAdaptGetResponseSource.

// DATAES-628, DATAES-848
@Test
public void shouldAdaptGetResponseSource() {
    BytesArray source = new BytesArray("{\"field\":\"value\"}");
    GetResult getResult = new GetResult("index", "type", "my-id", 1, 2, 42, true, source, Collections.emptyMap(), null);
    GetResponse response = new GetResponse(getResult);
    Document document = DocumentAdapters.from(response);
    assertThat(document.getIndex()).isEqualTo("index");
    assertThat(document.hasId()).isTrue();
    assertThat(document.getId()).isEqualTo("my-id");
    assertThat(document.hasVersion()).isTrue();
    assertThat(document.getVersion()).isEqualTo(42);
    assertThat(document.get("field")).isEqualTo("value");
    assertThat(document.hasSeqNo()).isTrue();
    assertThat(document.getSeqNo()).isEqualTo(1);
    assertThat(document.hasPrimaryTerm()).isTrue();
    assertThat(document.getPrimaryTerm()).isEqualTo(2);
}
Also used : BytesArray(org.elasticsearch.common.bytes.BytesArray) GetResult(org.elasticsearch.index.get.GetResult) SearchDocument(org.springframework.data.elasticsearch.core.document.SearchDocument) Document(org.springframework.data.elasticsearch.core.document.Document) GetResponse(org.elasticsearch.action.get.GetResponse) Test(org.junit.jupiter.api.Test)

Example 2 with Document

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

the class DocumentUnitTests method shouldReturnContainsValue.

// DATAES-628
@Test
public void shouldReturnContainsValue() {
    Document document = Document.create().append("string", "value").append("bool", Arrays.asList(true, true, false)).append("int", 43).append("long", 42L);
    assertThat(document.containsValue("value")).isTrue();
    assertThat(document.containsValue(43)).isTrue();
    assertThat(document.containsValue(44)).isFalse();
    assertThat(document.containsValue(Arrays.asList(true, true, false))).isTrue();
}
Also used : Document(org.springframework.data.elasticsearch.core.document.Document) Test(org.junit.jupiter.api.Test)

Example 3 with Document

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

the class DocumentUnitTests method shouldSetId.

// DATAES-628
@Test
public void shouldSetId() {
    Document document = Document.create();
    assertThat(document.hasId()).isFalse();
    assertThatIllegalStateException().isThrownBy(document::getId);
    document.setId("foo");
    assertThat(document.getId()).isEqualTo("foo");
}
Also used : Document(org.springframework.data.elasticsearch.core.document.Document) Test(org.junit.jupiter.api.Test)

Example 4 with Document

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

the class DocumentUnitTests method shouldApplyTransformer.

// DATAES-628
@Test
public void shouldApplyTransformer() {
    Document document = Document.create();
    document.setId("value");
    assertThat(document.transform(Document::getId)).isEqualTo("value");
}
Also used : Document(org.springframework.data.elasticsearch.core.document.Document) Test(org.junit.jupiter.api.Test)

Example 5 with Document

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

the class DocumentUnitTests method shouldSetVersion.

// DATAES-628
@Test
public void shouldSetVersion() {
    Document document = Document.create();
    assertThat(document.hasVersion()).isFalse();
    assertThatIllegalStateException().isThrownBy(document::getVersion);
    document.setVersion(14);
    assertThat(document.getVersion()).isEqualTo(14);
}
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)59 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