use of org.jboss.resteasy.core.ServerResponse 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.jboss.resteasy.core.ServerResponse in project candlepin by candlepin.
the class CandlepinQueryInterceptorTest method testNonCandlepinQueryObjectsAreIgnored.
@Test
public void testNonCandlepinQueryObjectsAreIgnored() {
// This test can't possibly be all-inclusive, so we'll just test most our common cases
// List of entities
List<Owner> owners = this.ownerCurator.listAll().list();
CandlepinQueryInterceptor cqi = new CandlepinQueryInterceptor(this.mockJsonProvider, this.emProvider);
ServerResponse response = new ServerResponse();
response.setEntity(owners);
cqi.postProcess(response);
assertSame(owners, response.getEntity());
// Single entity
Owner owner = owners.get(0);
response.setEntity(owner);
cqi.postProcess(response);
assertSame(owner, response.getEntity());
}
use of org.jboss.resteasy.core.ServerResponse in project candlepin by candlepin.
the class CandlepinQueryInterceptorTest method testWriteCandlepinQueryContents.
@Test
public void testWriteCandlepinQueryContents() throws IOException {
List<Owner> owners = this.ownerCurator.listAll().list();
CandlepinQueryInterceptor cqi = new CandlepinQueryInterceptor(this.mockJsonProvider, this.emProvider);
ServerResponse response = new ServerResponse();
response.setEntity(this.ownerCurator.listAll());
cqi.postProcess(response);
assertTrue(response.getEntity() instanceof StreamingOutput);
((StreamingOutput) response.getEntity()).write(this.mockOutputStream);
verify(this.mockJsonGenerator, times(1)).writeStartArray();
for (Owner owner : owners) {
verify(this.mockObjectMapper, times(1)).writeValue(eq(this.mockJsonGenerator), eq(owner));
}
verify(this.mockJsonGenerator, times(1)).writeEndArray();
}
Aggregations