Search in sources :

Example 21 with Document

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

Example 22 with Document

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

Example 23 with Document

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)));
}
Also used : MongoException(com.mongodb.MongoException) BasicDbListBuilder(org.springframework.data.mongodb.test.util.BasicDbListBuilder) Point(org.springframework.data.geo.Point) Document(org.springframework.data.mongodb.core.mapping.Document) DataAccessException(org.springframework.dao.DataAccessException) Test(org.junit.jupiter.api.Test)

Example 24 with Document

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

Example 25 with Document

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"));
}
Also used : Document(org.springframework.data.mongodb.core.mapping.Document) URL(java.net.URL) 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