36
36
import org .springframework .data .geo .Point ;
37
37
import org .springframework .data .geo .Polygon ;
38
38
import org .springframework .data .mongodb .core .MongoOperations ;
39
+ import org .springframework .data .mongodb .core .geo .GeoJsonPolygon ;
39
40
import org .springframework .data .mongodb .core .geo .Sphere ;
40
41
import org .springframework .data .mongodb .repository .ReadPreference ;
41
42
import org .springframework .data .repository .Repository ;
53
54
*/
54
55
public class QueryMethodContributionUnitTests {
55
56
56
- @ Test
57
+ @ Test // GH-5004
57
58
void rendersQueryForNearUsingPoint () throws NoSuchMethodException {
58
59
59
60
MethodSpec methodSpec = codeOf (UserRepository .class , "findByLocationCoordinatesNear" , Point .class );
@@ -64,7 +65,7 @@ void rendersQueryForNearUsingPoint() throws NoSuchMethodException {
64
65
.contains ("return finder.matching(filterQuery).all()" );
65
66
}
66
67
67
- @ Test
68
+ @ Test // GH-5004
68
69
void rendersQueryForWithinUsingCircle () throws NoSuchMethodException {
69
70
70
71
MethodSpec methodSpec = codeOf (UserRepository .class , "findByLocationCoordinatesWithin" , Circle .class );
@@ -76,7 +77,7 @@ void rendersQueryForWithinUsingCircle() throws NoSuchMethodException {
76
77
.contains ("return finder.matching(filterQuery).all()" );
77
78
}
78
79
79
- @ Test
80
+ @ Test // GH-5004
80
81
void rendersQueryForWithinUsingSphere () throws NoSuchMethodException {
81
82
82
83
MethodSpec methodSpec = codeOf (UserRepository .class , "findByLocationCoordinatesWithin" , Sphere .class );
@@ -88,7 +89,7 @@ void rendersQueryForWithinUsingSphere() throws NoSuchMethodException {
88
89
.contains ("return finder.matching(filterQuery).all()" );
89
90
}
90
91
91
- @ Test
92
+ @ Test // GH-5004
92
93
void rendersQueryForWithinUsingBox () throws NoSuchMethodException {
93
94
94
95
MethodSpec methodSpec = codeOf (UserRepository .class , "findByLocationCoordinatesWithin" , Box .class );
@@ -100,7 +101,7 @@ void rendersQueryForWithinUsingBox() throws NoSuchMethodException {
100
101
.contains ("return finder.matching(filterQuery).all()" );
101
102
}
102
103
103
- @ Test
104
+ @ Test // GH-5004
104
105
void rendersQueryForWithinUsingPolygon () throws NoSuchMethodException {
105
106
106
107
MethodSpec methodSpec = codeOf (UserRepository .class , "findByLocationCoordinatesWithin" , Polygon .class );
@@ -112,7 +113,18 @@ void rendersQueryForWithinUsingPolygon() throws NoSuchMethodException {
112
113
.contains ("return finder.matching(filterQuery).all()" );
113
114
}
114
115
115
- @ Test
116
+ @ Test // GH-5004
117
+ void rendersQueryForWithinUsingGeoJsonPolygon () throws NoSuchMethodException {
118
+
119
+ MethodSpec methodSpec = codeOf (UserRepository .class , "findByLocationCoordinatesWithin" , GeoJsonPolygon .class );
120
+
121
+ assertThat (methodSpec .toString ()) //
122
+ .contains ("{'location.coordinates':{'$geoWithin':{'$geometry':?0}}" ) //
123
+ .contains ("Object[]{ polygon }" ) //
124
+ .contains ("return finder.matching(filterQuery).all()" );
125
+ }
126
+
127
+ @ Test // GH-5004
116
128
void rendersNearQueryForGeoResults () throws NoSuchMethodException {
117
129
118
130
MethodSpec methodSpec = codeOf (UserRepoWithMeta .class , "findByLocationCoordinatesNear" , Point .class ,
@@ -127,23 +139,22 @@ void rendersNearQueryForGeoResults() throws NoSuchMethodException {
127
139
.contains ("return nearFinder.all()" );
128
140
}
129
141
130
- @ Test
142
+ @ Test // GH-5004
131
143
void rendersNearQueryWithDistanceRangeForGeoResults () throws NoSuchMethodException {
132
144
133
- MethodSpec methodSpec = codeOf (UserRepository .class , "findByLocationCoordinatesNear" , Point .class ,
134
- Range .class );
145
+ MethodSpec methodSpec = codeOf (UserRepository .class , "findByLocationCoordinatesNear" , Point .class , Range .class );
135
146
136
147
assertThat (methodSpec .toString ()) //
137
- .contains ("NearQuery.near(point)" ) //
138
- .contains ("if(distance.getLowerBound().isBounded())" ) //
139
- .contains ("nearQuery.minDistance(min).in(min.getMetric())" ) //
140
- .contains ("if(distance.getUpperBound().isBounded())" ) //
141
- .contains ("nearQuery.maxDistance(max).in(max.getMetric())" ) //
142
- .contains (".near(nearQuery)" ) //
143
- .contains ("return nearFinder.all()" );
148
+ .contains ("NearQuery.near(point)" ) //
149
+ .contains ("if(distance.getLowerBound().isBounded())" ) //
150
+ .contains ("nearQuery.minDistance(min).in(min.getMetric())" ) //
151
+ .contains ("if(distance.getUpperBound().isBounded())" ) //
152
+ .contains ("nearQuery.maxDistance(max).in(max.getMetric())" ) //
153
+ .contains (".near(nearQuery)" ) //
154
+ .contains ("return nearFinder.all()" );
144
155
}
145
156
146
- @ Test
157
+ @ Test // GH-5004
147
158
void rendersNearQueryReturningGeoPage () throws NoSuchMethodException {
148
159
149
160
MethodSpec methodSpec = codeOf (UserRepository .class , "findByLocationCoordinatesNear" , Point .class , Distance .class ,
@@ -158,7 +169,7 @@ void rendersNearQueryReturningGeoPage() throws NoSuchMethodException {
158
169
.contains ("GeoPage<>(geoResult, pageable, resultPage.getTotalElements())" );
159
170
}
160
171
161
- @ Test
172
+ @ Test // GH-5004
162
173
void rendersNearQueryWithFilterForGeoResults () throws NoSuchMethodException {
163
174
164
175
MethodSpec methodSpec = codeOf (UserRepository .class , "findByLocationCoordinatesNearAndLastname" , Point .class ,
0 commit comments