Search in sources :

Example 1 with Response

use of com.opentext.ia.sdk.support.http.Response in project infoarchive-sip-sdk by Enterprise-Content-Management.

the class WhenCreatingQueryResultFromResponse method shouldCreateResultAndNotCloseResponse.

@Test
void shouldCreateResultAndNotCloseResponse() throws IOException {
    int aipQuota = data.integer();
    int resultSetCount = data.integer();
    int aiuQuota = data.integer();
    int resultSetQuota = data.integer();
    // NOPMD mock only
    Response response = mock(Response.class);
    // NOPMD mock only
    InputStream body = mock(InputStream.class);
    when(response.getBody()).thenReturn(body);
    when(response.getHeaderValue("cacheOutAipIgnored", false)).thenReturn(Boolean.TRUE);
    when(response.getHeaderValue("aipQuota", 0)).thenReturn(aipQuota);
    when(response.getHeaderValue("resultSetCount", 0)).thenReturn(resultSetCount);
    when(response.getHeaderValue("aiuQuota", 0)).thenReturn(aiuQuota);
    when(response.getHeaderValue("resultSetQuota", 0)).thenReturn(resultSetQuota);
    try (QueryResult result = factory.create(response, () -> {
    })) {
        assertTrue(result.isCacheOutAipIgnored(), "Is cache-out of AIPs ignored");
        assertEquals(aipQuota, result.getAipQuota(), "AIP quota");
        assertEquals(aiuQuota, result.getAiuQuota(), "AIU quota");
        assertEquals(resultSetCount, result.getResultSetCount(), "# results");
        assertEquals(resultSetQuota, result.getResultSetQuota(), "Result set quota");
        verify(body, never()).close();
        verify(response, never()).close();
    }
    verify(body).close();
    verify(response).close();
}
Also used : Response(com.opentext.ia.sdk.support.http.Response) QueryResult(com.opentext.ia.sdk.client.api.QueryResult) InputStream(java.io.InputStream) Test(org.junit.jupiter.api.Test)

Example 2 with Response

use of com.opentext.ia.sdk.support.http.Response in project infoarchive-sip-sdk by Enterprise-Content-Management.

the class WhenCreatingQueryResultFromResponse method shouldReturnNullIfResponseBodyIsNull.

@Test
void shouldReturnNullIfResponseBodyIsNull() throws IOException {
    // NOPMD mock only
    Response response = mock(Response.class);
    Runnable closer = mock(Runnable.class);
    assertNull(factory.create(response, closer), "Missing query result");
    verify(closer).run();
}
Also used : Response(com.opentext.ia.sdk.support.http.Response) Test(org.junit.jupiter.api.Test)

Aggregations

Response (com.opentext.ia.sdk.support.http.Response)2 Test (org.junit.jupiter.api.Test)2 QueryResult (com.opentext.ia.sdk.client.api.QueryResult)1 InputStream (java.io.InputStream)1