Skip to content

Commit 1285880

Browse files
committed
fixed GeoJSON Test
1 parent b6f4af9 commit 1285880

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

springdata-mongodb/src/main/java/mongodb/geo/Location.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import org.springframework.data.annotation.Id;
44
import org.springframework.data.mongodb.core.geo.GeoJsonPoint;
5-
import org.springframework.data.mongodb.core.index.GeoSpatialIndexType;
6-
import org.springframework.data.mongodb.core.index.GeoSpatialIndexed;
75

86
/**
97
* A named location, using GeoJSON API.
@@ -13,7 +11,6 @@ public class Location {
1311

1412
@Id private String id;
1513

16-
@GeoSpatialIndexed(type = GeoSpatialIndexType.GEO_2DSPHERE)
1714
private GeoJsonPoint position;
1815

1916
public Location() {}

springdata-mongodb/src/test/java/mongodb/geo/LocationRepositoryTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
import org.springframework.data.geo.Distance;
1717
import org.springframework.data.geo.Metrics;
1818
import org.springframework.data.geo.Point;
19+
import org.springframework.data.mongodb.core.MongoTemplate;
20+
import org.springframework.data.mongodb.core.index.GeoSpatialIndexType;
21+
import org.springframework.data.mongodb.core.index.GeospatialIndex;
1922
import org.springframework.test.context.ContextConfiguration;
2023
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
2124

@@ -33,10 +36,17 @@ public class LocationRepositoryTest {
3336

3437
private static final Point DUS = new Point( 6.810036, 51.224088 );
3538

39+
@Autowired
40+
private MongoTemplate template;
41+
3642
@Autowired
3743
LocationRepository repo;
3844

3945
@Before public void setUp() {
46+
template
47+
.indexOps(Location.class)
48+
.ensureIndex(new GeospatialIndex("position").typed(GeoSpatialIndexType.GEO_2DSPHERE));
49+
4050
// prepare data
4151
repo.save( new Location("A", 0.001, -0.002) );
4252
repo.save( new Location("B", 1, 1) );

0 commit comments

Comments
 (0)