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:com.trenako.web.controllers.admin.AdminRailwaysControllerMappingTests.java

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

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

From source file:it.f2informatica.core.gateway.mysql.UserRepositoryGatewayMySQL.java

@Override
public Page<UserModel> findAllExcludingCurrentUser(Pageable pageable, String usernameToExclude) {
    return new PageImpl<>(mysqlUserToModelConverter
            .convertList(userRepository.findAllExcludingCurrentUser(usernameToExclude)));
}

From source file:org.apereo.openlrs.storage.inmemory.InMemoryStorage.java

@Override
public Page<OpenLRSEntity> findByContextAndUser(String context, 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(context) && entity.toJSON().contains(userId)) {
                if (filtered == null) {
                    filtered = new ArrayList<OpenLRSEntity>();
                }//from  ww  w  .j  a v  a  2s . c  o m

                filtered.add(entity);
            }
        }
        if (filtered != null) {
            return new PageImpl<OpenLRSEntity>(filtered);
        }
    }
    return null;
}

From source file:it.f2informatica.core.gateway.mongodb.UserRepositoryGatewayMongoDB.java

@Override
public Page<UserModel> findAllExcludingCurrentUser(Pageable pageable, String usernameToExclude) {
    return new PageImpl<>(Lists.newArrayList(userToModelConverter
            .convertIterable(userRepository.findAllExcludingUser(usernameToExclude, pageable))));
}

From source file:de.rahn.finances.server.web.ui.SecuritiesControllerTest.java

/**
 * Initialisiere die Testgren./*from w w w  .  java  2 s  .c o m*/
 */
@Before
public void setup() {
    when(securitiesService.getSecurities(anyBoolean(), any())).thenAnswer(invocation -> {
        List<Security> securitiesList = new ArrayList<>();

        Pageable pageable = invocation.getArgumentAt(1, Pageable.class);

        if (pageable == null || pageable.getPageNumber() == 0) {
            for (int i = 0; i < 10; i++) {
                Security security = new Security();
                security.setIsin(ISIN1 + i);
                security.setType(stock);
                security.setInventory(true);

                securitiesList.add(security);
            }
        }
        if (pageable == null || pageable.getPageNumber() == 1) {
            for (int i = 0; i < 10; i++) {
                Security security = new Security();
                security.setIsin(ISIN2 + i);
                security.setType(stock);
                security.setInventory(true);

                securitiesList.add(security);
            }
        }

        return new PageImpl<>(securitiesList);
    });

    when(securitiesService.getSecurity(ID_FOUND)).thenReturn(new Security() {
        {
            setId(ID_FOUND);
            setIsin(ISIN1 + "0");
            setType(stock);
            setInventory(true);
        }
    });

    when(securitiesService.getSecurity(ID_NOT_FOUND)).thenThrow(new SecurityNotFoundException(ID_NOT_FOUND));

    when(securitiesService.save(any(Security.class))).thenAnswer(invocation -> {
        String isin = invocation.getArgumentAt(0, Security.class).getIsin();

        if (ISIN_NOT_SAVE.equals(isin)) {
            throw new RuntimeException("could not execute statement");
        }

        return null;
    });
}

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

@Loggable
@SuppressWarnings("unused")
@HystrixCommand//w  w w  .j  a  va  2 s. com
private Optional<Page<Artifact>> defaultFindAllOwned(Pageable pageable, User user) {
    log.warn("Default find all owned triggered for user {} on page {}", user.getId(), pageable.getPageNumber());
    return Optional.of(new PageImpl<>(Collections.emptyList()));
}

From source file:capital.scalable.restdocs.example.items.ItemResource.java

/**
 * Searches for item based on lookup parameters.
 *
 * @param descMatch Lookup on description field.
 * @param hint      Lookup hint.//from  ww w  .j  a  v  a 2  s. c  o  m
 */
@RequestMapping("search")
public Page<ItemResponse> searchItem(@RequestParam("desc") @NotBlank @Size(max = 255) String descMatch,
        @RequestParam(required = false) @Min(10) @Max(100) Integer hint) {
    if (ITEM.getDescription().contains(descMatch)) {
        return new PageImpl<>(singletonList(ITEM));
    } else {
        return new PageImpl<>(Collections.<ItemResponse>emptyList());
    }
}

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

@Test
public void getEntriesExcludeContent() throws Exception {
    when(this.entryService.findAll(anyObject(),
            eq(SearchEntryOperations.SearchOptions.builder().excludeContent(true).build())))
                    .thenReturn(new PageImpl<>(
                            mockEntries.stream().peek(e -> e.setContent(null)).collect(Collectors.toList())));
    this.mockMvc.perform(get("/api/entries").param("excludeContent", "true")).andExpect(status().isOk())
            .andExpect(jsonPath("$.numberOfElements", is(2))).andExpect(jsonPath("$.number", is(0)))
            .andExpect(jsonPath("$.totalElements", is(2)))
            .andExpect(jsonPath("$.content[0].content").doesNotExist())
            .andExpect(jsonPath("$.content[0].entryId", is(2)))
            .andExpect(jsonPath("$.content[1].content").doesNotExist())
            .andExpect(jsonPath("$.content[1].entryId", is(1))).andDo(document("get-entries-exclude-content"));
}

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

@Test
public void shouldFindUsersByIds() {
    // given/* ww w. j a  va 2 s. c  o  m*/
    UUID id = UUID.randomUUID();
    UUID id2 = UUID.randomUUID();
    List<UUID> ids = Arrays.asList(id, id2);

    UserDto user = generateInstance();
    user.setId(id);
    UserDto anotherUser = generateInstance();
    anotherUser.setId(id2);

    Map<String, Object> payload = new HashMap<>();
    payload.put("id", ids);
    ResponseEntity response = mock(ResponseEntity.class);

    // when
    when(response.getBody()).thenReturn(new PageDto<>(new PageImpl<>(Arrays.asList(user, anotherUser))));
    when(restTemplate.exchange(any(URI.class), eq(HttpMethod.GET), any(HttpEntity.class),
            any(ParameterizedTypeReference.class))).thenReturn(response);

    List<UserDto> users = service.findByIds(ids);

    // then
    verify(restTemplate).exchange(uriCaptor.capture(), eq(HttpMethod.GET), entityCaptor.capture(),
            any(ParameterizedTypeReference.class));
    assertTrue(users.contains(user));
    assertTrue(users.contains(anotherUser));

    String actualUrl = uriCaptor.getValue().toString();
    assertTrue(actualUrl.startsWith(service.getServiceUrl() + service.getUrl()));
    assertTrue(actualUrl.contains(id.toString()));
    assertTrue(actualUrl.contains(id2.toString()));

    assertAuthHeader(entityCaptor.getValue());
}

From source file:io.pivotal.strepsirrhini.chaosloris.web.ApplicationControllerTest.java

@Test
public void list() throws Exception {
    Application application = new Application(UUID.randomUUID());
    application.setId(1L);//www . j av a 2  s . co  m

    when(this.applicationRepository.findAll(new PageRequest(0, 20)))
            .thenReturn(new PageImpl<>(Collections.singletonList(application)));

    this.mockMvc.perform(get("/applications").accept(HAL_JSON)).andExpect(status().isOk())
            .andExpect(jsonPath("$.page").exists()).andExpect(jsonPath("$._embedded.applications").exists())
            .andExpect(jsonPath("$._links").exists());
}