Example usage for org.springframework.data.domain PageImpl PageImpl

List of usage examples for org.springframework.data.domain PageImpl PageImpl

Introduction

In this page you can find the example usage for org.springframework.data.domain PageImpl PageImpl.

Prototype

public PageImpl(List<T> content) 

Source Link

Document

Creates a new PageImpl with the given content.

Usage

From source file:org.openlmis.fulfillment.service.referencedata.UserReferenceDataServiceTest.java

@Test
public void shouldReturnNullIfUserCannotBeFound() {
    // given// w w  w .  jav a 2 s.  c  o m
    String name = "userName";

    ResponseEntity response = mock(ResponseEntity.class);

    Map<String, Object> payload = new HashMap<>();
    payload.put("username", name);

    // when
    when(restTemplate.exchange(any(URI.class), eq(HttpMethod.POST), any(HttpEntity.class),
            any(ParameterizedTypeReference.class))).thenReturn(response);

    PageDto<UserDto> page = new PageDto<>(new PageImpl<>(Collections.emptyList()));
    when(response.getBody()).thenReturn(page);

    UserDto user = service.findUser(name);

    // then
    verify(restTemplate).exchange(uriCaptor.capture(), eq(HttpMethod.POST), entityCaptor.capture(),
            any(ParameterizedTypeReference.class));

    URI uri = uriCaptor.getValue();
    String url = service.getServiceUrl() + service.getUrl() + "search";

    assertThat(uri.toString(), is(equalTo(url)));
    assertThat(user, is(nullValue()));

    assertAuthHeader(entityCaptor.getValue());
    assertThat(entityCaptor.getValue().getBody(), is(payload));
}

From source file:com.frank.search.solr.repository.support.SimpleSolrRepository.java

@Override
public Iterable<T> findAll(Sort sort) {
    int itemCount = (int) this.count();
    if (itemCount == 0) {
        return new PageImpl<T>(Collections.<T>emptyList());
    }//from   ww  w .j a  va  2 s.  com
    return getSolrOperations()
            .queryForPage(new SimpleQuery(new Criteria(Criteria.WILDCARD).expression(Criteria.WILDCARD))
                    .setPageRequest(new SolrPageRequest(0, itemCount)).addSort(sort), getEntityClass());
}

From source file:net.maritimecloud.endorsement.controllers.EndorsementControllerTests.java

/**
 * Try to get a endorsement with authentication
 *//*w  w  w.java 2  s .  c om*/
@Test
public void testAccessGetEndorsementWithAuthentication() {
    KeycloakAuthenticationToken auth = TokenGenerator.generateKeycloakToken("urn:mrn:mcl:org:dma", "ROLE_USER",
            "");

    given(this.endorsementService.listByOrgMrnAndServiceLevel("urn:mrn:mcl:org:dma", "instance", null))
            .willReturn(new PageImpl<Endorsement>(Collections.emptyList()));
    try {
        mvc.perform(get("/oidc/endorsements-by/instance/urn:mrn:mcl:org:dma").with(authentication(auth))
                .header("Origin", "bla")).andExpect(status().isOk());
    } catch (Exception e) {
        e.printStackTrace();
        assertTrue(false);
    }
}

From source file:com.trenako.web.controllers.admin.AdminScalesControllerMappingTests.java

@Test
public void shouldShowTheScalesList() throws Exception {
    when(mockService.findAll(Mockito.isA(Pageable.class)))
            .thenReturn(new PageImpl<Scale>(Arrays.asList(new Scale(), new Scale())));

    mockMvc().perform(get("/admin/scales")).andExpect(status().isOk()).andExpect(model().size(2))
            .andExpect(model().attributeExists("scales")).andExpect(forwardedUrl(view("scale", "list")));
}

From source file:it.reply.orchestrator.service.DeploymentServiceTest.java

@Test
public void getDeploymentsPagedSuccessful() throws Exception {
    Pageable pageable = new PageRequest(0, 10);
    List<Deployment> deployments = ControllerTestUtils.createDeployments(10, false);

    Mockito.when(deploymentRepository.findAll(pageable)).thenReturn(new PageImpl<Deployment>(deployments));

    Page<Deployment> pagedDeployment = deploymentService.getDeployments(pageable);

    Assert.assertEquals(pagedDeployment.getContent(), deployments);
    Assert.assertTrue(pagedDeployment.getNumberOfElements() == 10);
}

From source file:it.reply.orchestrator.controller.ResourceControllerTest.java

