Skip to content

Commit aa06d52

Browse files
christophstroblodrotbohm
authored andcommitted
DATAMONGO-647 - Added test case to show that field names are mapped correctly.
Additional test added to check if the issue has truly been resolved by DATAMONGO-888. Original pull request: spring-projects#181. Related pull Request: spring-projects#162. Related ticket: DATAMONGO-888.
1 parent 4fa1d4b commit aa06d52

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/QueryMapperUnitTests.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import org.mockito.Mock;
3535
import org.mockito.runners.MockitoJUnitRunner;
3636
import org.springframework.data.annotation.Id;
37+
import org.springframework.data.domain.Sort;
38+
import org.springframework.data.domain.Sort.Direction;
3739
import org.springframework.data.mongodb.MongoDbFactory;
3840
import org.springframework.data.mongodb.core.DBObjectTestUtils;
3941
import org.springframework.data.mongodb.core.Person;
@@ -49,6 +51,7 @@
4951

5052
import com.mongodb.BasicDBList;
5153
import com.mongodb.BasicDBObject;
54+
import com.mongodb.BasicDBObjectBuilder;
5255
import com.mongodb.DBObject;
5356
import com.mongodb.QueryBuilder;
5457

@@ -586,6 +589,17 @@ public void classInformationShouldNotBePresentInDBObjectUsedInFinderMethods() {
586589
assertThat(dbo.toString(), equalTo("{ \"embedded\" : { \"$in\" : [ { \"_id\" : \"1\"} , { \"_id\" : \"2\"}]}}"));
587590
}
588591

592+
/**
593+
* @see DATAMONGO-647
594+
*/
595+
@Test
596+
public void customizedFieldNameShouldBeMappedCorrectlyWhenApplyingSort() {
597+
598+
Query query = query(where("field").is("bar")).with(new Sort(Direction.DESC, "field"));
599+
DBObject dbo = mapper.getMappedObject(query.getSortObject(), context.getPersistentEntity(CustomizedField.class));
600+
assertThat(dbo, equalTo(new BasicDBObjectBuilder().add("foo", -1).get()));
601+
}
602+
589603
@Document
590604
public class Foo {
591605
@Id private ObjectId id;

0 commit comments

Comments
 (0)