Search in sources :

Example 26 with Document

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);
}
Also used : DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) BasicDBList(com.mongodb.BasicDBList) Document(org.springframework.data.mongodb.core.mapping.Document) Test(org.junit.jupiter.api.Test)

Example 27 with Document

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);
}
Also used : BasicDBList(com.mongodb.BasicDBList) Document(org.springframework.data.mongodb.core.mapping.Document) Test(org.junit.jupiter.api.Test)

Example 28 with Document

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);
}
Also used : Document(org.springframework.data.mongodb.core.mapping.Document) MappingInstantiationException(org.springframework.data.mapping.model.MappingInstantiationException) ConverterNotFoundException(org.springframework.core.convert.ConverterNotFoundException) MappingException(org.springframework.data.mapping.MappingException) ConversionNotSupportedException(org.springframework.beans.ConversionNotSupportedException) Test(org.junit.jupiter.api.Test)

Example 29 with 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)));
}
Also used : BasicDBList(com.mongodb.BasicDBList) Point(org.springframework.data.geo.Point) Polygon(org.springframework.data.geo.Polygon) Document(org.springframework.data.mongodb.core.mapping.Document) Test(org.junit.jupiter.api.Test)

Example 30 with Document

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);
}
Also used : BasicDBList(com.mongodb.BasicDBList) Document(org.springframework.data.mongodb.core.mapping.Document) Test(org.junit.jupiter.api.Test)

Aggregations

Document (org.springframework.data.mongodb.core.mapping.Document)55 Test (org.junit.jupiter.api.Test)53 BasicQuery (org.springframework.data.mongodb.core.query.BasicQuery)16 Query (org.springframework.data.mongodb.core.query.Query)16 TextQuery (org.springframework.data.mongodb.core.query.TextQuery)16 Point (org.springframework.data.geo.Point)12 BasicDBList (com.mongodb.BasicDBList)8 BasicDBObject (com.mongodb.BasicDBObject)6 DBObject (com.mongodb.DBObject)5 DBRef (com.mongodb.DBRef)5 Sphere (org.springframework.data.mongodb.core.geo.Sphere)5 ObjectId (org.bson.types.ObjectId)4 Distance (org.springframework.data.geo.Distance)4 LocalDate (org.joda.time.LocalDate)3 MongoException (com.mongodb.MongoException)2 BigInteger (java.math.BigInteger)2 HashSet (java.util.HashSet)2 DataAccessException (org.springframework.dao.DataAccessException)2 Circle (org.springframework.data.geo.Circle)2 Polygon (org.springframework.data.geo.Polygon)2