Search in sources :

Example 1 with QueryResult

use of com.opentext.ia.sdk.client.api.QueryResult in project infoarchive-sip-sdk by Enterprise-Content-Management.

the class WhenUsingInfoArchive method shouldQuerySuccessfully.

@Test
public void shouldQuerySuccessfully() throws IOException {
    when(aics.getItems()).thenReturn(Stream.of(aic));
    Link dipLink = new Link();
    dipLink.setHref(randomString());
    aic.getLinks().put(LINK_DIP, dipLink);
    aic.setName("MyAic");
    UriBuilder uriBuilder = mock(UriBuilder.class);
    String uri = randomString();
    when(uriBuilder.build()).thenReturn(uri);
    when(uriBuilder.addParameter(anyString(), anyString())).thenReturn(uriBuilder);
    when(restClient.uri(anyString())).thenReturn(uriBuilder);
    QueryResultFactory queryResultFactory = mock(QueryResultFactory.class);
    DefaultQueryResult queryResult = mock(DefaultQueryResult.class);
    when(queryResultFactory.create(any(Response.class), any(Runnable.class))).thenReturn(queryResult);
    when(restClient.get(eq(uri), any(QueryResultFactory.class))).thenReturn(queryResult);
    SearchQuery query = new SearchQuery();
    query.getItems().add(new Comparison("variable", Operator.EQUAL, "value"));
    String aicName = "MyAic";
    String schema = NAMESPACE;
    configureServer();
    QueryResult result = archiveClient.query(query, aicName, schema, 10);
    assertEquals(queryResult, result);
}
Also used : SearchQuery(com.opentext.ia.sdk.dto.query.SearchQuery) QueryResult(com.opentext.ia.sdk.client.api.QueryResult) Comparison(com.opentext.ia.sdk.dto.query.Comparison) Link(com.opentext.ia.sdk.support.http.rest.Link) Test(org.junit.Test)

Example 2 with QueryResult

use of com.opentext.ia.sdk.client.api.QueryResult in project infoarchive-sip-sdk by Enterprise-Content-Management.

the class WhenWorkingWithQueryResult method shouldHaveDescriptiveToString.

@Test
void shouldHaveDescriptiveToString() throws IOException {
    try (QueryResult result = newQueryResult()) {
        String string = result.toString();
        assertTrue(string.contains(result.getClass().getSimpleName()));
        assertTrue(string.contains(String.valueOf(aipQouta)));
        assertTrue(string.contains(String.valueOf(aiuQuota)));
        assertTrue(string.contains(String.valueOf(resultSetQuota)));
        assertTrue(string.contains(String.valueOf(resultSetCount)));
        assertTrue(string.contains(String.valueOf(cacheOutIgnored)));
        assertTrue(string.contains(String.valueOf(stream)));
    }
}
Also used : DefaultQueryResult(com.opentext.ia.sdk.client.impl.DefaultQueryResult) QueryResult(com.opentext.ia.sdk.client.api.QueryResult) Test(org.junit.jupiter.api.Test)

Example 3 with QueryResult

use of com.opentext.ia.sdk.client.api.QueryResult in project infoarchive-sip-sdk by Enterprise-Content-Management.

the class WhenWorkingWithQueryResult method shouldHonorSetValues.

@Test
void shouldHonorSetValues() throws IOException {
    try (QueryResult result = newQueryResult()) {
        assertEquals(resultSetQuota, result.getResultSetQuota());
        assertEquals(resultSetCount, result.getResultSetCount());
        assertEquals(aipQouta, result.getAipQuota());
        assertEquals(aiuQuota, result.getAiuQuota());
        assertEquals(cacheOutIgnored, result.isCacheOutAipIgnored());
        assertEquals(stream, result.getResultStream());
    }
}
Also used : DefaultQueryResult(com.opentext.ia.sdk.client.impl.DefaultQueryResult) QueryResult(com.opentext.ia.sdk.client.api.QueryResult) Test(org.junit.jupiter.api.Test)

Example 4 with QueryResult

use of com.opentext.ia.sdk.client.api.QueryResult 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)

Aggregations

QueryResult (com.opentext.ia.sdk.client.api.QueryResult)4 Test (org.junit.jupiter.api.Test)3 DefaultQueryResult (com.opentext.ia.sdk.client.impl.DefaultQueryResult)2 Comparison (com.opentext.ia.sdk.dto.query.Comparison)1 SearchQuery (com.opentext.ia.sdk.dto.query.SearchQuery)1 Response (com.opentext.ia.sdk.support.http.Response)1 Link (com.opentext.ia.sdk.support.http.rest.Link)1 InputStream (java.io.InputStream)1 Test (org.junit.Test)1