List of usage examples for org.springframework.data.domain Page getContent
List<T> getContent();
From source file:com.olp.jpa.domain.docu.ut.DepartmentServiceTest.java
public void test_simpleSearch4() { //PageRequestBean request = new PageRequestBean(); //request.setPageNum(2); //request.setPageSize(3); PageRequest request = new PageRequest(1, 3); Page<DepartmentBean> response = __service.findText("trla", true, request); assertNotNull("Matching page search should not be null", response); assertNotNull("Matching page content should not be null", response.getContent()); assertTrue("Atleast 1 result", response.getContent().size() >= 1); assertTrue("Max 3 results", response.getContent().size() == 3); }
From source file:cn.guoyukun.spring.jpa.plugin.serivce.BaseMovableService.java
public void doReweight(Page<M> page) { int totalElements = (int) page.getTotalElements(); List<M> moves = page.getContent(); int firstElement = page.getNumber() * page.getSize(); for (int i = 0; i < moves.size(); i++) { M move = moves.get(i);/*from www .j a v a2 s . c om*/ move.setWeight((totalElements - firstElement - i) * stepLength); update(move); } }
From source file:com.github.markserrano.jsonquery.jpa.service.OrderServiceTest.java
@Test public void testReadAndCount_OrderByDateTime_ASC() { String filter = "{\"groupOp\":\"AND\",\"rules\":" + "[{\"field\":\"parent.store\",\"op\":\"ne\",\"data\":\"StoreB\"}," + "{\"field\":\"birthDate\",\"op\":\"gt\",\"data\":\"1995-10-01T00:00:00.000Z\"}]" + "}"; BooleanBuilder builder = jsonBooleanBuilder.build(new JsonFilter(filter)); orderSpecifier = order.by("id", OrderEnum.ASC); Page<Child> results = service.readAndCount(builder, new PageRequest(0, 3), Child.class, orderSpecifier); Assert.assertNotNull(results);/* w w w . java2 s. c o m*/ Assert.assertEquals(3, results.getTotalElements()); Assert.assertEquals(fmt.parseDateTime("1995-10-05"), results.getContent().get(0).getBirthDate()); Assert.assertEquals(fmt.parseDateTime("2003-10-12"), results.getContent().get(1).getBirthDate()); Assert.assertEquals(fmt.parseDateTime("1996-01-01"), results.getContent().get(2).getBirthDate()); }
From source file:com.github.markserrano.jsonquery.jpa.service.OrderServiceTest.java
@Test public void testReadAndCount_OrderByDateTime_DESC() { String filter = "{\"groupOp\":\"AND\",\"rules\":" + "[{\"field\":\"parent.store\",\"op\":\"ne\",\"data\":\"StoreB\"}," + "{\"field\":\"birthDate\",\"op\":\"gt\",\"data\":\"1995-10-01T00:00:00.000Z\"}]" + "}"; BooleanBuilder builder = jsonBooleanBuilder.build(new JsonFilter(filter)); orderSpecifier = order.by("id", OrderEnum.DESC); Page<Child> results = service.readAndCount(builder, new PageRequest(0, 3), Child.class, orderSpecifier); Assert.assertNotNull(results);//from w ww. ja v a 2 s. c om Assert.assertEquals(3, results.getTotalElements()); Assert.assertEquals(fmt.parseDateTime("1996-01-01"), results.getContent().get(0).getBirthDate()); Assert.assertEquals(fmt.parseDateTime("2003-10-12"), results.getContent().get(1).getBirthDate()); Assert.assertEquals(fmt.parseDateTime("1995-10-05"), results.getContent().get(2).getBirthDate()); }
From source file:org.ngrinder.perftest.service.PerfTestServiceTest.java
@Test public void testGetTestListAll() { createPerfTest("new Test1", Status.TESTING, new Date()); createPerfTest("new Test2", Status.FINISHED, new Date()); PerfTest candidate = testService.getNextRunnablePerfTestPerfTestCandidate(); assertThat(candidate, nullValue());/*from w w w . j a v a 2 s. c om*/ Pageable pageable = new PageRequest(0, 10); Page<PerfTest> testList = testService.getPagedAll(getTestUser(), null, null, null, pageable); assertThat(testList.getContent().size(), is(2)); testList = testService.getPagedAll(getTestUser(), null, null, "F", pageable); assertThat(testList.getContent().size(), is(1)); // test with no paging testList = testService.getPagedAll(getTestUser(), null, null, null, null); assertThat(testList.getContent().size(), is(2)); testList = testService.getPagedAll(getTestUser(), null, null, "F", null); assertThat(testList.getContent().size(), is(1)); List<PerfTest> list = testService.getAllTesting(); assertThat(list.size(), is(1)); for (PerfTest test : list) { long systemTimeMills = System.currentTimeMillis(); test.setStartTime(new Date(systemTimeMills)); PerfTest testTemp = testService.getOne(getTestUser(), test.getId()); assertThat(testTemp.getId(), is(test.getId())); assertThat(testTemp.getStartTime().getTime(), is(systemTimeMills)); testService.markAbnormalTermination(testTemp, StopReason.CANCEL_BY_USER); testService.markProgress(testTemp, "this test will be TESTING again"); testService.markStatusAndProgress(testTemp, Status.TESTING, "this is just test unit"); List<PerfTest> testingList = testService.getAll(getTestUser(), new Status[] { Status.TESTING }); assertThat(testingList.size(), is(1)); Long testCount = testService.count(getTestUser(), new Status[] { Status.TESTING }); assertThat(testCount, is(1L)); GrinderProperties properties = testService.getGrinderProperties(test); assertThat(properties, not(nullValue())); } createPerfTest("new Test2", Status.getProcessingOrTestingTestStatus()[0], new Date()); list = testService.getCurrentlyRunningTest(); assertThat(list.size(), is(2)); PerfTest finishedTest = createPerfTest("new Test3", Status.ABNORMAL_TESTING, new Date()); finishedTest.setPort(0); // need port number for finishing list = testService.getAllAbnormalTesting(); assertThat(list.size(), is(1)); testService.updatePerfTestAfterTestFinish(finishedTest); createPerfTest("new Test3", Status.START_AGENTS, new Date()); List<PerfTest> errorList = testService.getAll(getTestUser(), new Status[] { Status.START_AGENTS }); assertThat(errorList.size(), is(1)); testService.markAbnormalTermination(errorList.get(0), "this is error test"); }
From source file:it.f2informatica.core.gateway.mongodb.ConsultantRepositoryGatewayMongoDB.java
@Override public Page<ConsultantModel> paginateConsultants(final ConsultantSearchCriteria searchCriteria, Pageable pageable) {//from w w w . j av a 2s .com MongoQueryPredicate<Consultant> queryPredicate = new MongoQueryPredicate<Consultant>(Consultant.class) { @Override public Query queryPredicate() { final Query query = new Query(); if (StringUtils.hasText(searchCriteria.getName())) { query.addCriteria(where("firstName").regex(searchCriteria.getName(), "i")); } if (StringUtils.hasText(searchCriteria.getLastName())) { query.addCriteria(where("lastName").regex(searchCriteria.getLastName(), "i")); } if (StringUtils.hasText(searchCriteria.getSkills())) { query.addCriteria(where("skills").in(searchCriteria.getSkills().split(","))); } return query; } }; Page<Consultant> consultantPage = consultantRepository.findAll(queryPredicate, pageable); return new PageImpl<>(consultantToModelConverter.convertList(consultantPage.getContent()), pageable, consultantPage.getTotalElements()); }
From source file:ymanv.forex.web.RateControllerTest.java
@DirtiesContext @Sql("/sql/insert_data.sql") @Test//from w ww .j a v a 2 s. co m public void testFindLatestByCriteria() throws Exception { // when Page<LatestRate> result = controller.findLatestByCriteria(USD, EUR, null, null, null, null); // then assertThat(result.getTotalElements()).isEqualTo(1); assertThat(result.getNumberOfElements()).isEqualTo(1); RateEntity r = result.getContent().get(0); assertThat(r.getFromcur()).isEqualTo(USD); assertThat(r.getTocur()).isEqualTo(EUR); assertThat(r.getDate()).hasSameTimeAs(DATE_TIME_WITH_TZ.parse("2015-01-30 13:55:00.0 CET")); assertThat(r.getValue()).isEqualByComparingTo("0.88"); }
From source file:de.rahn.finances.services.securities.SecuritiesServiceImplTest.java
/** * Test method for {@link SecuritiesServiceImpl#getSecurities(Pageable)}. *//*from w ww .j a v a 2 s .c o m*/ @Test public void testGetSecuritiesPageable() { Page<Security> page = classUnderTests.getSecurities(null); assertThat(page, notNullValue()); assertThat(page.getNumberOfElements(), is(1)); assertThat(page.getContent(), notNullValue()); assertThat(page.getContent().size(), is(1)); assertThat(page.getContent(), contains(testSecurity)); Pageable pageable = page.nextPageable(); assertThat(pageable, notNullValue()); page = classUnderTests.getSecurities(pageable); assertThat(page, notNullValue()); assertThat(page.getNumberOfElements(), is(0)); assertThat(page.getContent(), empty()); page = classUnderTests.getSecurities(zeroPage); assertThat(page, notNullValue()); assertThat(page.getNumberOfElements(), is(0)); assertThat(page.getContent(), empty()); page = classUnderTests.getSecurities(new PageRequest(10, 10)); assertThat(page, notNullValue()); assertThat(page.getNumberOfElements(), is(0)); assertThat(page.getContent(), empty()); page = classUnderTests.getSecurities(false, stock, null); assertThat(page, notNullValue()); assertThat(page.getNumberOfElements(), is(1)); assertThat(page.getContent(), notNullValue()); assertThat(page.getContent().size(), is(1)); assertThat(page.getContent(), contains(testSecurity)); }
From source file:org.openlmis.fulfillment.web.shipment.ShipmentController.java
/** * Get shipment with request param.// w w w.ja va 2 s . c om * * @param orderId order UUID (required). * @return a page of shipments. */ @GetMapping @ResponseStatus(HttpStatus.OK) @ResponseBody public Page<ShipmentDto> getShipments(@RequestParam(required = false) UUID orderId, Pageable pageable) { XLOGGER.entry(orderId); Profiler profiler = new Profiler("GET_SHIPMENTS"); profiler.setLogger(XLOGGER); profiler.start("VALIDATE"); if (orderId == null) { throw new ValidationException(SHIPMENT_ORDER_REQUIRED); } Order order = orderRepository.findOne(orderId); if (order == null) { throw new ValidationException(ORDER_NOT_FOUND, orderId.toString()); } profiler.start("CHECK_RIGHTS"); permissionService.canViewShipment(order); profiler.start("FIND_BY_ORDER_AND_BUILD_DTO"); Page<Shipment> shipmentPage = shipmentRepository.findByOrder(order, pageable); List<ShipmentDto> shipmentDtos = shipmentDtoBuilder.build(shipmentPage.getContent()); Page<ShipmentDto> page = Pagination.getPage(shipmentDtos, pageable, shipmentPage.getNumberOfElements()); profiler.stop().log(); XLOGGER.exit(page); return page; }
From source file:edu.zipcloud.cloudstreetmarket.core.services.CommunityServiceImpl.java
@Override public Page<UserDTO> getLeaders(Pageable pageable) { Page<User> users = userRepository.findAll(pageable); List<UserDTO> result = users.getContent().stream().map(u -> hideSensitiveInformation(new UserDTO(u))) .collect(Collectors.toCollection(LinkedList::new)); return new PageImpl<>(result, pageable, users.getTotalElements()); }