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());
}
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();
}
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());
}
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());
}
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;
}
Aggregations