use of org.zalando.nakadi.domain.PaginationWrapper in project nakadi by zalando.
the class PaginationService method paginate.
public PaginationWrapper paginate(final int offset, final int limit, final String path, final ItemsSupplier itemsSupplier, final Supplier<Integer> countSupplier) {
final List items = itemsSupplier.queryOneMore(offset, limit);
final PaginationLinks paginationLinks;
if (items.isEmpty() && offset != 0 && limit != 0) {
final int count = countSupplier.get();
int latestOffset = count / limit;
if (offset >= latestOffset) {
latestOffset = 0;
}
paginationLinks = createLinks(path, latestOffset, limit, items.size());
} else {
paginationLinks = createLinks(path, offset, limit, items.size());
if (items.size() > limit) {
items.remove(items.size() - 1);
}
}
return new PaginationWrapper(items, paginationLinks);
}
use of org.zalando.nakadi.domain.PaginationWrapper in project nakadi by zalando.
the class SubscriptionControllerTest method whenListSubscriptionsWithoutQueryParamsThenOk.
@Test
public void whenListSubscriptionsWithoutQueryParamsThenOk() throws Exception {
final List<Subscription> subscriptions = createRandomSubscriptions(10);
when(subscriptionRepository.listSubscriptions(any(), any(), anyInt(), anyInt())).thenReturn(subscriptions);
final PaginationWrapper subscriptionList = new PaginationWrapper(subscriptions, new PaginationLinks());
getSubscriptions().andExpect(status().isOk()).andExpect(content().string(TestUtils.JSON_TEST_HELPER.matchesObject(subscriptionList)));
verify(subscriptionRepository, times(1)).listSubscriptions(ImmutableSet.of(), Optional.empty(), 0, 20);
}
use of org.zalando.nakadi.domain.PaginationWrapper in project nakadi by zalando.
the class PaginationServiceTest method testPaginationEmpty.
@Test
public void testPaginationEmpty() {
final PaginationService paginationService = new PaginationService();
final PaginationWrapper paginationWrapper = paginationService.paginate(0, 5, "/schemas", (o, l) -> Collections.emptyList(), () -> 5);
Assert.assertFalse(paginationWrapper.getLinks().getNext().isPresent());
Assert.assertFalse(paginationWrapper.getLinks().getPrev().isPresent());
}
use of org.zalando.nakadi.domain.PaginationWrapper in project nakadi by zalando.
the class PaginationServiceTest method testPaginationPrev2.
@Test
public void testPaginationPrev2() {
final PaginationService paginationService = new PaginationService();
final PaginationWrapper paginationWrapper = paginationService.paginate(2, 5, "/schemas", (o, l) -> Collections.emptyList(), () -> 20);
Assert.assertFalse(paginationWrapper.getLinks().getNext().isPresent());
Assert.assertEquals("/schemas?offset=0&limit=5", paginationWrapper.getLinks().getPrev().get().getHref());
}
use of org.zalando.nakadi.domain.PaginationWrapper in project nakadi by zalando.
the class PaginationServiceTest method testPaginationPrev4.
@Test
public void testPaginationPrev4() {
final PaginationService paginationService = new PaginationService();
final PaginationWrapper paginationWrapper = paginationService.paginate(2, 5, "/schemas", (o, l) -> Collections.emptyList(), () -> 5);
Assert.assertFalse(paginationWrapper.getLinks().getNext().isPresent());
Assert.assertFalse(paginationWrapper.getLinks().getPrev().isPresent());
}
Aggregations