use of org.springframework.data.elasticsearch.core.document.Document in project spring-data-elasticsearch by spring-projects.
the class MappingElasticsearchConverterUnitTests method shouldWriteTypeHintsIfConfigured.
// #1454
@Test
@DisplayName("should write type hints if configured")
void shouldWriteTypeHintsIfConfigured() throws JSONException {
((SimpleElasticsearchMappingContext) mappingElasticsearchConverter.getMappingContext()).setWriteTypeHints(true);
PersonWithCars person = new PersonWithCars();
person.setId("42");
person.setName("Smith");
Car car1 = new Car();
car1.setModel("Ford Mustang");
Car car2 = new ElectricCar();
car2.setModel("Porsche Taycan");
person.setCars(Arrays.asList(car1, car2));
String expected = //
"{\n" + " \"_class\": \"org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverterUnitTests$PersonWithCars\",\n" + //
" \"id\": \"42\",\n" + //
" \"name\": \"Smith\",\n" + //
" \"cars\": [\n" + //
" {\n" + //
" \"model\": \"Ford Mustang\"\n" + //
" },\n" + //
" {\n" + " \"_class\": \"org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverterUnitTests$ElectricCar\",\n" + //
" \"model\": \"Porsche Taycan\"\n" + //
" }\n" + //
" ]\n" + //
"}\n";
Document document = Document.create();
mappingElasticsearchConverter.write(person, document);
assertEquals(expected, document.toJson(), true);
}
use of org.springframework.data.elasticsearch.core.document.Document in project spring-data-elasticsearch by spring-projects.
the class MappingElasticsearchConverterUnitTests method readGenericList.
// DATAES-530
@Test
public void readGenericList() {
Document source = Document.create();
source.put("objectList", Arrays.asList(t800AsMap, gunAsMap));
Skynet target = mappingElasticsearchConverter.read(Skynet.class, source);
assertThat(target.getObjectList()).containsExactly(t800, gun);
}
use of org.springframework.data.elasticsearch.core.document.Document in project spring-data-elasticsearch by spring-projects.
the class MappingElasticsearchConverterUnitTests method readGenericMapWithSimpleTypes.
// DATAES-795
@Test
void readGenericMapWithSimpleTypes() {
Map<String, Object> mapWithSimpleValues = new HashMap<>();
mapWithSimpleValues.put("int", 1);
mapWithSimpleValues.put("string", "string");
mapWithSimpleValues.put("boolean", true);
Document document = Document.create();
document.put("schemaLessObject", mapWithSimpleValues);
SchemaLessObjectWrapper wrapper = mappingElasticsearchConverter.read(SchemaLessObjectWrapper.class, document);
assertThat(wrapper.getSchemaLessObject()).isEqualTo(mapWithSimpleValues);
}
use of org.springframework.data.elasticsearch.core.document.Document in project spring-data-elasticsearch by spring-projects.
the class MappingElasticsearchConverterUnitTests method shouldNotReadSeqNoPrimaryTermProperty.
// DATAES-799
@Test
void shouldNotReadSeqNoPrimaryTermProperty() {
Document document = Document.create().append("seqNoPrimaryTerm", emptyMap());
EntityWithSeqNoPrimaryTerm entity = mappingElasticsearchConverter.read(EntityWithSeqNoPrimaryTerm.class, document);
assertThat(entity.seqNoPrimaryTerm).isNull();
}
use of org.springframework.data.elasticsearch.core.document.Document in project spring-data-elasticsearch by spring-projects.
the class MappingElasticsearchConverterUnitTests method shouldWriteUsingValueConverters.
// #1945
@Test
@DisplayName("should write using ValueConverters")
void shouldWriteUsingValueConverters() throws JSONException {
EntityWithCustomValueConverters entity = new EntityWithCustomValueConverters();
entity.setId("42");
entity.setFieldWithClassBasedConverter("classbased");
entity.setFieldWithEnumBasedConverter("enumbased");
entity.setDontConvert("Monty Python's Flying Circus");
String expected = //
"{\n" + //
" \"id\": \"42\",\n" + //
" \"fieldWithClassBasedConverter\": \"desabssalc\",\n" + //
" \"fieldWithEnumBasedConverter\": \"desabmune\",\n" + //
" \"dontConvert\": \"Monty Python's Flying Circus\"\n" + //
"}\n";
Document document = Document.create();
mappingElasticsearchConverter.write(entity, document);
assertEquals(expected, document.toJson(), false);
}
Aggregations