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))));
}
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)))));
}
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()));
}
Aggregations