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");
}
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));
}
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));
}
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));
}
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));
}
Aggregations