@Test public void testBefore() throws Exception { Method method = getClass().getMethod("simpleHandler", Chunkable.class); MethodParameter methodParametere = new MethodParameter(method, 0); ModelAndViewContainer mavContainer = mock(ModelAndViewContainer.class); NativeWebRequest webRequest = mock(NativeWebRequest.class); when(webRequest.getParameter(eq("prev"))).thenReturn("89"); WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class); Object actual = sut.resolveArgument(methodParametere, mavContainer, webRequest, binderFactory); assertThat(actual, is(notNullValue())); assertThat(actual, is(instanceOf(Chunkable.class))); Chunkable actualChunkable = (Chunkable) actual; assertThat(actualChunkable.getPaginationRelation(), is(PaginationRelation.PREV)); assertThat(actualChunkable.getPaginationToken(), is(notNullValue())); assertThat(actualChunkable.getMaxPageSize(), is(2000)); assertThat(actualChunkable.getDirection(), is(nullValue())); }
@Override public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { SpringDataChunkableAnnotationUtils.assertChunkableUniqueness(methodParameter); String next = webRequest.getParameter(getParameterNameToUse(nextParameterName, methodParameter)); String prev = webRequest.getParameter(getParameterNameToUse(prevParameterName, methodParameter)); String pageSizeString = webRequest.getParameter(getParameterNameToUse(sizeParameterName, methodParameter)); String directionString = webRequest.getParameter(getParameterNameToUse(directionParameterName, methodParameter)); Chunkable defaultOrFallback = getDefaultFromAnnotationOrFallback(methodParameter); if (StringUtils.hasText(next) == false && StringUtils.hasText(prev) == false && StringUtils.hasText(pageSizeString) == false && StringUtils.hasText(directionString) == false) { return defaultOrFallback; } Integer pageSize = defaultOrFallback.getMaxPageSize() != null ? defaultOrFallback.getMaxPageSize() : maxPageSize; if (StringUtils.hasText(pageSizeString)) { try { pageSize = Integer.parseInt(pageSizeString); } catch (NumberFormatException e) { log.trace("invalid page size: {}", pageSizeString); } } pageSize = pageSize < 1 ? 1 : pageSize; pageSize = pageSize > maxPageSize ? maxPageSize : pageSize; Direction direction = Direction.fromOptionalString(directionString).orElse(null); if (StringUtils.hasText(next)) { return new ChunkRequest(next, PaginationRelation.NEXT, pageSize, direction); } else if (StringUtils.hasText(prev)) { return new ChunkRequest(prev, PaginationRelation.PREV, pageSize, direction); } else { return new ChunkRequest(pageSize, direction); } }
ChunkableHandlerMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { SpringDataChunkableAnnotationUtils.assertChunkableUniqueness(methodParameter); String next = webRequest.getParameter(getParameterNameToUse(nextParameterName, methodParameter)); String prev = webRequest.getParameter(getParameterNameToUse(prevParameterName, methodParameter)); String pageSizeString = webRequest.getParameter(getParameterNameToUse(sizeParameterName, methodParameter)); String directionString = webRequest.getParameter(getParameterNameToUse(directionParameterName, methodParameter)); Chunkable defaultOrFallback = getDefaultFromAnnotationOrFallback(methodParameter); if (StringUtils.hasText(next) == false && StringUtils.hasText(prev) == false && StringUtils.hasText(pageSizeString) == false && StringUtils.hasText(directionString) == false) { return defaultOrFallback; } Integer pageSize = defaultOrFallback.getMaxPageSize() != null ? defaultOrFallback.getMaxPageSize() : maxPageSize; if (StringUtils.hasText(pageSizeString)) { try { pageSize = Integer.parseInt(pageSizeString); } catch (NumberFormatException e) { log.trace("invalid page size: {}", pageSizeString); } } pageSize = pageSize < 1 ? 1 : pageSize; pageSize = pageSize > maxPageSize ? maxPageSize : pageSize; Direction direction = Direction.fromOptionalString(directionString).orElse(null); if (StringUtils.hasText(next)) { return new ChunkRequest(next, PaginationRelation.NEXT, pageSize, direction); } else if (StringUtils.hasText(prev)) { return new ChunkRequest(prev, PaginationRelation.PREV, pageSize, direction); } else { return new ChunkRequest(pageSize, direction); } } }
ChunkableHandlerMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { SpringDataChunkableAnnotationUtils.assertChunkableUniqueness(methodParameter); String next = webRequest.getParameter(getParameterNameToUse(nextParameterName, methodParameter)); String prev = webRequest.getParameter(getParameterNameToUse(prevParameterName, methodParameter)); String pageSizeString = webRequest.getParameter(getParameterNameToUse(sizeParameterName, methodParameter)); String directionString = webRequest.getParameter(getParameterNameToUse(directionParameterName, methodParameter)); Chunkable defaultOrFallback = getDefaultFromAnnotationOrFallback(methodParameter); if (StringUtils.hasText(next) == false && StringUtils.hasText(prev) == false && StringUtils.hasText(pageSizeString) == false && StringUtils.hasText(directionString) == false) { return defaultOrFallback; } Integer pageSize = defaultOrFallback.getMaxPageSize() != null ? defaultOrFallback.getMaxPageSize() : maxPageSize; if (StringUtils.hasText(pageSizeString)) { try { pageSize = Integer.parseInt(pageSizeString); } catch (NumberFormatException e) { log.trace("invalid page size: {}", pageSizeString); } } pageSize = pageSize < 1 ? 1 : pageSize; pageSize = pageSize > maxPageSize ? maxPageSize : pageSize; Direction direction = Direction.fromOptionalString(directionString).orElse(null); if (StringUtils.hasText(next)) { return new ChunkRequest(next, PaginationRelation.NEXT, pageSize, direction); } else if (StringUtils.hasText(prev)) { return new ChunkRequest(prev, PaginationRelation.PREV, pageSize, direction); } else { return new ChunkRequest(pageSize, direction); } }  }
ChunkableHandlerMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { SpringDataChunkableAnnotationUtils.assertChunkableUniqueness(methodParameter); String next = webRequest.getParameter(getParameterNameToUse(nextParameterName, methodParameter)); String prev = webRequest.getParameter(getParameterNameToUse(prevParameterName, methodParameter)); String pageSizeString = webRequest.getParameter(getParameterNameToUse(sizeParameterName, methodParameter)); String directionString = webRequest.getParameter(getParameterNameToUse(directionParameterName, methodParameter)); Chunkable defaultOrFallback = getDefaultFromAnnotationOrFallback(methodParameter); if (StringUtils.hasText(next) == false && StringUtils.hasText(prev) == false && StringUtils.hasText(pageSizeString) == false && StringUtils.hasText(directionString) == false) { return defaultOrFallback; } Integer pageSize = defaultOrFallback.getMaxPageSize() != null ? defaultOrFallback.getMaxPageSize() : maxPageSize; if (StringUtils.hasText(pageSizeString)) { try { pageSize = Integer.parseInt(pageSizeString); } catch (NumberFormatException e) { log.trace("invalid page size: {}", pageSizeString); } } pageSize = pageSize < 1 ? 1 : pageSize; pageSize = pageSize > maxPageSize ? maxPageSize : pageSize; Direction direction = Direction.fromOptionalString(directionString).orElse(null); if (StringUtils.hasText(next)) { return new ChunkRequest(next, PaginationRelation.NEXT, pageSize, direction); } else if (StringUtils.hasText(prev)) { return new ChunkRequest(prev, PaginationRelation.PREV, pageSize, direction); } else { return new ChunkRequest(pageSize, direction); } }  boolean isFallbackChunkable(Chunkable chunkable); void setPrefix(String prefix); @Override boolean supportsParameter(MethodParameter parameter); @Override Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer mavContainer, // NOPMD - cc
			NativeWebRequest webRequest, WebDataBinderFactory binderFactory); }
ChunkableHandlerMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { SpringDataChunkableAnnotationUtils.assertChunkableUniqueness(methodParameter); String next = webRequest.getParameter(getParameterNameToUse(nextParameterName, methodParameter)); String prev = webRequest.getParameter(getParameterNameToUse(prevParameterName, methodParameter)); String pageSizeString = webRequest.getParameter(getParameterNameToUse(sizeParameterName, methodParameter)); String directionString = webRequest.getParameter(getParameterNameToUse(directionParameterName, methodParameter)); Chunkable defaultOrFallback = getDefaultFromAnnotationOrFallback(methodParameter); if (StringUtils.hasText(next) == false && StringUtils.hasText(prev) == false && StringUtils.hasText(pageSizeString) == false && StringUtils.hasText(directionString) == false) { return defaultOrFallback; } Integer pageSize = defaultOrFallback.getMaxPageSize() != null ? defaultOrFallback.getMaxPageSize() : maxPageSize; if (StringUtils.hasText(pageSizeString)) { try { pageSize = Integer.parseInt(pageSizeString); } catch (NumberFormatException e) { log.trace("invalid page size: {}", pageSizeString); } } pageSize = pageSize < 1 ? 1 : pageSize; pageSize = pageSize > maxPageSize ? maxPageSize : pageSize; Direction direction = Direction.fromOptionalString(directionString).orElse(null); if (StringUtils.hasText(next)) { return new ChunkRequest(next, PaginationRelation.NEXT, pageSize, direction); } else if (StringUtils.hasText(prev)) { return new ChunkRequest(prev, PaginationRelation.PREV, pageSize, direction); } else { return new ChunkRequest(pageSize, direction); } }  boolean isFallbackChunkable(Chunkable chunkable); void setPrefix(String prefix); @Override boolean supportsParameter(MethodParameter parameter); @Override Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer mavContainer, // NOPMD - cc
			NativeWebRequest webRequest, WebDataBinderFactory binderFactory);  }