use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method writesNestedCollectionsCorrectly.
@Test
void writesNestedCollectionsCorrectly() {
CollectionWrapper wrapper = new CollectionWrapper();
wrapper.strings = Arrays.asList(Arrays.asList("Foo"));
org.bson.Document document = new org.bson.Document();
converter.write(wrapper, document);
Object outerStrings = document.get("strings");
assertThat(outerStrings).isInstanceOf(List.class);
List<Object> typedOuterString = (List<Object>) outerStrings;
assertThat(typedOuterString.size()).isEqualTo(1);
}
use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method readsEnumCollectionsCorrectly.
// DATAMONGO-209
@Test
void readsEnumCollectionsCorrectly() {
BasicDBList enums = new BasicDBList();
enums.add("FIRST");
org.bson.Document document = new org.bson.Document("enums", enums);
ClassWithEnumProperty result = converter.read(ClassWithEnumProperty.class, document);
assertThat(result.enums).isInstanceOf(List.class);
assertThat(result.enums.size()).isEqualTo(1);
assertThat(result.enums).contains(SampleEnum.FIRST);
}
use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method marshalsThrowableCorrectly.
// DATAMONGO-533
@Test
void marshalsThrowableCorrectly() {
ThrowableWrapper wrapper = new ThrowableWrapper();
wrapper.throwable = new Exception();
org.bson.Document document = new org.bson.Document();
converter.write(wrapper, document);
}
use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method shouldWriteEntityWithGeoPolygonCorrectly.
// DATAMONGO-858
@Test
void shouldWriteEntityWithGeoPolygonCorrectly() {
ClassWithGeoPolygon object = new ClassWithGeoPolygon();
object.polygon = new Polygon(new Point(1, 2), new Point(3, 4), new Point(4, 5));
org.bson.Document document = new org.bson.Document();
converter.write(object, document);
assertThat(document).isNotNull();
assertThat(document.get("polygon")).isInstanceOf(org.bson.Document.class);
org.bson.Document polygonDoc = (org.bson.Document) document.get("polygon");
@SuppressWarnings("unchecked") List<org.bson.Document> points = (List<org.bson.Document>) polygonDoc.get("points");
assertThat(points).hasSize(3);
assertThat(points).contains(toDocument(object.polygon.getPoints().get(0)), toDocument(object.polygon.getPoints().get(1)), toDocument(object.polygon.getPoints().get(2)));
}
use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method readsEnumSetCorrectly.
// DATAMONGO-833
@Test
void readsEnumSetCorrectly() {
BasicDBList enumSet = new BasicDBList();
enumSet.add("SECOND");
org.bson.Document document = new org.bson.Document("enumSet", enumSet);
ClassWithEnumProperty result = converter.read(ClassWithEnumProperty.class, document);
assertThat(result.enumSet).isInstanceOf(EnumSet.class);
assertThat(result.enumSet.size()).isEqualTo(1);
assertThat(result.enumSet).contains(SampleEnum.SECOND);
}
Aggregations