DATAJPA-243 - QueryDslJpaRepository applies sort given through Pageable correctly.

During the refactoring of the Querydsl interaction a regression of not applying a Sort wrapped in a Pageable was introduced in QueryDsl utility class.
This commit is contained in:
Oliver Gierke
2012-08-13 10:28:12 +02:00
parent c90d1c122d
commit e59b8b3194
2 changed files with 24 additions and 1 deletions

View File

@@ -104,7 +104,7 @@ public class Querydsl {
query.offset(pageable.getOffset());
query.limit(pageable.getPageSize());
return query;
return applySorting(pageable.getSort(), query);
}
/**

View File

@@ -26,12 +26,16 @@ import javax.persistence.PersistenceContext;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.jpa.domain.sample.QUser;
import org.springframework.data.jpa.domain.sample.User;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import com.mysema.query.types.Predicate;
import com.mysema.query.types.expr.BooleanExpression;
import com.mysema.query.types.path.PathBuilder;
import com.mysema.query.types.path.PathBuilderFactory;
@@ -89,4 +93,23 @@ public class QueryDslJpaRepositoryTests {
assertThat(result.size(), is(2));
assertThat(result, hasItems(carter, dave));
}
/**
* @see DATAJPA-243
*/
@Test
public void considersSortingProvidedThroughPageable() {
Predicate lastnameContainsE = user.lastname.contains("e");
Page<User> result = repository.findAll(lastnameContainsE, new PageRequest(0, 1, Direction.ASC, "lastname"));
assertThat(result.getContent(), hasSize(1));
assertThat(result.getContent().get(0), is(carter));
result = repository.findAll(lastnameContainsE, new PageRequest(0, 1, Direction.DESC, "lastname"));
assertThat(result.getContent(), hasSize(1));
assertThat(result.getContent().get(0), is(dave));
}
}