use of org.springframework.data.domain.Sort.Order in project irida by phac-nml.
the class CRUDServiceImplTest method testSearch.
@Test
@SuppressWarnings("unchecked")
public void testSearch() {
int page = 1;
int size = 1;
Direction order = Direction.ASC;
Page<IdentifiableTestEntity> idPage = new PageImpl<>(Lists.newArrayList(new IdentifiableTestEntity(), new IdentifiableTestEntity()));
when(crudRepository.findAll(any(Specification.class), any(Pageable.class))).thenReturn(idPage);
Page<IdentifiableTestEntity> search = crudService.search(IdentifiableTestEntitySpecification.search(), page, size, order);
assertEquals(2, search.getTotalElements());
ArgumentCaptor<Pageable> pageArgument = ArgumentCaptor.forClass(Pageable.class);
verify(crudRepository).findAll(any(Specification.class), pageArgument.capture());
// ensure a created date sort property is set
Pageable pagable = pageArgument.getValue();
Order sort = pagable.getSort().iterator().next();
assertEquals("createdDate", sort.getProperty());
}
use of org.springframework.data.domain.Sort.Order in project irida by phac-nml.
the class CRUDServiceImplTest method testSearchSortEmptyString.
@Test
@SuppressWarnings("unchecked")
public void testSearchSortEmptyString() {
int page = 1;
int size = 1;
Direction order = Direction.ASC;
Page<IdentifiableTestEntity> idPage = new PageImpl<>(Lists.newArrayList(new IdentifiableTestEntity(), new IdentifiableTestEntity()));
when(crudRepository.findAll(any(Specification.class), any(Pageable.class))).thenReturn(idPage);
Page<IdentifiableTestEntity> search = crudService.search(IdentifiableTestEntitySpecification.search(), page, size, order, "");
assertEquals(2, search.getTotalElements());
ArgumentCaptor<Pageable> pageArgument = ArgumentCaptor.forClass(Pageable.class);
verify(crudRepository).findAll(any(Specification.class), pageArgument.capture());
// ensure a created date sort property is set
Pageable pagable = pageArgument.getValue();
Order sort = pagable.getSort().iterator().next();
assertEquals("createdDate", sort.getProperty());
}
use of org.springframework.data.domain.Sort.Order in project spring-data-keyvalue by spring-projects.
the class KeyValueQuerydslUtils method toOrderSpecifier.
/**
* Transforms a plain {@link Order} into a QueryDsl specific {@link OrderSpecifier}.
*
* @param sort must not be {@literal null}.
* @param builder must not be {@literal null}.
* @return empty {@code OrderSpecifier<?>[]} when sort is {@literal null}.
*/
static OrderSpecifier<?>[] toOrderSpecifier(Sort sort, PathBuilder<?> builder) {
Assert.notNull(sort, "Sort must not be null.");
Assert.notNull(builder, "Builder must not be null.");
List<OrderSpecifier<?>> specifiers = null;
if (sort instanceof QSort) {
specifiers = ((QSort) sort).getOrderSpecifiers();
} else {
specifiers = new ArrayList<>();
for (Order order : sort) {
specifiers.add(toOrderSpecifier(order, builder));
}
}
return specifiers.toArray(new OrderSpecifier<?>[specifiers.size()]);
}
use of org.springframework.data.domain.Sort.Order in project spring-data-commons by spring-projects.
the class QSortUnitTests method shouldSupportSortByOperatorExpressions.
// DATACMNS-566
@Test
public void shouldSupportSortByOperatorExpressions() {
QUser user = QUser.user;
QSort sort = new QSort(user.dateOfBirth.yearMonth().asc());
Sort result = sort.and(Sort.by(Direction.ASC, "lastname"));
assertThat(result).hasSize(2);
assertThat(result).contains(new Order(Direction.ASC, "lastname"), new Order(Direction.ASC, user.dateOfBirth.yearMonth().toString()));
}
use of org.springframework.data.domain.Sort.Order in project spring-data-commons by spring-projects.
the class QSortUnitTests method shouldCreateSortForDeepNestedPathCorrectly.
// DATACMNS-621
@Test
public void shouldCreateSortForDeepNestedPathCorrectly() {
QSort sort = new QSort(wrapperForUserWrapper.wrapper.user.firstname.asc());
assertThat(sort).contains(new Order(Direction.ASC, "wrapper.user.firstname"));
}
Aggregations