Search in sources :

Example 1 with UriBuilder

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

the class WhenUsingInfoArchive method shouldFetchOrderContentSuccessfully.

@Test
@SuppressWarnings("rawtypes")
public void shouldFetchOrderContentSuccessfully() throws IOException {
    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);
    ResponseFactory contentResultFactory = mock(ContentResultFactory.class);
    DefaultContentResult contentResult = mock(DefaultContentResult.class);
    when(contentResultFactory.create(any(Response.class), any(Runnable.class))).thenReturn(contentResult);
    when(restClient.get(eq(uri), any(ContentResultFactory.class))).thenReturn(contentResult);
    OrderItem orderItem = new OrderItem();
    orderItem.setType("EXPORT");
    Link downloadLink = new Link();
    downloadLink.setHref(randomString());
    orderItem.getLinks().put(LINK_DOWNLOAD, downloadLink);
    configureServer();
    ContentResult result = archiveClient.fetchOrderContent(orderItem);
    assertEquals(contentResult, result);
}
Also used : Response(com.opentext.ia.sdk.support.http.Response) ContentResult(com.opentext.ia.sdk.client.api.ContentResult) DefaultContentResult(com.opentext.ia.sdk.client.impl.DefaultContentResult) ResponseFactory(com.opentext.ia.sdk.support.http.ResponseFactory) DefaultContentResult(com.opentext.ia.sdk.client.impl.DefaultContentResult) ContentResultFactory(com.opentext.ia.sdk.client.impl.ContentResultFactory) StringContains.containsString(org.hamcrest.core.StringContains.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UriBuilder(com.opentext.ia.sdk.support.http.UriBuilder) Link(com.opentext.ia.sdk.support.http.rest.Link) Test(org.junit.jupiter.api.Test)

Example 2 with UriBuilder

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

the class WhenUsingInfoArchive method shouldExportSuccessfully.

@Test
void shouldExportSuccessfully() throws IOException {
    UriBuilder uriBuilder = mock(UriBuilder.class);
    String uri = randomString();
    when(uriBuilder.build()).thenReturn(uri);
    when(uriBuilder.addParameter(anyString(), anyString())).thenReturn(uriBuilder);
    when(restClient.uri(any())).thenReturn(uriBuilder);
    OrderItem orderItem = mock(OrderItem.class);
    when(restClient.post(eq(uri), eq(OrderItem.class), anyString())).thenReturn(orderItem);
    SearchResults searchResults = new SearchResults();
    SearchResult searchResult = new SearchResult();
    List<Row> rows = new ArrayList<>();
    Row row = new Row();
    row.setId(randomString());
    rows.add(row);
    searchResult.setRows(rows);
    searchResults.addResult(searchResult);
    ExportConfiguration exportConfiguration = mock(ExportConfiguration.class);
    when(exportConfiguration.getSelfUri()).thenReturn(uri);
    configureServer();
    OrderItem result = archiveClient.export(searchResults, exportConfiguration, randomString());
    assertEquals(orderItem, result);
}
Also used : ExportConfiguration(com.opentext.ia.sdk.dto.export.ExportConfiguration) ArrayList(java.util.ArrayList) StringContains.containsString(org.hamcrest.core.StringContains.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UriBuilder(com.opentext.ia.sdk.support.http.UriBuilder) Test(org.junit.jupiter.api.Test)

Example 3 with UriBuilder

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

the class RestClient method replacePageQueryParameters.

private String replacePageQueryParameters(String href, int page, int size) {
    try {
        URIBuilder uriBuilder = new URIBuilder(href);
        List<NameValuePair> queryParameters = uriBuilder.getQueryParams().stream().filter(p -> !"page".equals(p.getName()) && !"size".equals(p.getName())).collect(Collectors.toList());
        uriBuilder.setParameters(queryParameters);
        uriBuilder.addParameter("page", String.valueOf(page));
        uriBuilder.addParameter("size", String.valueOf(size));
        return uriBuilder.build().toString();
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : Files(java.nio.file.Files) URIBuilder(org.apache.http.client.utils.URIBuilder) BinaryPart(com.opentext.ia.sdk.support.http.BinaryPart) URISyntaxException(java.net.URISyntaxException) Collection(java.util.Collection) StandardOpenOption(java.nio.file.StandardOpenOption) IOException(java.io.IOException) UriBuilder(com.opentext.ia.sdk.support.http.UriBuilder) Part(com.opentext.ia.sdk.support.http.Part) Collectors(java.util.stream.Collectors) File(java.io.File) ResponseFactory(com.opentext.ia.sdk.support.http.ResponseFactory) ArrayList(java.util.ArrayList) Objects(java.util.Objects) List(java.util.List) Closeable(java.io.Closeable) HttpClient(com.opentext.ia.sdk.support.http.HttpClient) JsonFormatter(com.opentext.ia.sdk.support.http.JsonFormatter) NameValuePair(org.apache.http.NameValuePair) Collections(java.util.Collections) Header(com.opentext.ia.sdk.support.http.Header) MediaTypes(com.opentext.ia.sdk.support.http.MediaTypes) InputStream(java.io.InputStream) NameValuePair(org.apache.http.NameValuePair) URISyntaxException(java.net.URISyntaxException) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 4 with UriBuilder

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

the class WhenMakingRestCalls method shouldForwardUri.

@Test
void shouldForwardUri() {
    UriBuilder expected = mock(UriBuilder.class);
    when(httpClient.uri(anyString())).thenReturn(expected);
    UriBuilder actual = restClient.uri(randomString());
    assertSame(expected, actual, "URI Builder");
}
Also used : UriBuilder(com.opentext.ia.sdk.support.http.UriBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

UriBuilder (com.opentext.ia.sdk.support.http.UriBuilder)4 Test (org.junit.jupiter.api.Test)3 ResponseFactory (com.opentext.ia.sdk.support.http.ResponseFactory)2 ArrayList (java.util.ArrayList)2 StringContains.containsString (org.hamcrest.core.StringContains.containsString)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 ContentResult (com.opentext.ia.sdk.client.api.ContentResult)1 ContentResultFactory (com.opentext.ia.sdk.client.impl.ContentResultFactory)1 DefaultContentResult (com.opentext.ia.sdk.client.impl.DefaultContentResult)1 ExportConfiguration (com.opentext.ia.sdk.dto.export.ExportConfiguration)1 BinaryPart (com.opentext.ia.sdk.support.http.BinaryPart)1 Header (com.opentext.ia.sdk.support.http.Header)1 HttpClient (com.opentext.ia.sdk.support.http.HttpClient)1 JsonFormatter (com.opentext.ia.sdk.support.http.JsonFormatter)1 MediaTypes (com.opentext.ia.sdk.support.http.MediaTypes)1 Part (com.opentext.ia.sdk.support.http.Part)1 Response (com.opentext.ia.sdk.support.http.Response)1 Link (com.opentext.ia.sdk.support.http.rest.Link)1 Closeable (java.io.Closeable)1 File (java.io.File)1