Skip to content

Commit d55f756

Browse files
author
Thomas Darimont
committed
DATAMONGO-1085 - Sort can not use the metamodel classes generated by QueryDSL.
Added test case for sorting with a QueryDSL OrderSpecifier. Seems to work as expected.
1 parent cb8f219 commit d55f756

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/AbstractPersonRepositoryIntegrationTests.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
import org.springframework.data.mongodb.repository.Person.Sex;
5050
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
5151

52+
import com.google.common.collect.Lists;
53+
5254
/**
5355
* Base class for tests for {@link PersonRepository}.
5456
*
@@ -1060,4 +1062,32 @@ public void shouldBindPlaceholdersUsedAsKeysCorrectly() {
10601062
assertThat(persons, hasSize(1));
10611063
assertThat(persons, hasItem(alicia));
10621064
}
1065+
1066+
/**
1067+
* @see DATAMONGO-1085
1068+
*/
1069+
@Test
1070+
public void shouldSupportSortingByQueryDslOrderSpecifier() {
1071+
1072+
repository.deleteAll();
1073+
1074+
List<Person> persons = new ArrayList<Person>();
1075+
for (int i = 0; i < 3; i++) {
1076+
1077+
Person pers = new Person(String.format("Siggi %s", i), "Bar", 30);
1078+
pers.setAddress(new Address(String.format("Street %s", i), "12345", "SinCity"));
1079+
1080+
persons.add(pers);
1081+
}
1082+
1083+
repository.save(persons);
1084+
1085+
QPerson person = QPerson.person;
1086+
1087+
List<Person> result = Lists.newArrayList(repository.findAll(person.firstname.isNotNull(),
1088+
person.address.street.desc()));
1089+
1090+
assertThat(result, hasSize(persons.size()));
1091+
assertThat(result.get(0).getFirstname(), is(persons.get(2).getFirstname()));
1092+
}
10631093
}

0 commit comments

Comments
 (0)