Search in sources :

Example 1 with ContentRetriever

use of eu.europeana.metis.network.AbstractHttpClient.ContentRetriever in project metis-framework by europeana.

the class StringHttpClientTest method createResult.

@Test
void createResult() throws URISyntaxException, IOException {
    List<Closeable> closeables = new ArrayList<>();
    HttpEntity responseEntity = new BasicHttpEntity(new ByteArrayInputStream("content".getBytes()), ContentType.TEXT_PLAIN);
    final ContentRetriever contentRetriever = ContentRetriever.forNonCloseableContent(responseEntity == null ? InputStream::nullInputStream : responseEntity::getContent, closeables::add);
    StringContent actualContent = stringHttpClient.createResult(new URI("/resource/provided"), new URI("/resource/actual"), "text/plain", 7L, contentRetriever);
    assertEquals("content", actualContent.getContent());
    assertEquals("text/plain", actualContent.getContentType());
}
Also used : BasicHttpEntity(org.apache.hc.core5.http.io.entity.BasicHttpEntity) HttpEntity(org.apache.hc.core5.http.HttpEntity) ByteArrayInputStream(java.io.ByteArrayInputStream) Closeable(java.io.Closeable) ArrayList(java.util.ArrayList) StringContent(eu.europeana.metis.network.StringHttpClient.StringContent) BasicHttpEntity(org.apache.hc.core5.http.io.entity.BasicHttpEntity) URI(java.net.URI) ContentRetriever(eu.europeana.metis.network.AbstractHttpClient.ContentRetriever) Test(org.junit.jupiter.api.Test)

Example 2 with ContentRetriever

use of eu.europeana.metis.network.AbstractHttpClient.ContentRetriever in project metis-framework by europeana.

the class StringHttpClientTest method createResultWithException.

@Disabled("TODO: MET-4250 Handle MockMaker in Jenkins")
@Test
void createResultWithException() throws IOException {
    final ContentRetriever contentRetriever = mock(ContentRetriever.class);
    when(contentRetriever.getContent()).thenThrow(IOException.class);
    assertThrows(IOException.class, () -> {
        stringHttpClient.createResult(new URI("/resource/provided"), new URI("/resource/actual"), "text/plain", 7L, contentRetriever);
    });
}
Also used : URI(java.net.URI) ContentRetriever(eu.europeana.metis.network.AbstractHttpClient.ContentRetriever) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Aggregations

ContentRetriever (eu.europeana.metis.network.AbstractHttpClient.ContentRetriever)2 URI (java.net.URI)2 Test (org.junit.jupiter.api.Test)2 StringContent (eu.europeana.metis.network.StringHttpClient.StringContent)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Closeable (java.io.Closeable)1 ArrayList (java.util.ArrayList)1 HttpEntity (org.apache.hc.core5.http.HttpEntity)1 BasicHttpEntity (org.apache.hc.core5.http.io.entity.BasicHttpEntity)1 Disabled (org.junit.jupiter.api.Disabled)1