use of com.liferay.apio.architect.pagination.Pagination in project com-liferay-apio-architect by liferay.
the class PaginationProviderTest method testPaginationProviderReturnDefaultValuesIfLessThanOne.
@Test
public void testPaginationProviderReturnDefaultValuesIfLessThanOne() {
PaginationProvider paginationProvider = new PaginationProvider();
HttpServletRequest httpServletRequest = Mockito.mock(HttpServletRequest.class);
Mockito.when(httpServletRequest.getParameter("per_page")).thenReturn("-4");
Mockito.when(httpServletRequest.getParameter("page")).thenReturn("0");
Pagination pagination = paginationProvider.createContext(httpServletRequest);
assertThat(pagination.getPageNumber(), is(1));
assertThat(pagination.getItemsPerPage(), is(30));
}
use of com.liferay.apio.architect.pagination.Pagination in project com-liferay-apio-architect by liferay.
the class PaginationProviderTest method testPaginationProviderReturnDefaultValuesIfError.
@Test
public void testPaginationProviderReturnDefaultValuesIfError() {
PaginationProvider paginationProvider = new PaginationProvider();
HttpServletRequest httpServletRequest = Mockito.mock(HttpServletRequest.class);
Mockito.when(httpServletRequest.getParameter("per_page")).thenReturn("Apio");
Pagination pagination = paginationProvider.createContext(httpServletRequest);
assertThat(pagination.getPageNumber(), is(1));
assertThat(pagination.getItemsPerPage(), is(30));
}
use of com.liferay.apio.architect.pagination.Pagination in project com-liferay-apio-architect by liferay.
the class URLCreatorTest method testCreateCollectionPageURL.
@Test
public void testCreateCollectionPageURL() {
Pagination pagination = Mockito.mock(Pagination.class);
Mockito.when(pagination.getItemsPerPage()).thenReturn(30);
Mockito.when(pagination.getPageNumber()).thenReturn(1);
PageItems<String> pageItems = new PageItems<>(emptyList(), 0);
Page page = new Page<>("", pageItems, pagination, null);
String firstPageURL = URLCreator.createCollectionPageURL("www.liferay.com", page, PageType.FIRST);
assertThat(firstPageURL, is("www.liferay.com?page=1&per_page=30"));
}
use of com.liferay.apio.architect.pagination.Pagination in project com-liferay-apio-architect by liferay.
the class PaginationProviderTest method testPaginationProviderReturnsPaginationIfParams.
@Test
public void testPaginationProviderReturnsPaginationIfParams() {
PaginationProvider paginationProvider = new PaginationProvider();
HttpServletRequest httpServletRequest = Mockito.mock(HttpServletRequest.class);
Mockito.when(httpServletRequest.getParameter("per_page")).thenReturn("42");
Mockito.when(httpServletRequest.getParameter("page")).thenReturn("6");
Pagination pagination = paginationProvider.createContext(httpServletRequest);
assertThat(pagination.getPageNumber(), is(6));
assertThat(pagination.getItemsPerPage(), is(42));
}
use of com.liferay.apio.architect.pagination.Pagination in project com-liferay-apio-architect by liferay.
the class MockPageWriter method write.
/**
* Writes a Collection of {@link RootModel}, with the hierarchy of embedded
* models and multiple fields.
*
* @param httpHeaders the request's {@code HttpHeaders}
* @param pageMessageMapper the {@link PageMessageMapper} to use for writing
* the JSON object
*/
public static JsonObject write(HttpHeaders httpHeaders, PageMessageMapper<RootModel> pageMessageMapper) {
RequestInfo requestInfo = getRequestInfo(httpHeaders);
Collection<RootModel> items = Arrays.asList(() -> "1", () -> "2", () -> "3");
PageItems<RootModel> pageItems = new PageItems<>(items, 9);
Pagination pagination = new Pagination(3, 2);
Path path = new Path("name", "id");
List<Operation> operations = Collections.singletonList(new Operation(createForm("c", "p"), POST, "create-operation"));
Page<RootModel> page = new Page<>("root", pageItems, pagination, path, operations);
PageWriter<RootModel> pageWriter = PageWriter.create(builder -> builder.page(page).pageMessageMapper(pageMessageMapper).pathFunction(MockWriterUtil::identifierToPath).resourceNameFunction(__ -> Optional.of("models")).representorFunction(MockWriterUtil::getRepresentorOptional).requestInfo(requestInfo).singleModelFunction(MockWriterUtil::getSingleModel).build());
return new Gson().fromJson(pageWriter.write(), JsonObject.class);
}
Aggregations