use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method convertsJodaTimeTypesCorrectly.
@Test
void convertsJodaTimeTypesCorrectly() {
converter = new MappingMongoConverter(resolver, mappingContext);
converter.afterPropertiesSet();
Person person = new Person();
person.birthDate = new LocalDate();
org.bson.Document document = new org.bson.Document();
converter.write(person, document);
assertThat(document.get("birthDate")).isInstanceOf(Date.class);
Person result = converter.read(Person.class, document);
assertThat(result.birthDate).isNotNull();
}
use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method writesCollectionWithInterfaceCorrectly.
// DATAMONGO-145
@Test
void writesCollectionWithInterfaceCorrectly() {
Person person = new Person();
person.firstname = "Oliver";
CollectionWrapper wrapper = new CollectionWrapper();
wrapper.contacts = Arrays.asList((Contact) person);
org.bson.Document document = new org.bson.Document();
converter.write(wrapper, document);
Object result = document.get("contacts");
assertThat(result).isInstanceOf(List.class);
List<Object> contacts = (List<Object>) result;
org.bson.Document personDocument = (org.bson.Document) contacts.get(0);
assertThat(personDocument.get("foo").toString()).isEqualTo("Oliver");
assertThat((String) personDocument.get(DefaultMongoTypeMapper.DEFAULT_TYPE_KEY)).isEqualTo(Person.class.getName());
}
use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method shouldReadEntityWithGeoCircleCorrectly.
// DATAMONGO-858
@Test
void shouldReadEntityWithGeoCircleCorrectly() {
ClassWithGeoCircle object = new ClassWithGeoCircle();
object.circle = new Circle(new Point(1, 2), 3);
org.bson.Document document = new org.bson.Document();
converter.write(object, document);
ClassWithGeoCircle result = converter.read(ClassWithGeoCircle.class, document);
assertThat(result).isNotNull();
assertThat(result.circle).isEqualTo(result.circle);
}
use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method resolveDBRefMapValueShouldInvokeCallbacks.
// DATAMONGO-2479
@Test
void resolveDBRefMapValueShouldInvokeCallbacks() {
AfterConvertCallback<Person> afterConvertCallback = spy(new ReturningAfterConvertCallback());
converter.setEntityCallbacks(EntityCallbacks.create(afterConvertCallback));
when(resolver.fetch(Mockito.any(DBRef.class))).thenReturn(new org.bson.Document());
DBRef dbRef = mock(DBRef.class);
org.bson.Document refMap = new org.bson.Document("foo", dbRef);
org.bson.Document document = new org.bson.Document("personMap", refMap);
DBRefWrapper result = converter.read(DBRefWrapper.class, document);
verify(afterConvertCallback).onAfterConvert(eq(result.personMap.get("foo")), eq(new org.bson.Document()), any());
}
use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method shouldWriteEntityWithGeoSphereCorrectly.
// DATAMONGO-858
@Test
void shouldWriteEntityWithGeoSphereCorrectly() {
ClassWithGeoSphere object = new ClassWithGeoSphere();
Sphere sphere = new Sphere(new Point(1, 2), 3);
Distance radius = sphere.getRadius();
object.sphere = sphere;
org.bson.Document document = new org.bson.Document();
converter.write(object, document);
assertThat(document).isNotNull();
assertThat(document.get("sphere")).isInstanceOf(org.bson.Document.class);
assertThat(document.get("sphere")).isEqualTo((Object) new org.bson.Document("center", new org.bson.Document("x", sphere.getCenter().getX()).append("y", sphere.getCenter().getY())).append("radius", radius.getNormalizedValue()).append("metric", radius.getMetric().toString()));
}
Aggregations