use of org.springframework.data.domain.Sort.Direction in project irida by phac-nml.
the class CRUDServiceImplTest method testSearchSortSetProperty.
@Test
@SuppressWarnings("unchecked")
public void testSearchSortSetProperty() {
int page = 1;
int size = 1;
String property = "nonNull";
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, property);
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(property, sort.getProperty());
}
use of org.springframework.data.domain.Sort.Direction in project irida by phac-nml.
the class CRUDServiceImplTest method testSearchSortEmptyArray.
@Test
@SuppressWarnings("unchecked")
public void testSearchSortEmptyArray() {
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, new String[0]);
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.Direction in project irida by phac-nml.
the class UserServiceImplTest method testSearchUser.
@SuppressWarnings("unchecked")
@Test
public void testSearchUser() {
int page = 1;
int size = 10;
Direction order = Direction.ASC;
String sortProperties = "id";
String searchString = "tom";
Page<User> userPage = new PageImpl<>(Lists.newArrayList(new User(1L, "tom", "tom@nowhere.com", "123456798", "Tom", "Matthews", "1234"), new User(2L, "tomorrow", "tomorrow@somewhere.com", "ABCDEFGHIJ", "Tommorrow", "Sillyname", "5678")));
when(userRepository.findAll(any(Specification.class), any(PageRequest.class))).thenReturn(userPage);
Page<User> searchUser = userService.search(UserSpecification.searchUser(searchString), page, size, order, sortProperties);
assertEquals(userPage, searchUser);
verify(userRepository).findAll(any(Specification.class), any(PageRequest.class));
}
Aggregations