use of org.springframework.data.elasticsearch.core.document.Document in project spring-data-elasticsearch by spring-projects.
the class MappingElasticsearchConverterUnitTests method shouldWriteLocalDate.
// DATAES-716
@Test
void shouldWriteLocalDate() throws JSONException {
Person person = new Person();
person.setId("4711");
person.setFirstName("John");
person.setLastName("Doe");
person.birthDate = LocalDate.of(2000, 8, 22);
person.gender = Gender.MAN;
String expected = //
'{' + //
" \"id\": \"4711\"," + //
" \"first-name\": \"John\"," + //
" \"last-name\": \"Doe\"," + //
" \"birth-date\": \"22.08.2000\"," + //
" \"gender\": \"MAN\"" + '}';
Document document = Document.create();
mappingElasticsearchConverter.write(person, 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 writeEntityWithMapDataType.
// DATAES-763
@Test
void writeEntityWithMapDataType() {
Notification notification = new Notification();
notification.setFromEmail("from@email.com");
notification.setToEmail("to@email.com");
Map<String, Object> data = new HashMap<>();
data.put("documentType", "abc");
data.put("content", null);
notification.params = data;
notification.id = 1L;
Document document = Document.create();
mappingElasticsearchConverter.write(notification, document);
assertThat(document).isEqualTo(notificationAsMap);
}
use of org.springframework.data.elasticsearch.core.document.Document in project spring-data-elasticsearch by spring-projects.
the class MappingElasticsearchConverterUnitTests method readGenericListWithMaps.
// DATAES-797
@Test
void readGenericListWithMaps() {
Map<String, Object> simpleMap = new HashMap<>();
simpleMap.put("int", 1);
List<Map<String, Object>> listWithSimpleMap = new ArrayList<>();
listWithSimpleMap.add(simpleMap);
Map<String, List<Map<String, Object>>> mapWithSimpleList = new HashMap<>();
mapWithSimpleList.put("someKey", listWithSimpleMap);
Document document = Document.create();
document.put("schemaLessObject", mapWithSimpleList);
SchemaLessObjectWrapper wrapper = mappingElasticsearchConverter.read(SchemaLessObjectWrapper.class, document);
assertThat(wrapper.getSchemaLessObject()).isEqualTo(mapWithSimpleList);
}
use of org.springframework.data.elasticsearch.core.document.Document in project spring-data-elasticsearch by spring-projects.
the class MappingElasticsearchConverterUnitTests method shouldWriteCollectionsWithNullValues.
// DATAES-845
@Test
void shouldWriteCollectionsWithNullValues() throws JSONException {
EntityWithListProperty entity = new EntityWithListProperty();
entity.setId("42");
entity.setValues(Arrays.asList(null, "two", null, "four"));
String expected = //
'{' + //
" \"id\": \"42\"," + //
" \"values\": [null, \"two\", null, \"four\"]" + '}';
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 ElasticsearchTemplateTests method shouldReturnSourceWhenRequested.
// DATAES-693
@Test
public void shouldReturnSourceWhenRequested() {
// given
Map<String, Object> doc = new HashMap<>();
doc.put("id", "1");
doc.put("message", "test");
org.springframework.data.elasticsearch.core.document.Document document = org.springframework.data.elasticsearch.core.document.Document.from(doc);
UpdateQuery updateQuery = //
UpdateQuery.builder("1").withDocument(//
document).withFetchSource(//
true).build();
// when
UpdateRequest request = getRequestFactory().updateRequest(updateQuery, IndexCoordinates.of("index"));
// then
assertThat(request).isNotNull();
assertThat(request.fetchSource()).isEqualTo(FetchSourceContext.FETCH_SOURCE);
}
Aggregations