Search in sources :

Example 1 with BasicDbListBuilder

use of org.springframework.data.mongodb.test.util.BasicDbListBuilder in project spring-data-mongodb by spring-projects.

the class GeoJsonTests method shouldConvertPointRepresentationCorrectlyWhenSourceCoordinatesUsesInteger.

// DATAMONGO-1453
@Test
public void shouldConvertPointRepresentationCorrectlyWhenSourceCoordinatesUsesInteger() {
    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 pointRepresentation = new org.bson.Document();
            pointRepresentation.put("type", "Point");
            pointRepresentation.put("coordinates", new BasicDbListBuilder().add(0).add(0).get());
            org.bson.Document document = new org.bson.Document();
            document.append("_id", "datamongo-1453");
            document.append("geoJsonPoint", pointRepresentation);
            collection.insertOne(document);
            return document;
        }
    });
    assertThat(template.findOne(query(where("id").is("datamongo-1453")), DocumentWithPropertyUsingGeoJsonType.class).geoJsonPoint, is(equalTo(new GeoJsonPoint(0D, 0D))));
}
Also used : MongoException(com.mongodb.MongoException) BasicDbListBuilder(org.springframework.data.mongodb.test.util.BasicDbListBuilder) DataAccessException(org.springframework.dao.DataAccessException) Test(org.junit.Test)

Example 2 with BasicDbListBuilder

use of org.springframework.data.mongodb.test.util.BasicDbListBuilder 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, is(equalTo(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) DataAccessException(org.springframework.dao.DataAccessException) Test(org.junit.Test)

Example 3 with BasicDbListBuilder

use of org.springframework.data.mongodb.test.util.BasicDbListBuilder in project spring-data-mongodb by spring-projects.

the class QueryMapperUnitTests method shouldMapQueryForNestedCustomizedPropertiesUsingConfiguredFieldNames.

// DATAMONGO-1406
@Test
public void shouldMapQueryForNestedCustomizedPropertiesUsingConfiguredFieldNames() {
    EmbeddedClass embeddedClass = new EmbeddedClass();
    embeddedClass.customizedField = "hello";
    Foo foo = new Foo();
    foo.listOfItems = Arrays.asList(embeddedClass);
    Query query = new Query(// 
    Criteria.where("listOfItems").elemMatch(// 
    new Criteria().andOperator(Criteria.where("customizedField").is(embeddedClass.customizedField))));
    org.bson.Document document = mapper.getMappedObject(query.getQueryObject(), context.getPersistentEntity(Foo.class));
    assertThat(document, isBsonObject().containing("my_items.$elemMatch.$and", new BasicDbListBuilder().add(new BasicDBObject("fancy_custom_name", embeddedClass.customizedField)).get()));
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) Query(org.springframework.data.mongodb.core.query.Query) BasicDbListBuilder(org.springframework.data.mongodb.test.util.BasicDbListBuilder) Criteria(org.springframework.data.mongodb.core.query.Criteria) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 BasicDbListBuilder (org.springframework.data.mongodb.test.util.BasicDbListBuilder)3 MongoException (com.mongodb.MongoException)2 DataAccessException (org.springframework.dao.DataAccessException)2 BasicDBObject (com.mongodb.BasicDBObject)1 Point (org.springframework.data.geo.Point)1 BasicQuery (org.springframework.data.mongodb.core.query.BasicQuery)1 Criteria (org.springframework.data.mongodb.core.query.Criteria)1 Query (org.springframework.data.mongodb.core.query.Query)1