use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method shouldReadEntityWithGeoShapeCorrectly.
// DATAMONGO-858
@Test
@Disabled
void shouldReadEntityWithGeoShapeCorrectly() {
ClassWithGeoShape object = new ClassWithGeoShape();
Sphere sphere = new Sphere(new Point(1, 2), 3);
object.shape = sphere;
org.bson.Document document = new org.bson.Document();
converter.write(object, document);
ClassWithGeoShape result = converter.read(ClassWithGeoShape.class, document);
assertThat(result).isNotNull();
assertThat(result.shape).isEqualTo(sphere);
}
use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method resolvesDBRefMapValue.
// DATAMONGO-424
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
void resolvesDBRefMapValue() {
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);
assertThat(result.personMap.entrySet()).hasSize(1);
assertThat(result.personMap.values()).anyMatch(Person.class::isInstance);
}
use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class GeoJsonTests method shouldConvertLineStringRepresentationCorrectlyWhenSourceCoordinatesUsesInteger.
// DATAMONGO-1453
@Test
public void shouldConvertLineStringRepresentationCorrectlyWhenSourceCoordinatesUsesInteger() {
this.template.execute(template.getCollectionName(DocumentWithPropertyUsingGeoJsonType.class), new CollectionCallback<Object>() {
@Override
public Object doInCollection(MongoCollection<org.bson.Document> collection) throws MongoException, DataAccessException {
org.bson.Document lineStringRepresentation = new org.bson.Document();
lineStringRepresentation.put("type", "LineString");
lineStringRepresentation.put("coordinates", new BasicDbListBuilder().add(new BasicDbListBuilder().add(0).add(0).get()).add(new BasicDbListBuilder().add(1).add(1).get()).get());
org.bson.Document document = new org.bson.Document();
document.append("_id", "datamongo-1453");
document.append("geoJsonLineString", lineStringRepresentation);
collection.insertOne(document);
return document;
}
});
assertThat(template.findOne(query(where("id").is("datamongo-1453")), DocumentWithPropertyUsingGeoJsonType.class).geoJsonLineString).isEqualTo(new GeoJsonLineString(new Point(0D, 0D), new Point(1, 1)));
}
use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method usesDocumentsStoredTypeIfSubtypeOfRequest.
// DATAMONGO-128
@Test
void usesDocumentsStoredTypeIfSubtypeOfRequest() {
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(Contact.class, document)).isInstanceOf(Person.class);
}
use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method readsURLFromStringOutOfTheBox.
// DATAMONGO-462
@Test
void readsURLFromStringOutOfTheBox() throws Exception {
org.bson.Document document = new org.bson.Document("url", "https://springsource.org");
URLWrapper result = converter.read(URLWrapper.class, document);
assertThat(result.url).isEqualTo(new URL("https://springsource.org"));
}
Aggregations