41
41
import org .springframework .data .mapping .MappingException ;
42
42
import org .springframework .data .mongodb .core .aggregation .ExposedFields .DirectFieldReference ;
43
43
import org .springframework .data .mongodb .core .aggregation .ExposedFields .ExposedField ;
44
- import org .springframework .data .mongodb .core .aggregation .ExposedFields .FieldReference ;
45
44
import org .springframework .data .mongodb .core .convert .DbRefResolver ;
46
45
import org .springframework .data .mongodb .core .convert .MappingMongoConverter ;
47
46
import org .springframework .data .mongodb .core .convert .MongoCustomConversions ;
55
54
* @author Oliver Gierke
56
55
* @author Thomas Darimont
57
56
* @author Mark Paluch
57
+ * @author Christoph Strobl
58
58
*/
59
59
@ RunWith (MockitoJUnitRunner .class )
60
60
public class TypeBasedAggregationOperationContextUnitTests {
@@ -99,8 +99,7 @@ public void returnsReferencesToNestedFieldsCorrectly() {
99
99
public void aliasesIdFieldCorrectly () {
100
100
101
101
AggregationOperationContext context = getContext (Foo .class );
102
- assertThat (context .getReference ("id" ),
103
- is ((FieldReference ) new DirectFieldReference (new ExposedField (field ("id" , "_id" ), true ))));
102
+ assertThat (context .getReference ("id" ), is (new DirectFieldReference (new ExposedField (field ("id" , "_id" ), true ))));
104
103
}
105
104
106
105
@ Test // DATAMONGO-912
@@ -117,8 +116,7 @@ public void shouldUseCustomConversionIfPresentAndConversionIsRequiredInFirstStag
117
116
118
117
org .bson .Document agg = newAggregation (matchStage , projectStage ).toDocument ("test" , context );
119
118
120
- org .bson .Document age = getValue (
121
- (org .bson .Document ) getValue (getPipelineElementFromAggregationAt (agg , 0 ), "$match" ), "age" );
119
+ org .bson .Document age = getValue (getValue (getPipelineElementFromAggregationAt (agg , 0 ), "$match" ), "age" );
122
120
assertThat (age , is (new org .bson .Document ("v" , 10 )));
123
121
}
124
122
@@ -136,8 +134,7 @@ public void shouldUseCustomConversionIfPresentAndConversionIsRequiredInLaterStag
136
134
137
135
org .bson .Document agg = newAggregation (projectStage , matchStage ).toDocument ("test" , context );
138
136
139
- org .bson .Document age = getValue (
140
- (org .bson .Document ) getValue (getPipelineElementFromAggregationAt (agg , 1 ), "$match" ), "age" );
137
+ org .bson .Document age = getValue (getValue (getPipelineElementFromAggregationAt (agg , 1 ), "$match" ), "age" );
141
138
assertThat (age , is (new org .bson .Document ("v" , 10 )));
142
139
}
143
140
@@ -154,11 +151,11 @@ public void rendersAggregationOptionsInTypedAggregationContextCorrectly() {
154
151
org .bson .Document projection = getPipelineElementFromAggregationAt (document , 0 );
155
152
assertThat (projection .containsKey ("$project" ), is (true ));
156
153
157
- assertThat (projection .get ("$project" ), is (( Object ) new org . bson . Document ("name" , 1 ).append ("age" , 1 )));
154
+ assertThat (projection .get ("$project" ), is (new Document ("name" , 1 ).append ("age" , 1 )));
158
155
159
- assertThat (document .get ("allowDiskUse" ), is (( Object ) true ));
160
- assertThat (document .get ("explain" ), is (( Object ) true ));
161
- assertThat (document .get ("cursor" ), is (( Object ) new org . bson . Document ("foo" , 1 )));
156
+ assertThat (document .get ("allowDiskUse" ), is (true ));
157
+ assertThat (document .get ("explain" ), is (true ));
158
+ assertThat (document .get ("cursor" ), is (new Document ("foo" , 1 )));
162
159
}
163
160
164
161
@ Test // DATAMONGO-1585
@@ -172,25 +169,23 @@ public void rendersSortOfProjectedFieldCorrectly() {
172
169
Document sort = getPipelineElementFromAggregationAt (dbo , 1 );
173
170
174
171
Document definition = (Document ) sort .get ("$sort" );
175
- assertThat (definition .get ("counter" ), is (equalTo (( Object ) 1 )));
172
+ assertThat (definition .get ("counter" ), is (equalTo (1 )));
176
173
}
177
174
178
175
@ Test // DATAMONGO-1586
179
176
public void rendersFieldAliasingProjectionCorrectly () {
180
177
181
178
AggregationOperationContext context = getContext (FooPerson .class );
182
- TypedAggregation <FooPerson > agg = newAggregation (FooPerson .class ,
183
- project () //
184
- .and ("name" ).as ("person_name" ) //
185
- .and ("age.value" ).as ("age" ));
179
+ TypedAggregation <FooPerson > agg = newAggregation (FooPerson .class , project () //
180
+ .and ("name" ).as ("person_name" ) //
181
+ .and ("age.value" ).as ("age" ));
186
182
187
183
Document dbo = agg .toDocument ("person" , context );
188
184
189
185
Document projection = getPipelineElementFromAggregationAt (dbo , 0 );
190
- assertThat (getAsDocument (projection , "$project" ),
191
- isBsonObject () //
192
- .containing ("person_name" , "$name" ) //
193
- .containing ("age" , "$age.value" ));
186
+ assertThat (getAsDocument (projection , "$project" ), isBsonObject () //
187
+ .containing ("person_name" , "$name" ) //
188
+ .containing ("age" , "$age.value" ));
194
189
}
195
190
196
191
@ Test // DATAMONGO-1133
@@ -205,7 +200,7 @@ public void shouldHonorAliasedFieldsInGroupExpressions() {
205
200
206
201
org .bson .Document definition = (org .bson .Document ) group .get ("$group" );
207
202
208
- assertThat (definition .get ("_id" ), is (equalTo (( Object ) "$counter_name" )));
203
+ assertThat (definition .get ("_id" ), is (equalTo ("$counter_name" )));
209
204
}
210
205
211
206
@ Test // DATAMONGO-1326, DATAMONGO-1585
@@ -221,8 +216,8 @@ public void lookupShouldInheritFieldsFromInheritingAggregationOperation() {
221
216
222
217
org .bson .Document definition = (org .bson .Document ) sort .get ("$sort" );
223
218
224
- assertThat (definition .get ("resourceId" ), is (equalTo (( Object ) 1 )));
225
- assertThat (definition .get ("counter_name" ), is (equalTo (( Object ) 1 )));
219
+ assertThat (definition .get ("resourceId" ), is (equalTo (1 )));
220
+ assertThat (definition .get ("counter_name" ), is (equalTo (1 )));
226
221
}
227
222
228
223
@ Test // DATAMONGO-1326
@@ -237,7 +232,7 @@ public void groupLookupShouldInheritFieldsFromPreviousAggregationOperation() {
237
232
238
233
org .bson .Document definition = (org .bson .Document ) sort .get ("$sort" );
239
234
240
- assertThat (definition .get ("foreignKey" ), is (equalTo (( Object ) 1 )));
235
+ assertThat (definition .get ("foreignKey" ), is (equalTo (1 )));
241
236
}
242
237
243
238
@ Test // DATAMONGO-1326
@@ -254,7 +249,7 @@ public void lookupGroupAggregationShouldUseCorrectGroupField() {
254
249
org .bson .Document definition = (org .bson .Document ) group .get ("$group" );
255
250
org .bson .Document field = (org .bson .Document ) definition .get ("something_totally_different" );
256
251
257
- assertThat (field .get ("$min" ), is (equalTo (( Object ) "$lookup.otherkey" )));
252
+ assertThat (field .get ("$min" ), is (equalTo ("$lookup.otherkey" )));
258
253
}
259
254
260
255
@ Test // DATAMONGO-1326
@@ -271,7 +266,7 @@ public void lookupGroupAggregationShouldOverwriteExposedFields() {
271
266
272
267
org .bson .Document definition = (org .bson .Document ) sort .get ("$sort" );
273
268
274
- assertThat (definition .get ("something_totally_different" ), is (equalTo (( Object ) 1 )));
269
+ assertThat (definition .get ("something_totally_different" ), is (equalTo (1 )));
275
270
}
276
271
277
272
@ Test (expected = IllegalArgumentException .class ) // DATAMONGO-1326
@@ -289,11 +284,10 @@ public void lookupGroupAggregationShouldFailInvalidFieldReference() {
289
284
public void rendersAggregationConditionalInTypedAggregationContextCorrectly () {
290
285
291
286
AggregationOperationContext context = getContext (FooPerson .class );
292
- TypedAggregation <FooPerson > agg = newAggregation (FooPerson .class ,
293
- project ("name" ) //
294
- .and ("age" ) //
295
- .applyCondition (
296
- ConditionalOperators .when (Criteria .where ("age.value" ).lt (10 )).then (new Age (0 )).otherwiseValueOf ("age" )) //
287
+ TypedAggregation <FooPerson > agg = newAggregation (FooPerson .class , project ("name" ) //
288
+ .and ("age" ) //
289
+ .applyCondition (
290
+ ConditionalOperators .when (Criteria .where ("age.value" ).lt (10 )).then (new Age (0 )).otherwiseValueOf ("age" )) //
297
291
);
298
292
299
293
Document document = agg .toDocument ("person" , context );
@@ -316,10 +310,9 @@ public void rendersAggregationConditionalInTypedAggregationContextCorrectly() {
316
310
public void rendersAggregationIfNullInTypedAggregationContextCorrectly () {
317
311
318
312
AggregationOperationContext context = getContext (FooPerson .class );
319
- TypedAggregation <FooPerson > agg = newAggregation (FooPerson .class ,
320
- project ("name" ) //
321
- .and ("age" ) //
322
- .applyCondition (ConditionalOperators .ifNull ("age" ).then (new Age (0 ))) //
313
+ TypedAggregation <FooPerson > agg = newAggregation (FooPerson .class , project ("name" ) //
314
+ .and ("age" ) //
315
+ .applyCondition (ConditionalOperators .ifNull ("age" ).then (new Age (0 ))) //
323
316
);
324
317
325
318
Document document = agg .toDocument ("person" , context );
0 commit comments