Search in sources :

Example 1 with HttpResponse

use of org.apache.hc.core5.http.HttpResponse in project pact-jvm by DiUS.

the class BeforeEachTest method testPactExecutedAfterBeforeEach.

@Test
@PactTestFor(pactMethod = "pactExecutedAfterBeforeEach")
void testPactExecutedAfterBeforeEach(MockServer mockServer) throws IOException {
    ClassicHttpResponse httpResponse = (ClassicHttpResponse) Request.get(mockServer.getUrl() + "/").execute().returnResponse();
    assertThat(IOUtils.toString(httpResponse.getEntity().getContent()), is(equalTo(EXPECTED_RESPONSE)));
}
Also used : ClassicHttpResponse(org.apache.hc.core5.http.ClassicHttpResponse) Test(org.junit.jupiter.api.Test)

Example 2 with HttpResponse

use of org.apache.hc.core5.http.HttpResponse in project pact-jvm by DiUS.

the class UrlEncocdedFormPostTest method testFormPost.

@Test
void testFormPost(MockServer mockServer) throws IOException {
    HttpResponse httpResponse = Request.post(mockServer.getUrl() + "/form").bodyForm(new BasicNameValuePair("id", UUID.randomUUID().toString()), new BasicNameValuePair("value", "3"), new BasicNameValuePair("value", "1"), new BasicNameValuePair("value", "2")).execute().returnResponse();
    assertThat(httpResponse.getCode(), is(equalTo(200)));
}
Also used : BasicNameValuePair(org.apache.hc.core5.http.message.BasicNameValuePair) HttpResponse(org.apache.hc.core5.http.HttpResponse) Test(org.junit.jupiter.api.Test)

Example 3 with HttpResponse

use of org.apache.hc.core5.http.HttpResponse in project pact-jvm by DiUS.

the class V4PactBuilderTest method runHttpTest.

@Test
@PactTestFor(pactMethod = "httpInteraction")
void runHttpTest(MockServer mockServer) throws IOException {
    ClassicHttpResponse httpResponse = (ClassicHttpResponse) Request.get(mockServer.getUrl()).execute().returnResponse();
    assertThat(httpResponse.getCode(), is(200));
    assertThat(new String(httpResponse.getEntity().getContent().readAllBytes()), is(equalTo("{\"responsetest\": true, \"version\": \"v3\"}")));
}
Also used : ClassicHttpResponse(org.apache.hc.core5.http.ClassicHttpResponse) Test(org.junit.jupiter.api.Test)

Example 4 with HttpResponse

use of org.apache.hc.core5.http.HttpResponse in project pact-jvm by DiUS.

the class NullValuesTest method testArticles.

@Test
void testArticles(MockServer mockServer) throws IOException {
    ClassicHttpResponse httpResponse = (ClassicHttpResponse) Request.get(mockServer.getUrl()).execute().returnResponse();
    assertThat(httpResponse.getCode(), is(equalTo(200)));
    assertThat(IOUtils.toString(httpResponse.getEntity().getContent()), is(equalTo("{\"transaction\":{\"amount\":{\"amount\":null,\"currency\":null,\"salesAmount\":null,\"surchargeAmount\":null},\"description\":null}}")));
}
Also used : ClassicHttpResponse(org.apache.hc.core5.http.ClassicHttpResponse) Test(org.junit.jupiter.api.Test)

Example 5 with HttpResponse

use of org.apache.hc.core5.http.HttpResponse in project feign by OpenFeign.

the class AsyncApacheHttp5Client method toFeignResponse.

Response toFeignResponse(SimpleHttpResponse httpResponse, Request request) {
    final int statusCode = httpResponse.getCode();
    final String reason = httpResponse.getReasonPhrase();
    final Map<String, Collection<String>> headers = new HashMap<String, Collection<String>>();
    for (final Header header : httpResponse.getHeaders()) {
        final String name = header.getName();
        final String value = header.getValue();
        Collection<String> headerValues = headers.get(name);
        if (headerValues == null) {
            headerValues = new ArrayList<String>();
            headers.put(name, headerValues);
        }
        headerValues.add(value);
    }
    return Response.builder().status(statusCode).reason(reason).headers(headers).request(request).body(httpResponse.getBodyBytes()).build();
}
Also used : Header(org.apache.hc.core5.http.Header)

Aggregations

Test (org.junit.jupiter.api.Test)8 ClassicHttpResponse (org.apache.hc.core5.http.ClassicHttpResponse)7 HttpResponse (org.apache.hc.core5.http.HttpResponse)3 Header (org.apache.hc.core5.http.Header)2 PactVerifications (au.com.dius.pact.consumer.junit.PactVerifications)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 SimpleHttpRequest (org.apache.hc.client5.http.async.methods.SimpleHttpRequest)1 SimpleHttpResponse (org.apache.hc.client5.http.async.methods.SimpleHttpResponse)1 BasicCookieStore (org.apache.hc.client5.http.cookie.BasicCookieStore)1 Cookie (org.apache.hc.client5.http.cookie.Cookie)1 HttpAsyncClientBuilder (org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder)1 PoolingAsyncClientConnectionManager (org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager)1 HttpClientContext (org.apache.hc.client5.http.protocol.HttpClientContext)1 RedirectStrategy (org.apache.hc.client5.http.protocol.RedirectStrategy)1 DefaultClientTlsStrategy (org.apache.hc.client5.http.ssl.DefaultClientTlsStrategy)1 FutureCallback (org.apache.hc.core5.concurrent.FutureCallback)1 HttpRequest (org.apache.hc.core5.http.HttpRequest)1 BasicNameValuePair (org.apache.hc.core5.http.message.BasicNameValuePair)1 TlsStrategy (org.apache.hc.core5.http.nio.ssl.TlsStrategy)1 HttpContext (org.apache.hc.core5.http.protocol.HttpContext)1