Search in sources :

Example 6 with Document

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

Example 7 with Document

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

Example 8 with Document

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

Example 9 with Document

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

Example 10 with Document

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));
}
Also used : BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) TextQuery(org.springframework.data.mongodb.core.query.TextQuery) Query(org.springframework.data.mongodb.core.query.Query) 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