|
1 | 1 | /*
|
2 |
| - * Copyright 2015 the original author or authors. |
| 2 | + * Copyright 2015-2016 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
29 | 29 | import org.junit.runner.RunWith;
|
30 | 30 | import org.springframework.beans.factory.annotation.Autowired;
|
31 | 31 | import org.springframework.context.annotation.Configuration;
|
| 32 | +import org.springframework.dao.DataAccessException; |
32 | 33 | import org.springframework.data.annotation.Id;
|
33 | 34 | import org.springframework.data.annotation.PersistenceConstructor;
|
34 | 35 | import org.springframework.data.geo.GeoResults;
|
35 | 36 | import org.springframework.data.geo.Metric;
|
36 | 37 | import org.springframework.data.geo.Metrics;
|
37 | 38 | import org.springframework.data.geo.Point;
|
38 | 39 | import org.springframework.data.mongodb.config.AbstractMongoConfiguration;
|
| 40 | +import org.springframework.data.mongodb.core.CollectionCallback; |
39 | 41 | import org.springframework.data.mongodb.core.MongoTemplate;
|
40 | 42 | import org.springframework.data.mongodb.core.index.GeoSpatialIndexType;
|
41 | 43 | import org.springframework.data.mongodb.core.index.GeoSpatialIndexed;
|
42 | 44 | import org.springframework.data.mongodb.core.index.GeospatialIndex;
|
43 | 45 | import org.springframework.data.mongodb.core.mapping.Document;
|
44 | 46 | import org.springframework.data.mongodb.core.query.NearQuery;
|
45 | 47 | import org.springframework.data.mongodb.core.query.Query;
|
| 48 | +import org.springframework.data.mongodb.test.util.BasicDbListBuilder; |
46 | 49 | import org.springframework.test.context.ContextConfiguration;
|
47 | 50 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
48 | 51 |
|
| 52 | +import com.mongodb.BasicDBObject; |
| 53 | +import com.mongodb.DBCollection; |
49 | 54 | import com.mongodb.Mongo;
|
50 | 55 | import com.mongodb.MongoClient;
|
| 56 | +import com.mongodb.MongoException; |
51 | 57 | import com.mongodb.WriteConcern;
|
| 58 | +import com.mongodb.client.MongoCollection; |
52 | 59 |
|
53 | 60 | /**
|
54 | 61 | * @author Christoph Strobl
|
@@ -317,6 +324,67 @@ public void nearWithMinAndMaxDistance() {
|
317 | 324 | assertThat(venues.size(), is(2));
|
318 | 325 | }
|
319 | 326 |
|
| 327 | + /** |
| 328 | + * @see DATAMONGO-1453 |
| 329 | + */ |
| 330 | + @Test |
| 331 | + public void shouldConvertPointRepresentationCorrectlyWhenSourceCoordinatesUsesInteger() { |
| 332 | + |
| 333 | + this.template.execute(template.getCollectionName(DocumentWithPropertyUsingGeoJsonType.class), |
| 334 | + new CollectionCallback<Object>() { |
| 335 | + |
| 336 | + @Override |
| 337 | + public Object doInCollection(MongoCollection<org.bson.Document> collection) throws MongoException, DataAccessException { |
| 338 | + |
| 339 | + org.bson.Document pointRepresentation = new org.bson.Document(); |
| 340 | + pointRepresentation.put("type", "Point"); |
| 341 | + pointRepresentation.put("coordinates", Arrays.asList(0, 0)); |
| 342 | + |
| 343 | + org.bson.Document document = new org.bson.Document(); |
| 344 | + document.append("_id", "datamongo-1453"); |
| 345 | + document.append("geoJsonPoint", pointRepresentation); |
| 346 | + |
| 347 | + collection.insertOne(document); |
| 348 | + return null; |
| 349 | + } |
| 350 | + }); |
| 351 | + |
| 352 | + assertThat(template.findOne(query(where("id").is("datamongo-1453")), |
| 353 | + DocumentWithPropertyUsingGeoJsonType.class).geoJsonPoint, is(equalTo(new GeoJsonPoint(0D, 0D)))); |
| 354 | + } |
| 355 | + |
| 356 | + /** |
| 357 | + * @see DATAMONGO-1453 |
| 358 | + */ |
| 359 | + @Test |
| 360 | + public void shouldConvertLineStringRepresentationCorrectlyWhenSourceCoordinatesUsesInteger() { |
| 361 | + |
| 362 | + this.template.execute(template.getCollectionName(DocumentWithPropertyUsingGeoJsonType.class), |
| 363 | + new CollectionCallback<Object>() { |
| 364 | + |
| 365 | + @Override |
| 366 | + public Object doInCollection(MongoCollection<org.bson.Document> collection) throws MongoException, DataAccessException { |
| 367 | + |
| 368 | + org.bson.Document lineStringRepresentation = new org.bson.Document(); |
| 369 | + lineStringRepresentation.put("type", "LineString"); |
| 370 | + lineStringRepresentation.put("coordinates", |
| 371 | + Arrays.asList(Arrays.asList(0, 0), Arrays.asList(1, 1))); |
| 372 | + |
| 373 | + org.bson.Document document = new org.bson.Document(); |
| 374 | + document.append("_id", "datamongo-1453"); |
| 375 | + document.append("geoJsonLineString", lineStringRepresentation); |
| 376 | + |
| 377 | + collection.insertOne(document); |
| 378 | + return null; |
| 379 | + } |
| 380 | + }); |
| 381 | + |
| 382 | + assertThat( |
| 383 | + template.findOne(query(where("id").is("datamongo-1453")), |
| 384 | + DocumentWithPropertyUsingGeoJsonType.class).geoJsonLineString, |
| 385 | + is(equalTo(new GeoJsonLineString(new Point(0D, 0D), new Point(1, 1))))); |
| 386 | + } |
| 387 | + |
320 | 388 | private void addVenues() {
|
321 | 389 |
|
322 | 390 | template.insert(new Venue2DSphere("Penn Station", -73.99408, 40.75057));
|
|
0 commit comments