use of org.springframework.data.domain.Sort.Direction 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.Direction 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.Direction in project irida by phac-nml.
the class RemoteAPIControllerTest method testGetAjaxList.
@SuppressWarnings("unchecked")
@Test
public void testGetAjaxList() {
int page = 0;
int size = 10;
int draw = 1;
int sortColumn = 0;
String direction = "asc";
String searchValue = "";
Principal principal = () -> USER_NAME;
RemoteAPI api1 = new RemoteAPI("api name", "http://somewhere", "an api", "client1", "secret1");
api1.setId(1L);
RemoteAPI api2 = new RemoteAPI("api name 2", "http://nowhere", "another api", "client2", "secret2");
api2.setId(2L);
Page<RemoteAPI> apiPage = new PageImpl<>(Lists.newArrayList(api1, api2));
when(remoteAPIService.search(any(Specification.class), eq(page), eq(size), any(Direction.class), any(String.class))).thenReturn(apiPage);
Map<String, Object> ajaxAPIList = remoteAPIController.getAjaxAPIList(page, size, draw, sortColumn, direction, searchValue, principal, locale);
verify(remoteAPIService).search(any(Specification.class), eq(page), eq(size), any(Direction.class), any(String.class));
assertNotNull(ajaxAPIList);
assertFalse(ajaxAPIList.isEmpty());
List<List<String>> apiList = (List<List<String>>) ajaxAPIList.get(DataTable.RESPONSE_PARAM_DATA);
assertEquals(2, apiList.size());
}
use of org.springframework.data.domain.Sort.Direction in project irida by phac-nml.
the class ProjectSamplesControllerTest method testGetProjectsAvailableToCopySamplesAsUser.
@Test
public void testGetProjectsAvailableToCopySamplesAsUser() {
String term = "";
int page = 0;
int pagesize = 10;
Direction order = Direction.ASC;
final Project p = new Project();
User puser = new User(USER_NAME, null, null, null, null, null);
puser.setSystemRole(Role.ROLE_USER);
Page<Project> projects = new PageImpl<>(Lists.newArrayList(TestDataFactory.constructProject(), TestDataFactory.constructProject()));
when(projectService.read(1L)).thenReturn(p);
when(projectService.getUnassociatedProjects(p, term, page, pagesize, order, ProjectSamplesController.PROJECT_NAME_PROPERTY)).thenReturn(projects);
Map<String, Object> projectsAvailableToCopySamples = controller.getProjectsAvailableToCopySamples(1L, term, pagesize, page);
assertTrue(projectsAvailableToCopySamples.containsKey("total"));
assertEquals(2L, projectsAvailableToCopySamples.get("total"));
assertTrue(projectsAvailableToCopySamples.containsKey("projects"));
verify(projectService).getUnassociatedProjects(p, term, page, pagesize, order, ProjectSamplesController.PROJECT_NAME_PROPERTY);
}
use of org.springframework.data.domain.Sort.Direction in project spring-data-commons by spring-projects.
the class SortHandlerMethodArgumentResolver method legacyFoldExpressions.
/**
* Folds the given {@link Sort} instance into two expressions. The first being the property list, the second being the
* direction.
*
* @throws IllegalArgumentException if a {@link Sort} with multiple {@link Direction}s has been handed in.
* @param sort must not be {@literal null}.
* @return
*/
protected List<String> legacyFoldExpressions(Sort sort) {
List<String> expressions = new ArrayList<>();
ExpressionBuilder builder = null;
for (Order order : sort) {
Direction direction = order.getDirection();
if (builder == null) {
builder = new ExpressionBuilder(direction);
} else if (!builder.hasSameDirectionAs(order)) {
throw new IllegalArgumentException(String.format("%s in legacy configuration only supports a single direction to sort by!", getClass().getSimpleName()));
}
builder.add(order.getProperty());
}
return builder == null ? Collections.emptyList() : builder.dumpExpressionIfPresentInto(expressions);
}
Aggregations