|
19 | 19 | import static org.junit.Assert.*;
|
20 | 20 | import static org.springframework.data.mongodb.core.aggregation.AggregationFunctionExpressions.*;
|
21 | 21 | import static org.springframework.data.mongodb.core.aggregation.Fields.*;
|
| 22 | +import static org.springframework.data.mongodb.test.util.IsBsonObject.*; |
22 | 23 | import static org.springframework.data.mongodb.util.DBObjectUtils.*;
|
23 | 24 |
|
24 | 25 | import java.util.Arrays;
|
@@ -402,6 +403,90 @@ public void shouldRenderSliceWithPositionCorrectly() throws Exception {
|
402 | 403 | is((Object) new BasicDBObject("$slice", Arrays.<Object> asList("$field", 5, 10))));
|
403 | 404 | }
|
404 | 405 |
|
| 406 | + /** |
| 407 | + * @see DATAMONGO-784 |
| 408 | + */ |
| 409 | + @Test |
| 410 | + public void shouldRenderCmpCorrectly() { |
| 411 | + |
| 412 | + ProjectionOperation operation = Aggregation.project().and("field").cmp(10).as("cmp10"); |
| 413 | + |
| 414 | + assertThat(operation.toDBObject(Aggregation.DEFAULT_CONTEXT), |
| 415 | + isBsonObject().containing("$project.cmp10.$cmp.[0]", "$field").containing("$project.cmp10.$cmp.[1]", 10)); |
| 416 | + } |
| 417 | + |
| 418 | + /** |
| 419 | + * @see DATAMONGO-784 |
| 420 | + */ |
| 421 | + @Test |
| 422 | + public void shouldRenderEqCorrectly() { |
| 423 | + |
| 424 | + ProjectionOperation operation = Aggregation.project().and("field").eq(10).as("eq10"); |
| 425 | + |
| 426 | + assertThat(operation.toDBObject(Aggregation.DEFAULT_CONTEXT), |
| 427 | + isBsonObject().containing("$project.eq10.$eq.[0]", "$field").containing("$project.eq10.$eq.[1]", 10)); |
| 428 | + } |
| 429 | + |
| 430 | + /** |
| 431 | + * @see DATAMONGO-784 |
| 432 | + */ |
| 433 | + @Test |
| 434 | + public void shouldRenderGtCorrectly() { |
| 435 | + |
| 436 | + ProjectionOperation operation = Aggregation.project().and("field").gt(10).as("gt10"); |
| 437 | + |
| 438 | + assertThat(operation.toDBObject(Aggregation.DEFAULT_CONTEXT), |
| 439 | + isBsonObject().containing("$project.gt10.$gt.[0]", "$field").containing("$project.gt10.$gt.[1]", 10)); |
| 440 | + } |
| 441 | + |
| 442 | + /** |
| 443 | + * @see DATAMONGO-784 |
| 444 | + */ |
| 445 | + @Test |
| 446 | + public void shouldRenderGteCorrectly() { |
| 447 | + |
| 448 | + ProjectionOperation operation = Aggregation.project().and("field").gte(10).as("gte10"); |
| 449 | + |
| 450 | + assertThat(operation.toDBObject(Aggregation.DEFAULT_CONTEXT), |
| 451 | + isBsonObject().containing("$project.gte10.$gte.[0]", "$field").containing("$project.gte10.$gte.[1]", 10)); |
| 452 | + } |
| 453 | + |
| 454 | + /** |
| 455 | + * @see DATAMONGO-784 |
| 456 | + */ |
| 457 | + @Test |
| 458 | + public void shouldRenderLtCorrectly() { |
| 459 | + |
| 460 | + ProjectionOperation operation = Aggregation.project().and("field").lt(10).as("lt10"); |
| 461 | + |
| 462 | + assertThat(operation.toDBObject(Aggregation.DEFAULT_CONTEXT), |
| 463 | + isBsonObject().containing("$project.lt10.$lt.[0]", "$field").containing("$project.lt10.$lt.[1]", 10)); |
| 464 | + } |
| 465 | + |
| 466 | + /** |
| 467 | + * @see DATAMONGO-784 |
| 468 | + */ |
| 469 | + @Test |
| 470 | + public void shouldRenderLteCorrectly() { |
| 471 | + |
| 472 | + ProjectionOperation operation = Aggregation.project().and("field").lte(10).as("lte10"); |
| 473 | + |
| 474 | + assertThat(operation.toDBObject(Aggregation.DEFAULT_CONTEXT), |
| 475 | + isBsonObject().containing("$project.lte10.$lte.[0]", "$field").containing("$project.lte10.$lte.[1]", 10)); |
| 476 | + } |
| 477 | + |
| 478 | + /** |
| 479 | + * @see DATAMONGO-784 |
| 480 | + */ |
| 481 | + @Test |
| 482 | + public void shouldRenderNeCorrectly() { |
| 483 | + |
| 484 | + ProjectionOperation operation = Aggregation.project().and("field").ne(10).as("ne10"); |
| 485 | + |
| 486 | + assertThat(operation.toDBObject(Aggregation.DEFAULT_CONTEXT), |
| 487 | + isBsonObject().containing("$project.ne10.$ne.[0]", "$field").containing("$project.ne10.$ne.[1]", 10)); |
| 488 | + } |
| 489 | + |
405 | 490 | private static DBObject exctractOperation(String field, DBObject fromProjectClause) {
|
406 | 491 | return (DBObject) fromProjectClause.get(field);
|
407 | 492 | }
|
|
0 commit comments