use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method shouldReadEntityWithGeoBoxCorrectly.
// DATAMONGO-858
@Test
void shouldReadEntityWithGeoBoxCorrectly() {
ClassWithGeoBox object = new ClassWithGeoBox();
object.box = new Box(new Point(1, 2), new Point(3, 4));
org.bson.Document document = new org.bson.Document();
converter.write(object, document);
ClassWithGeoBox result = converter.read(ClassWithGeoBox.class, document);
assertThat(result).isNotNull();
assertThat(result.box).isEqualTo(object.box);
}
use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method ignoresDocumentsStoredTypeIfCompletelyDifferentTypeRequested.
// DATAMONGO-128
@Test
void ignoresDocumentsStoredTypeIfCompletelyDifferentTypeRequested() {
org.bson.Document document = new org.bson.Document();
document.put("birthDate", new LocalDate());
document.put(DefaultMongoTypeMapper.DEFAULT_TYPE_KEY, Person.class.getName());
assertThat(converter.read(BirthDateContainer.class, document)).isInstanceOf(BirthDateContainer.class);
}
use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method convertsLocalesOutOfTheBox.
@Test
void convertsLocalesOutOfTheBox() {
LocaleWrapper wrapper = new LocaleWrapper();
wrapper.locale = Locale.US;
org.bson.Document document = new org.bson.Document();
converter.write(wrapper, document);
Object localeField = document.get("locale");
assertThat(localeField).isInstanceOf(String.class);
assertThat(localeField).isEqualTo("en_US");
LocaleWrapper read = converter.read(LocaleWrapper.class, document);
assertThat(read.locale).isEqualTo(Locale.US);
}
use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class QueryMapperUnitTests method handlesBigIntegerIdsCorrectly.
@Test
void handlesBigIntegerIdsCorrectly() {
org.bson.Document document = new org.bson.Document("id", new BigInteger("1"));
org.bson.Document result = mapper.getMappedObject(document, context.getPersistentEntity(IdWrapper.class));
assertThat(result).containsEntry("_id", "1");
}
use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class QueryMapperUnitTests method customizedFieldNameShouldBeMappedCorrectlyWhenApplyingSort.
// DATAMONGO-647
@Test
void customizedFieldNameShouldBeMappedCorrectlyWhenApplyingSort() {
Query query = query(where("field").is("bar")).with(Sort.by(Direction.DESC, "field"));
org.bson.Document document = mapper.getMappedObject(query.getSortObject(), context.getPersistentEntity(CustomizedField.class));
assertThat(document).isEqualTo(new org.bson.Document().append("foo", -1));
}
Aggregations