Package org.springframework.data.domain

Examples of org.springframework.data.domain.Sort


  }

  @Test
  public void returnsSortFromPageableIfAvailable() throws Exception {

    Sort sort = new Sort("foo");
    Pageable pageable = new PageRequest(0, 10, sort);
    ParameterAccessor accessor = new ParametersParameterAccessor(pageableParameters, new Object[] { "test", pageable });
    assertThat(accessor.getPageable(), is(pageable));
    assertThat(accessor.getSort(), is(sort));
  }
View Full Code Here


  public void shouldSupportSortByOperatorExpressions() {

    QUser user = QUser.user;
    QSort sort = new QSort(user.dateOfBirth.yearMonth().asc());

    Sort result = sort.and(new Sort(Direction.ASC, "lastname"));
    assertThat(result, is(Matchers.<Order> iterableWithSize(2)));
    assertThat(result, hasItems(new Order(Direction.ASC, "lastname"), new Order(Direction.ASC, user.dateOfBirth.yearMonth().toString())));
  }
View Full Code Here

  public void invokesFindAllWithSortByDefault() throws Exception {

    Repository repository = mock(Repository.class);
    Method method = PagingAndSortingRepository.class.getMethod("findAll", Sort.class);

    getInvokerFor(repository, expectInvocationOf(method)).invokeFindAll(new Sort("foo"));
    getInvokerFor(repository, expectInvocationOf(method)).invokeFindAll((Sort) null);
  }
View Full Code Here

  public void invokesRedeclaredFindAllWithSort() throws Exception {

    RepositoryWithRedeclaredFindAllWithSort repository = mock(RepositoryWithRedeclaredFindAllWithSort.class);
    Method method = RepositoryWithRedeclaredFindAllWithSort.class.getMethod("findAll", Sort.class);

    getInvokerFor(repository, expectInvocationOf(method)).invokeFindAll(new Sort("foo"));
    getInvokerFor(repository, expectInvocationOf(method)).invokeFindAll((Sort) null);
  }
View Full Code Here

    ManualCrudRepository repository = mock(ManualCrudRepository.class);

    getInvokerFor(repository, expectInvocationOf(method)).invokeFindAll((Pageable) null);
    getInvokerFor(repository, expectInvocationOf(method)).invokeFindAll(new PageRequest(0, 10));
    getInvokerFor(repository, expectInvocationOf(method)).invokeFindAll((Sort) null);
    getInvokerFor(repository, expectInvocationOf(method)).invokeFindAll(new Sort("foo"));
  }
View Full Code Here

    RepoWithFindAllWithSort repository = mock(RepoWithFindAllWithSort.class);

    getInvokerFor(repository, expectInvocationOf(method)).invokeFindAll((Pageable) null);
    getInvokerFor(repository, expectInvocationOf(method)).invokeFindAll(new PageRequest(0, 10));
    getInvokerFor(repository, expectInvocationOf(method)).invokeFindAll((Sort) null);
    getInvokerFor(repository, expectInvocationOf(method)).invokeFindAll(new Sort("foo"));
  }
View Full Code Here

  @Test
  public void fallbackToGivenDefaultSort() throws Exception {

    MethodParameter parameter = TestUtils.getParameterOfMethod(getControllerClass(), "unsupportedMethod", String.class);
    SortHandlerMethodArgumentResolver resolver = new SortHandlerMethodArgumentResolver();
    Sort fallbackSort = new Sort(Direction.ASC, "ID");
    resolver.setFallbackSort(fallbackSort);

    Sort sort = resolver.resolveArgument(parameter, null, new ServletWebRequest(new MockHttpServletRequest()), null);
    assertThat(sort, is(fallbackSort));
  }
View Full Code Here

  public void fallbackToDefaultDefaultSort() throws Exception {

    MethodParameter parameter = TestUtils.getParameterOfMethod(getControllerClass(), "unsupportedMethod", String.class);
    SortHandlerMethodArgumentResolver resolver = new SortHandlerMethodArgumentResolver();

    Sort sort = resolver.resolveArgument(parameter, null, new ServletWebRequest(new MockHttpServletRequest()), null);
    assertThat(sort, is(nullValue()));
  }
View Full Code Here

  @Test
  public void discoversSimpleSortFromRequest() {

    MethodParameter parameter = getParameterOfMethod("simpleDefault");
    Sort reference = new Sort("bar", "foo");
    NativeWebRequest request = getRequestWithSort(reference);

    assertSupportedAndResolvedTo(request, parameter, reference);
  }
View Full Code Here

  @Test
  public void discoversComplexSortFromRequest() {

    MethodParameter parameter = getParameterOfMethod("simpleDefault");
    Sort reference = new Sort("bar", "foo").and(new Sort("fizz", "buzz"));

    assertSupportedAndResolvedTo(getRequestWithSort(reference), parameter, reference);
  }
View Full Code Here

TOP

Related Classes of org.springframework.data.domain.Sort

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.