|
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.
|
|
53 | 53 | import org.springframework.data.mongodb.core.query.BasicQuery;
|
54 | 54 | import org.springframework.data.mongodb.core.query.Criteria;
|
55 | 55 | import org.springframework.data.mongodb.core.query.Query;
|
| 56 | +import org.springframework.data.mongodb.test.util.BasicDbListBuilder; |
56 | 57 |
|
57 | 58 | import com.mongodb.BasicDBList;
|
58 | 59 | import com.mongodb.BasicDBObject;
|
|
67 | 68 | * @author Patryk Wasik
|
68 | 69 | * @author Thomas Darimont
|
69 | 70 | * @author Christoph Strobl
|
| 71 | + * @author Mark Paluch |
70 | 72 | */
|
71 | 73 | @RunWith(MockitoJUnitRunner.class)
|
72 | 74 | public class QueryMapperUnitTests {
|
@@ -594,6 +596,28 @@ public void classInformationShouldNotBePresentInDBObjectUsedInFinderMethods() {
|
594 | 596 | assertThat(dbo.toString(), equalTo("{ \"embedded\" : { \"$in\" : [ { \"_id\" : \"1\"} , { \"_id\" : \"2\"}]}}"));
|
595 | 597 | }
|
596 | 598 |
|
| 599 | + /** |
| 600 | + * @see DATAMONGO-1406 |
| 601 | + */ |
| 602 | + @Test |
| 603 | + public void shouldMapQueryForNestedCustomizedPropertiesUsingConfiguredFieldNames() { |
| 604 | + |
| 605 | + EmbeddedClass embeddedClass = new EmbeddedClass(); |
| 606 | + embeddedClass.customizedField = "hello"; |
| 607 | + |
| 608 | + Foo foo = new Foo(); |
| 609 | + foo.listOfItems = Arrays.asList(embeddedClass); |
| 610 | + |
| 611 | + Query query = new Query(Criteria.where("listOfItems") // |
| 612 | + .elemMatch(new Criteria(). // |
| 613 | + andOperator(Criteria.where("customizedField").is(embeddedClass.customizedField)))); |
| 614 | + |
| 615 | + DBObject dbo = mapper.getMappedObject(query.getQueryObject(), context.getPersistentEntity(Foo.class)); |
| 616 | + |
| 617 | + assertThat(dbo, isBsonObject().containing("my_items.$elemMatch.$and", |
| 618 | + new BasicDbListBuilder().add(new BasicDBObject("fancy_custom_name", embeddedClass.customizedField)).get())); |
| 619 | + } |
| 620 | + |
597 | 621 | /**
|
598 | 622 | * @see DATAMONGO-647
|
599 | 623 | */
|
@@ -822,10 +846,14 @@ public void mappingShouldRetainNumericPositionInList() {
|
822 | 846 | public class Foo {
|
823 | 847 | @Id private ObjectId id;
|
824 | 848 | EmbeddedClass embedded;
|
| 849 | + |
| 850 | + @Field("my_items") List<EmbeddedClass> listOfItems; |
825 | 851 | }
|
826 | 852 |
|
827 | 853 | public class EmbeddedClass {
|
828 | 854 | public String id;
|
| 855 | + |
| 856 | + @Field("fancy_custom_name") public String customizedField; |
829 | 857 | }
|
830 | 858 |
|
831 | 859 | class IdWrapper {
|
|
0 commit comments