|
1 | 1 | /* |
2 | | - * Copyright 2011-2015 the original author or authors. |
| 2 | + * Copyright 2011-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. |
|
35 | 35 | import org.junit.runner.RunWith; |
36 | 36 | import org.mockito.Mock; |
37 | 37 | import org.mockito.runners.MockitoJUnitRunner; |
| 38 | + |
38 | 39 | import org.springframework.data.annotation.Id; |
39 | 40 | import org.springframework.data.domain.Sort; |
40 | 41 | import org.springframework.data.domain.Sort.Direction; |
|
54 | 55 | import org.springframework.data.mongodb.core.query.BasicQuery; |
55 | 56 | import org.springframework.data.mongodb.core.query.Criteria; |
56 | 57 | import org.springframework.data.mongodb.core.query.Query; |
| 58 | +import org.springframework.data.mongodb.test.util.BasicDbListBuilder; |
57 | 59 |
|
58 | 60 | import com.mongodb.BasicDBList; |
59 | 61 | import com.mongodb.BasicDBObject; |
|
68 | 70 | * @author Patryk Wasik |
69 | 71 | * @author Thomas Darimont |
70 | 72 | * @author Christoph Strobl |
| 73 | + * @author Mark Paluch |
71 | 74 | */ |
72 | 75 | @RunWith(MockitoJUnitRunner.class) |
73 | 76 | public class QueryMapperUnitTests { |
@@ -595,6 +598,28 @@ public void classInformationShouldNotBePresentInDBObjectUsedInFinderMethods() { |
595 | 598 | assertThat(dbo.toString(), equalTo("{ \"embedded\" : { \"$in\" : [ { \"_id\" : \"1\"} , { \"_id\" : \"2\"}]}}")); |
596 | 599 | } |
597 | 600 |
|
| 601 | +/** |
| 602 | + * @see DATAMONGO-1406 |
| 603 | + */ |
| 604 | +@Test |
| 605 | +public void shouldMapQueryForNestedCustomizedPropertiesUsingConfiguredFieldNames() { |
| 606 | + |
| 607 | +EmbeddedClass embeddedClass = new EmbeddedClass(); |
| 608 | +embeddedClass.customizedField = "hello"; |
| 609 | + |
| 610 | +Foo foo = new Foo(); |
| 611 | +foo.listOfItems = Arrays.asList(embeddedClass); |
| 612 | + |
| 613 | +Query query = new Query(Criteria.where("listOfItems") // |
| 614 | +.elemMatch(new Criteria(). // |
| 615 | +andOperator(Criteria.where("customizedField").is(embeddedClass.customizedField)))); |
| 616 | + |
| 617 | +DBObject dbo = mapper.getMappedObject(query.getQueryObject(), context.getPersistentEntity(Foo.class)); |
| 618 | + |
| 619 | +assertThat(dbo, isBsonObject().containing("my_items.$elemMatch.$and", |
| 620 | +new BasicDbListBuilder().add(new BasicDBObject("fancy_custom_name", embeddedClass.customizedField)).get())); |
| 621 | +} |
| 622 | + |
598 | 623 | /** |
599 | 624 | * @see DATAMONGO-647 |
600 | 625 | */ |
@@ -792,8 +817,7 @@ public void intersectsShouldUseGeoJsonRepresentationCorrectly() { |
792 | 817 | } |
793 | 818 |
|
794 | 819 | /** |
795 | | - * <<<<<<< HEAD |
796 | | - * |
| 820 | + * |
797 | 821 | * @see DATAMONGO-1269 |
798 | 822 | */ |
799 | 823 | @Test |
@@ -859,10 +883,15 @@ public void exampleShouldBeMappedCorrectlyWhenContainingLegacyPoint() { |
859 | 883 | public class Foo { |
860 | 884 | @Id private ObjectId id; |
861 | 885 | EmbeddedClass embedded; |
| 886 | + |
| 887 | +@Field("my_items") |
| 888 | +List<EmbeddedClass> listOfItems; |
862 | 889 | } |
863 | 890 |
|
864 | 891 | public class EmbeddedClass { |
865 | 892 | public String id; |
| 893 | + |
| 894 | +@Field("fancy_custom_name") public String customizedField; |
866 | 895 | } |
867 | 896 |
|
868 | 897 | class IdWrapper { |
|
0 commit comments