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