Search in sources :

Example 1 with QuerySortOrder

use of com.vaadin.flow.data.provider.QuerySortOrder in project flow by vaadin.

the class VaadinSpringDataHelpersTest method toSpringDataSort_generatesAscendingAndDescendingSpringSort.

@Test
public void toSpringDataSort_generatesAscendingAndDescendingSpringSort() {
    List<QuerySortOrder> querySortOrders = QuerySortOrder.asc("name").thenDesc("age").build();
    Query<?, ?> query = new Query<>(0, 1, querySortOrders, null, null);
    Sort sort = VaadinSpringDataHelpers.toSpringDataSort(query);
    Assert.assertNotNull(sort);
    Assert.assertEquals(2L, sort.stream().count());
    Sort.Order nameOrder = sort.getOrderFor("name");
    Assert.assertNotNull(nameOrder);
    Assert.assertTrue(nameOrder.isAscending());
    Sort.Order ageOrder = sort.getOrderFor("age");
    Assert.assertNotNull(ageOrder);
    Assert.assertTrue(ageOrder.isDescending());
}
Also used : QuerySortOrder(com.vaadin.flow.data.provider.QuerySortOrder) Query(com.vaadin.flow.data.provider.Query) Sort(org.springframework.data.domain.Sort) Test(org.junit.Test)

Example 2 with QuerySortOrder

use of com.vaadin.flow.data.provider.QuerySortOrder in project flow by vaadin.

the class VaadinSpringDataHelpersTest method toSpringPageRequest_generatesSpringPageRequestWithPagingAndSort.

@Test
public void toSpringPageRequest_generatesSpringPageRequestWithPagingAndSort() {
    List<QuerySortOrder> querySortOrders = QuerySortOrder.asc("name").build();
    Query<?, ?> query = new Query<>(100, 50, querySortOrders, null, null);
    PageRequest pageRequest = VaadinSpringDataHelpers.toSpringPageRequest(query);
    Assert.assertNotNull(pageRequest);
    Assert.assertEquals(50, pageRequest.getPageSize());
    Assert.assertEquals(2, pageRequest.getPageNumber());
    Sort.Order order = pageRequest.getSort().getOrderFor("name");
    Assert.assertNotNull(order);
    Assert.assertTrue(order.isAscending());
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) QuerySortOrder(com.vaadin.flow.data.provider.QuerySortOrder) Query(com.vaadin.flow.data.provider.Query) Sort(org.springframework.data.domain.Sort) Test(org.junit.Test)

Aggregations

Query (com.vaadin.flow.data.provider.Query)2 QuerySortOrder (com.vaadin.flow.data.provider.QuerySortOrder)2 Test (org.junit.Test)2 Sort (org.springframework.data.domain.Sort)2 PageRequest (org.springframework.data.domain.PageRequest)1