@Test
public void getResources() throws Exception {
    Pageable pageable = ControllerTestUtils.createDefaultPageable();
    Deployment deployment = ControllerTestUtils.createDeployment();
    List<Resource> resources = ControllerTestUtils.createResources(deployment, 2, true);
    Mockito.when(resourceService.getResources(deployment.getId(), pageable))
            .thenReturn(new PageImpl<Resource>(resources));

    mockMvc.perform(get("/deployments/" + deployment.getId() + "/resources").accept(MediaType.APPLICATION_JSON)
            .header(HttpHeaders.AUTHORIZATION, OAuth2AccessToken.BEARER_TYPE + " <access token>"))
            .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON))
            .andExpect(jsonPath("$.content", org.hamcrest.Matchers.hasSize(2)))
            .andExpect(jsonPath("$.content", org.hamcrest.Matchers.hasSize(2)))
            .andExpect(jsonPath("$.page.totalElements", equalTo(2)))
            .andExpect(jsonPath("$.links[0].rel", is("self")))
            .andExpect(//w ww  .  j a v  a 2s .c om
                    jsonPath("$.links[0].href", endsWith("/deployments/" + deployment.getId() + "/resources")))

            .andDo(document("resources", preprocessResponse(prettyPrint()), responseFields(
                    fieldWithPath("links[]").ignored(),
                    fieldWithPath("content[].uuid").description("The unique identifier of a resource"),
                    fieldWithPath("content[].creationTime").description(
                            "Creation date-time (http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14)"),
                    fieldWithPath("content[].state").description(
                            "The status of the resource. (http://indigo-dc.github.io/orchestrator/apidocs/it/reply/orchestrator/enums/NodeStates.html)"),
                    fieldWithPath("content[].toscaNodeType").optional()
                            .description("The type of the represented TOSCA node"),
                    fieldWithPath("content[].toscaNodeName").optional()
                            .description("The name of the represented TOSCA node"),
                    fieldWithPath("content[].requiredBy")
                            .description("A list of nodes that require this resource"),
                    fieldWithPath("content[].links[]").ignored(), fieldWithPath("page").ignored())));

}

From source file:am.ik.categolj3.api.entry.EntryRestControllerDocumentation.java

@Test
public void getEntries() throws Exception {
    when(this.entryService.findAll(anyObject())).thenReturn(new PageImpl<>(mockEntries));
    this.mockMvc.perform(get("/api/entries")).andExpect(status().isOk())
            .andExpect(jsonPath("$.numberOfElements", is(2))).andExpect(jsonPath("$.number", is(0)))
            .andExpect(jsonPath("$.totalElements", is(2)))
            .andExpect(jsonPath("$.content[0].content", is(notNullValue())))
            .andExpect(jsonPath("$.content[0].entryId", is(2)))
            .andExpect(jsonPath("$.content[1].content", is(notNullValue())))
            .andExpect(jsonPath("$.content[1].entryId", is(1))).andDo(document("get-entries"));
}

From source file:org.yukung.daguerreo.domain.repository.BasicJooqRepository.java

/**
 * {@inheritDoc}/* ww  w  .j  a va 2 s. c o m*/
 */
@Override
public Page<E> findAll(Pageable pageable) {
    if (pageable == null) {
        return new PageImpl<>(findAll());
    }
    SelectQuery<R> query = getQuery(pageable);
    return new PageImpl<>(query.fetch().map(mapper()), pageable, count());
}

From source file:com.real.apps.shuttle.controller.VehicleControllerTest.java

@Test
public void shouldFindVehiclesForTheCompanyWhenACompanyUserIsLoggedIn() throws Exception {
    final ObjectId id = ObjectId.get();
    Vehicle vehicle = new Vehicle();
    vehicle.setCompanyId(id);//from  w w w. ja  v a  2 s .c  om
    final Page<Vehicle> page = new PageImpl<>(Arrays.asList(vehicle));

    context.checking(new Expectations() {
        {
            oneOf(service).pageByCompanyId(id, skip, limit);
            will(returnValue(page));
        }
    });
    controller.setService(service);
    mockMvc.perform(get(String.format("/%s/%d/%d", VIEW_PAGE, skip, limit)).with(user(companyUser(id))))
            .andExpect(status().isOk())
            .andExpect(jsonPath("$.content[0].companyId._time").value(id.getTimestamp()));

}

From source file:io.curly.artifact.service.DefaultArtifactCommand.java

@Loggable
@SuppressWarnings("unused")
@HystrixCommand//w  w w  .j av  a  2  s. co m
private Optional<Page<Artifact>> defaultFindAll(Pageable pageable) {
    log.warn("Default find all owned triggered on page {}", pageable.getPageNumber());
    return Optional.of(new PageImpl<>(Collections.emptyList()));
}