Search in sources :

Example 1 with ServerResponse

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();
}
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 2 with ServerResponse

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());
}
Also used : ServerResponse(org.jboss.resteasy.core.ServerResponse) Owner(org.candlepin.model.Owner) Test(org.junit.Test)

Example 3 with ServerResponse

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();
}
Also used : ServerResponse(org.jboss.resteasy.core.ServerResponse) Owner(org.candlepin.model.Owner) StreamingOutput(javax.ws.rs.core.StreamingOutput) Test(org.junit.Test)

Aggregations

Owner (org.candlepin.model.Owner)3 ServerResponse (org.jboss.resteasy.core.ServerResponse)3 Test (org.junit.Test)3 StreamingOutput (javax.ws.rs.core.StreamingOutput)2 Parameters (junitparams.Parameters)1 PageRequest (org.candlepin.common.paging.PageRequest)1