Search in sources :

Example 56 with PageRequest

use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.

the class OwnerResourceTest method consumerCanListConsumersByIdWhenOtherParametersPresent.

@Test
public void consumerCanListConsumersByIdWhenOtherParametersPresent() {
    Consumer c = createConsumer(owner);
    List<String> uuids = new ArrayList<>();
    uuids.add(c.getUuid());
    setupPrincipal(owner, Access.ALL);
    securityInterceptor.enable();
    Set<String> types = new HashSet<>();
    types.add("type");
    consumerTypeCurator.create(new ConsumerType("type"));
    CandlepinQuery<ConsumerDTO> result = ownerResource.listConsumers(owner.getKey(), "username", types, uuids, null, null, null, null, null, new PageRequest());
    assertNotNull(result);
    List<ConsumerDTO> consumers = result.list();
    assertEquals(0, consumers.size());
}
Also used : PageRequest(org.candlepin.common.paging.PageRequest) UpstreamConsumer(org.candlepin.model.UpstreamConsumer) Consumer(org.candlepin.model.Consumer) UpstreamConsumerDTO(org.candlepin.dto.api.v1.UpstreamConsumerDTO) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) ConsumerType(org.candlepin.model.ConsumerType) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 57 with PageRequest

use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.

the class CandlepinQueryInterceptorTest method testWritePaginatedCandlepinQueryContents.

@Test
@Parameters(method = "paramsForPaginatedContentTest")
public void testWritePaginatedCandlepinQueryContents(int page, int perPage, String sortBy, PageRequest.Order order) throws IOException {
    int offset = (page - 1) * perPage;
    int end = offset + perPage;
    List<Owner> owners = this.ownerCurator.listAll().addOrder(order == PageRequest.Order.ASCENDING ? Order.asc(sortBy) : Order.desc(sortBy)).list();
    PageRequest pageRequest = new PageRequest();
    pageRequest.setPage(page);
    pageRequest.setPerPage(perPage);
    pageRequest.setSortBy(sortBy);
    pageRequest.setOrder(order);
    CandlepinQueryInterceptor cqi = new CandlepinQueryInterceptor(this.mockJsonProvider, this.emProvider);
    ServerResponse response = new ServerResponse();
    response.setEntity(this.ownerCurator.listAll());
    ResteasyProviderFactory.pushContext(PageRequest.class, pageRequest);
    cqi.postProcess(response);
    assertTrue(response.getEntity() instanceof StreamingOutput);
    ((StreamingOutput) response.getEntity()).write(this.mockOutputStream);
    verify(this.mockJsonGenerator, times(1)).writeStartArray();
    for (int i = 0; i < owners.size(); ++i) {
        Owner owner = owners.get(i);
        if (i < offset || i >= end) {
            verify(this.mockObjectMapper, never()).writeValue(eq(this.mockJsonGenerator), eq(owner));
        } else {
            verify(this.mockObjectMapper, times(1)).writeValue(eq(this.mockJsonGenerator), eq(owner));
        }
    }
    verify(this.mockJsonGenerator, times(1)).writeEndArray();
}
Also used : ServerResponse(org.jboss.resteasy.core.ServerResponse) Owner(org.candlepin.model.Owner) PageRequest(org.candlepin.common.paging.PageRequest) StreamingOutput(javax.ws.rs.core.StreamingOutput) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 58 with PageRequest

use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.

the class PoolManagerFunctionalTest method testListAllForConsumerIncludesWarnings.

@Test
public void testListAllForConsumerIncludesWarnings() {
    Page<List<Pool>> results = poolManager.listAvailableEntitlementPools(parentSystem, null, parentSystem.getOwnerId(), null, null, null, true, new PoolFilterBuilder(), new PageRequest(), false, false, null);
    assertEquals(4, results.getPageData().size());
    Pool pool = createPool(o, socketLimitedProduct, 100L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2050, 3, 2));
    poolCurator.create(pool);
    parentSystem.setFact("cpu.sockets", "4");
    results = poolManager.listAvailableEntitlementPools(parentSystem, null, parentSystem.getOwnerId(), null, null, null, true, new PoolFilterBuilder(), new PageRequest(), false, false, null);
    // Expect the warnings to be included. Should have one more pool available.
    assertEquals(5, results.getPageData().size());
}
Also used : PageRequest(org.candlepin.common.paging.PageRequest) PoolFilterBuilder(org.candlepin.model.PoolFilterBuilder) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Pool(org.candlepin.model.Pool) Test(org.junit.Test)

