List of usage examples for org.springframework.data.domain PageImpl PageImpl
public PageImpl(List<T> content)
From source file:com.alliander.osgp.acceptancetests.devicemanagement.RetrieveReceivedEventNotificationsSteps.java
@DomainStep("a received event notification at (.*) from (.*)") public void givenAReceivedEventNotificationAtFrom(final String timestamp, final String device) { LOGGER.info("GIVEN: a received event notification at (.*) from (.*)", timestamp, device); this.event = new EventBuilder().withDevice(new DeviceBuilder().withDeviceIdentification(device).build()) .build();/*from www . j a va 2 s. c om*/ final List<Event> eventList = new ArrayList<Event>(); eventList.add(this.event); this.eventsPage = new PageImpl<Event>(eventList); LOGGER.info("events: {}", this.eventsPage.getContent().size()); when(this.eventRepositoryMock.findAll(Matchers.<Specifications<Event>>any(), any(PageRequest.class))) .thenReturn(this.eventsPage); }
From source file:it.reply.orchestrator.controller.DeploymentControllerTest.java
@Test public void deploymentsPagination() throws Exception { List<Deployment> deployments = ControllerTestUtils.createDeployments(5, true); Pageable pageable = ControllerTestUtils.createDefaultPageable(); Mockito.when(deploymentService.getDeployments(pageable)).thenReturn(new PageImpl<Deployment>(deployments)); mockMvc.perform(get("/deployments").header(HttpHeaders.AUTHORIZATION, OAuth2AccessToken.BEARER_TYPE + " <access token>")).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andDo(document("deployment-pagination", preprocessResponse(prettyPrint()), responseFields( fieldWithPath("links[]").ignored(), fieldWithPath("content[].links[]").ignored(), fieldWithPath("page.size").description("The size of the page"), fieldWithPath("page.totalElements").description("The total number of elements"), fieldWithPath("page.totalPages").description("The total number of the page"), fieldWithPath("page.number").description("The current page"), fieldWithPath("content[].uuid").ignored(), fieldWithPath("content[].creationTime").ignored(), fieldWithPath("content[].updateTime").ignored(), fieldWithPath("content[].status").ignored(), fieldWithPath("content[].outputs").ignored(), fieldWithPath("content[].task").ignored(), fieldWithPath("content[].callback").ignored()))); }
From source file:com.uni.dao.etc.UniJpaRepository.java
public Page<T> findAll(Specification<T> spec, Pageable pageable) { TypedQuery<T> query = getQuery(spec, pageable); return pageable == null ? new PageImpl<T>(query.getResultList()) : readPage(query, pageable, spec); }
From source file:org.openlmis.fulfillment.web.ShipmentControllerIntegrationTest.java
@Test public void shouldFindShipmentBasedOnOrder() { when(orderRepository.findOne(orderId)).thenReturn(shipment.getOrder()); when(shipmentRepository.findByOrder(eq(shipment.getOrder()), any(Pageable.class))) .thenReturn(new PageImpl<>(singletonList(shipment))); PageDto response = restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .queryParam("page", 2).queryParam("size", 10).contentType(APPLICATION_JSON_VALUE) .queryParam(ORDER_ID, orderId).when().get(RESOURCE_URL).then().statusCode(200).extract() .as(PageDto.class); assertEquals(10, response.getSize()); assertEquals(2, response.getNumber()); assertEquals(1, response.getContent().size()); assertEquals(1, response.getNumberOfElements()); assertEquals(21, response.getTotalElements()); assertEquals(3, response.getTotalPages()); assertEquals(shipmentDtoExpected, getPageContent(response, ShipmentDto.class).get(0)); assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:io.pivotal.strepsirrhini.chaosloris.web.ChaosControllerTest.java
@Test public void list() throws Exception { Application application = new Application(UUID.randomUUID()); application.setId(1L);/*from www. j ava 2 s .com*/ Schedule schedule = new Schedule("0 0 * * * *", "hourly"); schedule.setId(2L); Chaos chaos = new Chaos(application, 0.1, schedule); chaos.setId(3L); when(this.chaosRepository.findAll(new PageRequest(0, 20))) .thenReturn(new PageImpl<>(Collections.singletonList(chaos))); this.mockMvc.perform(get("/chaoses").accept(HAL_JSON)).andExpect(status().isOk()) .andExpect(jsonPath("$.page").exists()).andExpect(jsonPath("$._embedded.chaoses").value(hasSize(1))) .andExpect(jsonPath("$._links.self").exists()); }
From source file:com.ethlo.geodata.GeodataServiceImpl.java
@Override public Page<Continent> findContinents() { final List<Continent> continents = findByIds(CONTINENT_IDS.values()).stream().filter(Objects::nonNull) .map(l -> new Continent(getContinentCode(l.getId()), l)).filter(Objects::nonNull) .collect(Collectors.toList()); return new PageImpl<>(continents); }
From source file:com.ethlo.geodata.GeodataServiceImpl.java
@Override public Page<Country> findCountriesOnContinent(String continentCode, Pageable pageable) { final Long continentId = CONTINENT_IDS.get(continentCode.toUpperCase()); if (continentId == null) { return new PageImpl<>(Collections.emptyList()); }/* ww w. ja va 2s . co m*/ return findChildren(continentId, pageable).map(l -> findCountryById(l.getId())); }
From source file:org.openlmis.fulfillment.web.ShipmentDraftControllerIntegrationTest.java
@Test public void shouldFindShipmentDraftBasedOnOrder() { when(orderRepository.findOne(shipmentDraftDtoExpected.getOrder().getId())) .thenReturn(shipmentDraft.getOrder()); when(shipmentDraftRepository.findByOrder(eq(shipmentDraft.getOrder()), any(Pageable.class))) .thenReturn(new PageImpl<>(singletonList(shipmentDraft))); PageDto response = restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .queryParam("page", 2).queryParam("size", 10).contentType(APPLICATION_JSON_VALUE) .queryParam(ORDER_ID, shipmentDraftDtoExpected.getOrder().getId()).when().get(RESOURCE_URL).then() .statusCode(200).extract().as(PageDto.class); assertEquals(10, response.getSize()); assertEquals(2, response.getNumber()); assertEquals(1, response.getContent().size()); assertEquals(1, response.getNumberOfElements()); assertEquals(21, response.getTotalElements()); assertEquals(3, response.getTotalPages()); assertEquals(shipmentDraftDtoExpected, getPageContent(response, ShipmentDraftDto.class).get(0)); assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:org.apereo.openlrs.storage.aws.elasticsearch.XApiOnlyAwsElasticsearchTierTwoStorage.java
private Page<OpenLRSEntity> createPage(Iterable<Statement> statements) { if (statements != null) { return new PageImpl<OpenLRSEntity>(IteratorUtils.toList(statements.iterator())); }//from w ww . j a v a 2s .c om return null; }
From source file:it.reply.orchestrator.service.deployment.providers.ImServiceTest.java
@Test public void testFinalizeDeploy() throws ImClientException { DeploymentMessage dm = generateIsDeployedDm(); Map<String, Object> outputs = Maps.newHashMap(); outputs.put("firstKey", 1); outputs.put("SecondKey", null); InfOutputValues outputValues = new InfOutputValues(outputs); InfrastructureUris vmUrls = new InfrastructureUris(Lists.newArrayList()); vmUrls.getUris().add(new InfrastructureUri( "http://localhost/infrastructures/" + dm.getDeployment().getEndpoint() + "/" + 0)); vmUrls.getUris().add(new InfrastructureUri( "http://localhost/infrastructures/" + dm.getDeployment().getEndpoint() + "/" + 1)); VirtualMachineInfo vmInfo0 = new VirtualMachineInfo(Lists.newArrayList()); vmInfo0.getVmProperties().add(Maps.newHashMap()); vmInfo0.getVmProperties().get(0).put("id", dm.getDeployment().getResources().get(0).getToscaNodeName()); VirtualMachineInfo vmInfo1 = new VirtualMachineInfo(Lists.newArrayList()); vmInfo0.getVmProperties().get(0).put("id", dm.getDeployment().getResources().get(1).getToscaNodeName()); Mockito.when(deploymentRepository.findOne(dm.getDeployment().getId())).thenReturn(dm.getDeployment()); Mockito.when(deploymentRepository.save(dm.getDeployment())).thenReturn(dm.getDeployment()); Mockito.when(resourceRepository.findByDeployment_id(dm.getDeployment().getId(), null)) .thenReturn(new PageImpl<Resource>(dm.getDeployment().getResources())); Mockito.doReturn(infrastructureManager).when(imService).getClient(Mockito.any(DeploymentMessage.class)); Mockito.when(infrastructureManager.getInfrastructureOutputs(dm.getDeployment().getEndpoint())) .thenReturn(outputValues);//from ww w .java 2s . c om Mockito.when(infrastructureManager.getInfrastructureInfo(dm.getDeployment().getEndpoint())) .thenReturn(vmUrls); Mockito.when(infrastructureManager.getVmInfo(dm.getDeployment().getEndpoint(), String.valueOf(0))) .thenReturn(vmInfo0); Mockito.when(infrastructureManager.getVmInfo(dm.getDeployment().getEndpoint(), String.valueOf(1))) .thenReturn(vmInfo1); imService.finalizeDeploy(dm, true); Assert.assertEquals(dm.getDeployment().getTask(), Task.NONE); Assert.assertEquals(dm.getDeployment().getStatus(), Status.CREATE_COMPLETE); Assert.assertEquals(dm.getDeployment().getDeploymentProvider(), DeploymentProvider.IM); Assert.assertEquals(dm.getDeployment().getEndpoint(), dm.getDeployment().getEndpoint()); Assert.assertEquals(dm.getDeployment().getResources().size(), 2); Assert.assertEquals(dm.getDeployment().getResources().get(0).getState(), NodeStates.STARTED); Assert.assertEquals(dm.getDeployment().getResources().get(1).getState(), NodeStates.STARTED); Assert.assertFalse(dm.isPollComplete()); }