Search in sources :

Example 1 with PaginationWrapper

use of org.zalando.nakadi.domain.PaginationWrapper in project nakadi by zalando.

the class SubscriptionControllerTest method whenListSubscriptionsWithQueryParamsThenOk.

@Test
public void whenListSubscriptionsWithQueryParamsThenOk() 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(ImmutableSet.of("et1", "et2"), "app", 0, 30).andExpect(status().isOk()).andExpect(content().string(TestUtils.JSON_TEST_HELPER.matchesObject(subscriptionList)));
    verify(subscriptionRepository, times(1)).listSubscriptions(ImmutableSet.of("et1", "et2"), Optional.of("app"), 0, 30);
}
Also used : PaginationLinks(org.zalando.nakadi.domain.PaginationLinks) Subscription(org.zalando.nakadi.domain.Subscription) PaginationWrapper(org.zalando.nakadi.domain.PaginationWrapper) Test(org.junit.Test)

Example 2 with PaginationWrapper

use of org.zalando.nakadi.domain.PaginationWrapper in project nakadi by zalando.

the class SubscriptionControllerTest method whenListSubscriptionsThenPaginationIsOk.

@Test
public void whenListSubscriptionsThenPaginationIsOk() throws Exception {
    final List<Subscription> subscriptions = createRandomSubscriptions(10);
    when(subscriptionRepository.listSubscriptions(any(), any(), anyInt(), anyInt())).thenReturn(subscriptions);
    final PaginationLinks.Link prevLink = new PaginationLinks.Link("/subscriptions?event_type=et1&event_type=et2&owning_application=app&offset=0&limit=10");
    final PaginationLinks.Link nextLink = new PaginationLinks.Link("/subscriptions?event_type=et1&event_type=et2&owning_application=app&offset=15&limit=10");
    final PaginationLinks links = new PaginationLinks(Optional.of(prevLink), Optional.of(nextLink));
    final PaginationWrapper expectedResult = new PaginationWrapper(subscriptions, links);
    getSubscriptions(ImmutableSet.of("et1", "et2"), "app", 5, 10).andExpect(status().isOk()).andExpect(content().string(TestUtils.JSON_TEST_HELPER.matchesObject(expectedResult)));
}
Also used : PaginationLinks(org.zalando.nakadi.domain.PaginationLinks) Subscription(org.zalando.nakadi.domain.Subscription) PaginationWrapper(org.zalando.nakadi.domain.PaginationWrapper) Test(org.junit.Test)

Example 3 with PaginationWrapper

use of org.zalando.nakadi.domain.PaginationWrapper in project nakadi by zalando.

the class PaginationServiceTest method testPaginationPrev.

@Test
public void testPaginationPrev() {
    final PaginationService paginationService = new PaginationService();
    final PaginationWrapper paginationWrapper = paginationService.paginate(2, 5, "/schemas", (o, l) -> Collections.emptyList(), () -> 1);
    Assert.assertFalse(paginationWrapper.getLinks().getNext().isPresent());
    Assert.assertFalse(paginationWrapper.getLinks().getPrev().isPresent());
}
Also used : PaginationWrapper(org.zalando.nakadi.domain.PaginationWrapper) Test(org.junit.Test)

Example 4 with PaginationWrapper

use of org.zalando.nakadi.domain.PaginationWrapper in project nakadi by zalando.

the class PaginationServiceTest method testPaginationPrev3.

@Test
public void testPaginationPrev3() {
    final PaginationService paginationService = new PaginationService();
    final PaginationWrapper paginationWrapper = paginationService.paginate(2, 5, "/schemas", (o, l) -> Collections.emptyList(), () -> 2);
    Assert.assertFalse(paginationWrapper.getLinks().getNext().isPresent());
    Assert.assertFalse(paginationWrapper.getLinks().getPrev().isPresent());
}
Also used : PaginationWrapper(org.zalando.nakadi.domain.PaginationWrapper) Test(org.junit.Test)

Example 5 with PaginationWrapper

use of org.zalando.nakadi.domain.PaginationWrapper in project nakadi by zalando.

the class PaginationServiceTest method testPaginationNext.

@Test
public void testPaginationNext() {
    final PaginationService paginationService = new PaginationService();
    final PaginationWrapper paginationWrapper = paginationService.paginate(0, 3, "/schemas", (o, l) -> Lists.newArrayList("One", "Two", "Three", "Four"), () -> 1);
    Assert.assertEquals("/schemas?offset=3&limit=3", paginationWrapper.getLinks().getNext().get().getHref());
    Assert.assertFalse(paginationWrapper.getLinks().getPrev().isPresent());
}
Also used : PaginationWrapper(org.zalando.nakadi.domain.PaginationWrapper) Test(org.junit.Test)

Aggregations

PaginationWrapper (org.zalando.nakadi.domain.PaginationWrapper)12 Test (org.junit.Test)11 PaginationLinks (org.zalando.nakadi.domain.PaginationLinks)5 Subscription (org.zalando.nakadi.domain.Subscription)4 List (java.util.List)1 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)1 NakadiTestUtils.createSubscription (org.zalando.nakadi.webservice.utils.NakadiTestUtils.createSubscription)1