Package org.springframework.data.domain

Examples of org.springframework.data.domain.PageRequest


    List<Product> baseList = createProductList(10);
    repo.save(baseList);

    Assert.assertEquals(baseList.size(), repo.count());

    Page<Product> popularProducts = repo.findByPopularity(20, new PageRequest(0, 10));
    Assert.assertEquals(1, popularProducts.getTotalElements());

    Assert.assertEquals("2", popularProducts.getContent().get(0).getId());
  }
View Full Code Here


    List<Product> baseList = createProductList(10);
    repo.save(baseList);

    Assert.assertEquals(baseList.size(), repo.count());

    Page<Product> unavailableProducts = repo.findByAvailableFalseUsingAnnotatedQuery(new PageRequest(0, 10));
    Assert.assertEquals(5, unavailableProducts.getTotalElements());
    for (Product product : unavailableProducts) {
      Assert.assertFalse(product.isAvailable());
    }
  }
View Full Code Here

  public void testCustomRepositoryImplementation() {
    Product initial = createProduct(1);
    repo.save(initial);
    Assert.assertEquals(1, repo.count());

    Page<Product> page = repo.findProductsByCustomImplementation(initial.getName(), new PageRequest(0, 10));

    Assert.assertEquals(1, page.getTotalElements());
  }
View Full Code Here

        assertEquals(20, personRepository.count());
    }

    @Test
    public void testFindByName() {
        Page<Person> p = personRepository.findByNameLike("%name1%", new PageRequest(
                0, 5));
        System.out.println(p.getContent());
        assertNotNull(p);
        assertEquals(5, p.getNumberOfElements());
        assertEquals(0, p.getNumber());
View Full Code Here

    protected PersonRepository personRepository;

    @Override
    @Transactional(readOnly = true)
    public Page<Person> findAll(int page, int size) {
        Pageable pageable = new PageRequest(page, size, new Sort(
                Direction.DESC, "id"));
        Page<Person> persons = personRepository.findAll(pageable);
        return persons;
    }
View Full Code Here

    }

    @Override
    @Transactional(readOnly = true)
    public Page<Person> findByNameLike(String name, int page, int size) {
        Pageable pageable = new PageRequest(page, size, new Sort(
                Direction.DESC, "id"));
        String q = "%" + name + "%";
        Page<Person> persons = personRepository.findByNameLike(q, pageable);
        return persons;
    }
View Full Code Here

  public void adjustedWellKnownPagedFindAllMethodShouldReturnOnlyTheUserWithFirstnameOliver() {

    ollie = repository.save(ollie);
    tom = repository.save(tom);

    Page<User> page = repository.findAll(new PageRequest(0, 2));

    assertThat(page.getNumberOfElements(), is(1));
    assertThat(page.getContent().get(0).getFirstname(), is("Oliver"));
  }
View Full Code Here

  public void executesCombinedSpecificationsWithPageableCorrectly() {

    flushTestUsers();
    Specification<User> spec = where(userHasFirstname("Oliver")).or(userHasLastname("Arrasz"));

    Page<User> users = repository.findAll(spec, new PageRequest(0, 1));
    assertThat(users.getSize(), is(1));
    assertThat(users.hasPrevious(), is(false));
    assertThat(users.getTotalElements(), is(2L));
  }
View Full Code Here

  }

  @Test
  public void returnsSamePageIfNoSpecGiven() throws Exception {

    Pageable pageable = new PageRequest(0, 1);

    flushTestUsers();
    assertThat(repository.findAll(null, pageable), is(repository.findAll(pageable)));
  }
View Full Code Here

  @Test
  public void readsPageWithGroupByClauseCorrectly() {

    flushTestUsers();

    Page<String> result = repository.findByLastnameGrouped(new PageRequest(0, 10));
    assertThat(result.getTotalPages(), is(1));
  }
View Full Code Here

TOP

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

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.