List of usage examples for org.springframework.data.domain PageImpl PageImpl
public PageImpl(List<T> content)
From source file:org.openlmis.fulfillment.service.referencedata.UserReferenceDataServiceTest.java
@Test public void shouldFindUserByName() { // given/* ww w . j a v a2 s . co m*/ String name = "userName"; UserDto userDto = generateInstance(); userDto.setUsername(name); Map<String, Object> payload = new HashMap<>(); payload.put("username", name); ResponseEntity response = mock(ResponseEntity.class); // 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<>(ImmutableList.of(userDto))); 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.getUsername(), is(equalTo(name))); assertAuthHeader(entityCaptor.getValue()); assertThat(entityCaptor.getValue().getBody(), is(payload)); }
From source file:com.trenako.web.controllers.admin.AdminBrandsControllerTests.java
@SuppressWarnings("unchecked") @Test/*from ww w .j a va 2s . com*/ public void shouldShowTheBrandsList() { Pageable pageable = new PageRequest(0, 10); Page<Brand> results = new PageImpl<Brand>(Arrays.asList(acme(), roco())); when(service.findAll(eq(pageable))).thenReturn(results); String viewName = controller.list(pageable, model); verify(service, times(1)).findAll(eq(pageable)); assertEquals(viewName, "brand/list"); assertTrue(model.containsAttribute("brands")); assertEquals(results, (Page<Brand>) model.get("brands")); }
From source file:it.f2informatica.test.services.domain.user.UserServiceTest.java
@Test public void findAllWithPageable() { PageImpl<UserModel> paginatedResult = new PageImpl<>(getUserList().subList(0, 10)); when(userRepositoryGateway.findAllExcludingCurrentUser(any(Pageable.class), anyString())) .thenReturn(paginatedResult); Page<UserModel> users = userService.findAllExcludingCurrentUser(new PageRequest(1, 10), "jhon"); assertThat(users.getContent()).hasSize(10); }
From source file:org.terasoluna.gfw.functionaltest.app.pagination.PaginationController.java
@RequestMapping(value = "1_4", method = RequestMethod.GET) public String fuinctionTest_1_4(Model model, @PageableDefault Pageable pageable) { List<Person> nameList = new ArrayList<Person>(); model.addAttribute("page", new PageImpl<Person>(nameList)); return "pagination/pagination"; }
From source file:org.openlmis.fulfillment.util.MergerTest.java
@Test public void shouldMergePages() { PageDto<String> page1 = new PageDto<>(new PageImpl<>(ImmutableList.of("a"))); PageDto<String> page2 = new PageDto<>(new PageImpl<>(ImmutableList.of("b", "d"))); PageDto<String> page3 = new PageDto<>(new PageImpl<>(ImmutableList.of("c"))); PageDto<String> merged = Merger.ofPages(ImmutableList.of(page1, page2, page3)).merge(); assertThat(merged, is(notNullValue())); assertThat(merged.getContent(), hasSize(4)); assertThat(merged.getContent(), hasItems("a", "b", "c", "d")); }
From source file:org.apereo.openlrs.storage.inmemory.InMemoryStorage.java
@Override public Page<OpenLRSEntity> findByUser(String userId, Pageable pageable) { Collection<OpenLRSEntity> values = store.values(); if (values != null && !values.isEmpty()) { List<OpenLRSEntity> filtered = null; for (OpenLRSEntity entity : values) { if (entity.toJSON().contains(userId)) { if (filtered == null) { filtered = new ArrayList<OpenLRSEntity>(); }/*from ww w. ja va 2 s.co m*/ filtered.add(entity); } } if (filtered != null) { return new PageImpl<OpenLRSEntity>(filtered); } } return null; }
From source file:org.socialsignin.spring.data.dynamodb.repository.support.SimpleDynamoDBPagingAndSortingRepository.java
@Override public Page<T> findAll(Pageable pageable) { if (pageable.getSort() != null) { throw new UnsupportedOperationException("Sorting not supported for find all scan operations"); }//from w w w .j ava 2s . co m DynamoDBScanExpression scanExpression = new DynamoDBScanExpression(); // Scan to the end of the page after the requested page int scanTo = pageable.getOffset() + (2 * pageable.getPageSize()); scanExpression.setLimit(scanTo); PaginatedScanList<T> paginatedScanList = dynamoDBOperations.scan(domainType, scanExpression); Iterator<T> iterator = paginatedScanList.iterator(); int processedCount = 0; if (pageable.getOffset() > 0) { processedCount = scanThroughResults(iterator, pageable.getOffset()); if (processedCount < pageable.getOffset()) return new PageImpl<T>(new ArrayList<T>()); } // Scan ahead to retrieve the next page count List<T> results = readPageOfResults(iterator, pageable.getPageSize()); assertScanEnabled(enableScanPermissions.isFindAllPaginatedScanEnabled(), "findAll(Pageable pageable)"); assertScanCountEnabled(enableScanPermissions.isFindAllUnpaginatedScanCountEnabled(), "findAll(Pageable pageable)"); int totalCount = dynamoDBOperations.count(domainType, scanExpression); return new PageImpl<T>(results, pageable, totalCount); }
From source file:net.maritimecloud.endorsement.controllers.EndorsementControllerTests.java
/** * Try to get a endorsement without being authenticated *//*w w w. ja v a 2s. c o m*/ @Test public void testAccessGetEndorsementWithoutAuthentication() { 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").header("Origin", "bla")) .andExpect(status().isUnauthorized()); } catch (Exception e) { e.printStackTrace(); assertTrue(false); } }
From source file:com.googlecode.spring.appengine.objectify.repository.SimpleOfyRepository.java
@Override public Page<T> findAll(Pageable pageable) { if (pageable == null) { return new PageImpl<T>(findAll()); }/*from w w w . java2s . c o m*/ Query<T> query = query(); query.offset(pageable.getOffset()); query.limit(pageable.getPageSize()); long total = count(); List<T> content = total > pageable.getOffset() ? query.list() : Collections.<T>emptyList(); return new PageImpl<T>(content, pageable, total); }
From source file:egov.data.hibernate.repository.support.SimpleHibernateRepository.java
@Override public Page<T> findAll(Pageable pageable) { if (pageable == null) { return new PageImpl<T>(findAll()); }//from w w w .j a v a2s . com return (Page<T>) getCriteria(null, pageable).list(); }