Search in sources :

Example 51 with Document

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

the class DocumentUnitTests method shouldCreateNewDocument.

// DATAES-628
@Test
public void shouldCreateNewDocument() {
    Document document = Document.create().append("key", "value");
    assertThat(document).containsEntry("key", "value");
}
Also used : Document(org.springframework.data.elasticsearch.core.document.Document) Test(org.junit.jupiter.api.Test)

Example 52 with Document

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

the class DocumentUnitTests method shouldReturnTypedValue.

// DATAES-628
@Test
public void shouldReturnTypedValue() {
    Document document = Document.create().append("string", "value").append("bool", true).append("int", 43).append("long", 42L);
    assertThat(document.get("string")).isEqualTo("value");
    assertThat(document.getString("string")).isEqualTo("value");
    assertThatExceptionOfType(ClassCastException.class).isThrownBy(() -> document.get("long", String.class));
}
Also used : Document(org.springframework.data.elasticsearch.core.document.Document) Test(org.junit.jupiter.api.Test)

Example 53 with Document

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

the class DocumentUnitTests method shouldReturnTypedValueInt.

// DATAES-628
@Test
public void shouldReturnTypedValueInt() {
    Document document = Document.create().append("string", "value").append("bool", true).append("int", 43).append("long", 42L);
    assertThat(document.getInt("int")).isEqualTo(43);
    assertThat(document.getIntOrDefault("not-set", 44)).isEqualTo(44);
    assertThat(document.getIntOrDefault("not-set", () -> 44)).isEqualTo(44);
    assertThatExceptionOfType(ClassCastException.class).isThrownBy(() -> document.getString("int"));
    assertThatExceptionOfType(ClassCastException.class).isThrownBy(() -> document.get("int", String.class));
}
Also used : Document(org.springframework.data.elasticsearch.core.document.Document) Test(org.junit.jupiter.api.Test)

Example 54 with Document

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

the class DocumentUnitTests method shouldReturnTypedValueBoolean.

// DATAES-628
@Test
public void shouldReturnTypedValueBoolean() {
    Document document = Document.create().append("string", "value").append("bool", true).append("int", 43).append("long", 42L);
    assertThat(document.getBoolean("bool")).isTrue();
    assertThat(document.getBooleanOrDefault("not-set", true)).isTrue();
    assertThat(document.getBooleanOrDefault("not-set", () -> true)).isTrue();
    assertThatExceptionOfType(ClassCastException.class).isThrownBy(() -> document.getString("bool"));
    assertThatExceptionOfType(ClassCastException.class).isThrownBy(() -> document.get("bool", String.class));
}
Also used : Document(org.springframework.data.elasticsearch.core.document.Document) Test(org.junit.jupiter.api.Test)

Example 55 with Document

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

the class DocumentUnitTests method shouldReturnTypedValueString.

// DATAES-628
@Test
public void shouldReturnTypedValueString() {
    Document document = Document.create().append("string", "value").append("bool", true).append("int", 43).append("long", 42L);
    assertThat(document.getString("string")).isEqualTo("value");
    assertThat(document.getStringOrDefault("not-set", "default")).isEqualTo("default");
    assertThat(document.getStringOrDefault("not-set", () -> "default")).isEqualTo("default");
    assertThatExceptionOfType(ClassCastException.class).isThrownBy(() -> document.getString("long"));
    assertThatExceptionOfType(ClassCastException.class).isThrownBy(() -> document.get("long", String.class));
}
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