Example usage for org.springframework.data.domain PageRequest getPageNumber

List of usage examples for org.springframework.data.domain PageRequest getPageNumber

Introduction

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

Prototype

public int getPageNumber() 

Source Link

Usage

From source file:com.ushahidi.swiftriver.core.api.service.DropIndexServiceTest.java

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test/*from  w  w  w  .j  ava 2  s.co  m*/
public void findDrops() {
    DropDocument dropDocument = new DropDocument();
    dropDocument.setId("1");
    dropDocument.setChannel("channel");
    dropDocument.setTitle("title");
    dropDocument.setContent("content");

    List<DropDocument> dropDocuments = new ArrayList<DropDocument>();
    dropDocuments.add(dropDocument);

    when(mockRepository.find(anyString(), any(Pageable.class))).thenReturn(dropDocuments);
    dropIndexService.findDrops("keyword", 30, 6);

    // First, we verify that a search is performed against the index
    ArgumentCaptor<PageRequest> pageRequestArgument = ArgumentCaptor.forClass(PageRequest.class);
    ArgumentCaptor<String> searchTermArgument = ArgumentCaptor.forClass(String.class);

    verify(mockRepository).find(searchTermArgument.capture(), pageRequestArgument.capture());

    // Assert that "keyword" is the value used for the search
    String searchTerm = searchTermArgument.getValue();
    assertEquals("keyword", searchTerm);

    // Validate the Pageable instance passed to DropDocumentRepository
    PageRequest pageRequest = pageRequestArgument.getValue();
    assertEquals(5, pageRequest.getPageNumber());
    assertEquals(30, pageRequest.getPageSize());

    // Then we verify that the drops & their metadata are retrieved from the DB 
    ArgumentCaptor<List> dropIdArgument = ArgumentCaptor.forClass(List.class);
    verify(mockDropDao).findAll(dropIdArgument.capture());
}

From source file:org.duracloud.snapshot.rest.SnapshotResourceTest.java

@Test
public void testGetSnapshotContent() {
    String snapshotId = "snapshot-id";
    String prefix = "prefix";
    int page = 1;
    int pageSize = 5;
    String metaName = "metadata-name";
    String metaValue = "metadata-value";
    Long count = 1000l;//from   w  w w.  jav  a  2 s.c om

    Capture<PageRequest> pageRequestCapture = new Capture<>();

    SnapshotContentItem item = new SnapshotContentItem();
    item.setContentId("test");
    item.setMetadata("{\"" + metaName + "\" : \"" + metaValue + "\"}");

    List<SnapshotContentItem> contentIds = Arrays.asList(new SnapshotContentItem[] { item });
    EasyMock.expect(snapshotContentItemRepo.findBySnapshotNameAndContentIdStartingWithOrderByContentIdAsc(
            EasyMock.eq(snapshotId), EasyMock.eq(prefix), EasyMock.capture(pageRequestCapture)))
            .andReturn(contentIds);

    EasyMock.expect(snapshotContentItemRepo.countBySnapshotName(EasyMock.eq(snapshotId))).andReturn(count);

    replayAll();

    Response response = resource.getContent(snapshotId, page, pageSize, prefix);
    GetSnapshotContentBridgeResult result = (GetSnapshotContentBridgeResult) response.getEntity();

    PageRequest pageRequest = pageRequestCapture.getValue();
    Assert.assertEquals(page, pageRequest.getPageNumber());
    Assert.assertEquals(pageSize, pageRequest.getPageSize());

    org.duracloud.snapshot.dto.SnapshotContentItem resultItem = result.getContentItems().get(0);
    Assert.assertEquals("test", resultItem.getContentId());
    Assert.assertEquals(metaValue, resultItem.getContentProperties().get(metaName));
    Assert.assertEquals(count, result.getTotalCount());

}

From source file:com.alliander.osgp.adapter.ws.core.application.services.DeviceManagementService.java

@Transactional(value = "transactionManager")
public Page<Event> findEvents(@Identification final String organisationIdentification,
        final String deviceIdentification, final Integer pageSize, final Integer pageNumber,
        final DateTime from, final DateTime until, final List<EventType> eventTypes)
        throws FunctionalException {

    LOGGER.debug("findEvents called for organisation {} and device {}", organisationIdentification,
            deviceIdentification);//from w  w w .  j  a  v a2  s. c o  m

    final Organisation organisation = this.domainHelperService.findOrganisation(organisationIdentification);

    this.pagingSettings.updatePagingSettings(pageSize, pageNumber);

    final PageRequest request = new PageRequest(this.pagingSettings.getPageNumber(),
            this.pagingSettings.getPageSize(), Sort.Direction.DESC, "dateTime");

    Specifications<Event> specifications = null;

    try {
        if (deviceIdentification != null && !deviceIdentification.isEmpty()) {
            final Device device = this.domainHelperService.findDevice(deviceIdentification);
            this.domainHelperService.isAllowed(organisation, device, DeviceFunction.GET_EVENT_NOTIFICATIONS);

            specifications = where(this.eventSpecifications.isFromDevice(device));
        } else {
            specifications = where(this.eventSpecifications.isAuthorized(organisation));
        }

        if (from != null) {
            specifications = specifications.and(this.eventSpecifications.isCreatedAfter(from.toDate()));
        }

        if (until != null) {
            specifications = specifications.and(this.eventSpecifications.isCreatedBefore(until.toDate()));
        }

        if (eventTypes != null && !eventTypes.isEmpty()) {
            specifications = specifications.and(this.eventSpecifications.hasEventTypes(eventTypes));
        }
    } catch (final ArgumentNullOrEmptyException e) {
        throw new FunctionalException(FunctionalExceptionType.ARGUMENT_NULL, ComponentType.WS_CORE, e);
    }

    LOGGER.debug("request offset     : {}", request.getOffset());
    LOGGER.debug("        pageNumber : {}", request.getPageNumber());
    LOGGER.debug("        pageSize   : {}", request.getPageSize());
    LOGGER.debug("        sort       : {}", request.getSort());

    return this.eventRepository.findAll(specifications, request);
}