Search in sources :

Example 1 with SearchQuery

use of com.opentext.ia.sdk.dto.query.SearchQuery 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 SearchQuery

use of com.opentext.ia.sdk.dto.query.SearchQuery in project infoarchive-sip-sdk by Enterprise-Content-Management.

the class WhenUsingInfoArchive method shouldSearchSuccessfully.

@Test
void shouldSearchSuccessfully() throws IOException {
    SearchResults searchResults = mock(SearchResults.class);
    when(searchResults.getUri("next")).thenReturn(null);
    when(restClient.post(anyString(), eq(SearchResults.class), anyString(), eq(MediaTypes.XML))).thenReturn(searchResults);
    SearchQuery searchQuery = new SearchQuery();
    List<Item> items = new ArrayList<>();
    items.add(new Comparison("from", Operator.EQUAL, ""));
    items.add(new Comparison("recipient", Operator.EQUAL, ""));
    List<String> dates = new ArrayList<>();
    dates.add("2014-04-27");
    dates.add("2016-10-11");
    items.add(new Comparison("sentDate", Operator.BETWEEN, dates));
    items.add(new Comparison("fromCountry", Operator.STARTS_WITH, ""));
    items.add(new Comparison("toCountry", Operator.NOT_EQUAL, ""));
    searchQuery.setItems(items);
    SearchComposition searchComparison = new SearchComposition();
    Map<String, Link> searchComparisonLinks = new HashMap<>();
    Link compositionLink = new Link();
    compositionLink.setHref(randomString());
    searchComparisonLinks.put("self", compositionLink);
    searchComparison.setLinks(searchComparisonLinks);
    configureServer();
    SearchResults result = archiveClient.search(searchQuery, searchComparison);
    assertEquals(searchResults, result);
}
Also used : SearchQuery(com.opentext.ia.sdk.dto.query.SearchQuery) Item(com.opentext.ia.sdk.dto.query.Item) Comparison(com.opentext.ia.sdk.dto.query.Comparison) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StringContains.containsString(org.hamcrest.core.StringContains.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Link(com.opentext.ia.sdk.support.http.rest.Link) Test(org.junit.jupiter.api.Test)

Aggregations

Comparison (com.opentext.ia.sdk.dto.query.Comparison)2 SearchQuery (com.opentext.ia.sdk.dto.query.SearchQuery)2 Link (com.opentext.ia.sdk.support.http.rest.Link)2 QueryResult (com.opentext.ia.sdk.client.api.QueryResult)1 Item (com.opentext.ia.sdk.dto.query.Item)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 StringContains.containsString (org.hamcrest.core.StringContains.containsString)1 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1