DATAJPA-596 - Allow sorting by Querydsl operator expression.

Added test case for sorting by Querydsl operator expression.

Original pull request: #107.
This commit is contained in:
Thomas Darimont
2014-08-26 13:44:29 +02:00
committed by Oliver Gierke
parent f52167ed40
commit ebb2be942a
2 changed files with 31 additions and 2 deletions

View File

@@ -84,6 +84,8 @@ public class User {
@Lob private byte[] binaryData;
@ElementCollection private Set<String> attributes;
@Temporal(TemporalType.DATE) private Date dateOfBirth;
/**
* Creates a new empty instance of {@code User}.
@@ -365,6 +367,14 @@ public class User {
public void setAttributes(Set<String> attributes) {
this.attributes = attributes;
}
public Date getDateOfBirth() {
return dateOfBirth;
}
public void setDateOfBirth(Date dateOfBirth) {
this.dateOfBirth = dateOfBirth;
}
/*
* (non-Javadoc)

View File

@@ -15,14 +15,17 @@
*/
package org.springframework.data.jpa.repository.support;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.joda.time.LocalDate;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -309,4 +312,20 @@ public class QueryDslJpaRepositoryTests {
assertThat(users, hasSize(3));
assertThat(users, hasItems(dave, oliver, carter));
}
/**
* @DATAJPA-566
*/
@Test
public void shouldSupportSortByOperatorWithDateExpressions() {
carter.setDateOfBirth(new LocalDate(2000, 2, 1).toDate());
dave.setDateOfBirth(new LocalDate(2000, 1, 1).toDate());
oliver.setDateOfBirth(new LocalDate(2003, 5, 1).toDate());
List<User> users = repository.findAll(QUser.user.id.goe(0), QUser.user.dateOfBirth.yearMonth().asc());
assertThat(users, hasSize(3));
assertThat(users, hasItems(dave, carter, oliver));
}
}