Example 59 with PageRequest

use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.

the class PoolManagerFunctionalTest method testListAllForOldGuestExcludesTempPools.

@Test
public void testListAllForOldGuestExcludesTempPools() {
    Pool pool = createPool(o, virtGuest, 100L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2050, 3, 2));
    pool.setAttribute(Pool.Attributes.UNMAPPED_GUESTS_ONLY, "true");
    poolCurator.create(pool);
    Page<List<Pool>> results = poolManager.listAvailableEntitlementPools(childVirtSystem, null, o.getId(), virtGuest.getId(), null, null, true, new PoolFilterBuilder(), new PageRequest(), false, false, null);
    int newbornPools = results.getPageData().size();
    childVirtSystem.setCreated(TestUtil.createDate(2000, 01, 01));
    consumerCurator.update(childVirtSystem);
    results = poolManager.listAvailableEntitlementPools(childVirtSystem, null, o.getId(), virtGuest.getId(), null, null, true, new PoolFilterBuilder(), new PageRequest(), false, false, null);
    assertEquals(newbornPools - 1, results.getPageData().size());
}
Also used : PageRequest(org.candlepin.common.paging.PageRequest) PoolFilterBuilder(org.candlepin.model.PoolFilterBuilder) Pool(org.candlepin.model.Pool) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 60 with PageRequest

use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.

the class AbstractHibernateCurator method listByCriteria.

@SuppressWarnings("unchecked")
@Transactional
public Page<List<E>> listByCriteria(Criteria query, PageRequest pageRequest, boolean postFilter) {
    Page<List<E>> resultsPage;
    if (postFilter) {
        // Create a copy of the page request with just the order and sort by values.
        // Since we are filtering after the results are returned, we don't want
        // to send the page or page size values in.
        PageRequest orderAndSortByPageRequest = null;
        if (pageRequest != null) {
            orderAndSortByPageRequest = new PageRequest();
            orderAndSortByPageRequest.setOrder(pageRequest.getOrder());
            orderAndSortByPageRequest.setSortBy(pageRequest.getSortBy());
        }
        resultsPage = listByCriteria(query, orderAndSortByPageRequest);
        // Set the pageRequest to the correct object here.
        resultsPage.setPageRequest(pageRequest);
    } else {
        resultsPage = listByCriteria(query, pageRequest);
    }
    return resultsPage;
}
Also used : PageRequest(org.candlepin.common.paging.PageRequest) List(java.util.List) ArrayList(java.util.ArrayList) Transactional(com.google.inject.persist.Transactional)

Aggregations

PageRequest (org.candlepin.common.paging.PageRequest)62 Test (org.junit.Test)54 List (java.util.List)35 ArrayList (java.util.ArrayList)32 LinkedList (java.util.LinkedList)26 Date (java.util.Date)14 Page (org.candlepin.common.paging.Page)13 Pool (org.candlepin.model.Pool)9 PoolFilterBuilder (org.candlepin.model.PoolFilterBuilder)7 Consumer (org.candlepin.model.Consumer)6 Owner (org.candlepin.model.Owner)5 EntitlementDTO (org.candlepin.dto.api.v1.EntitlementDTO)4 Entitlement (org.candlepin.model.Entitlement)4 Product (org.candlepin.model.Product)4 Transactional (com.google.inject.persist.Transactional)3 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)3 EntitlementFilterBuilder (org.candlepin.model.EntitlementFilterBuilder)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 BadRequestException (org.candlepin.common.exceptions.BadRequestException)2