Search in sources :

Example 1 with ClassicHttpResponse

use of org.apache.hc.core5.http.ClassicHttpResponse in project ksql by confluentinc.

the class KsqlVersionCheckerResponseHandlerTest method testHandle.

@Test
public void testHandle() throws IOException {
    // Given
    final ClassicHttpResponse response = mock(ClassicHttpResponse.class);
    final HttpEntity entity = mock(HttpEntity.class);
    final Logger log = mock(Logger.class);
    expect(response.getCode()).andReturn(HttpStatus.SC_OK).once();
    expect(response.getEntity()).andReturn(entity).times(2);
    final ByteArrayInputStream bais = new ByteArrayInputStream("yolo".getBytes(StandardCharsets.UTF_8));
    expect(entity.getContent()).andReturn(bais).times(2);
    expect(entity.getContentType()).andReturn("content-type").times(1);
    expect(entity.getContentLength()).andReturn(4L).times(1);
    log.warn("yolo");
    expectLastCall().once();
    replay(response, entity, log);
    final KsqlVersionCheckerResponseHandler kvcr = new KsqlVersionCheckerResponseHandler(log);
    // When
    kvcr.handle(response);
    // Then
    verify(response, entity, log);
}
Also used : ClassicHttpResponse(org.apache.hc.core5.http.ClassicHttpResponse) HttpEntity(org.apache.hc.core5.http.HttpEntity) ByteArrayInputStream(java.io.ByteArrayInputStream) Logger(org.slf4j.Logger) Test(org.junit.Test)

Example 2 with ClassicHttpResponse

use of org.apache.hc.core5.http.ClassicHttpResponse 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 3 with ClassicHttpResponse

use of org.apache.hc.core5.http.ClassicHttpResponse 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 ClassicHttpResponse

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

the class ProviderCarBookingRestClient method placeOrder.

public ClassicHttpResponse placeOrder(String baseUrl, String personId, String carId, String date) throws IOException {
    String personStr = Request.get(baseUrl + "/persons/" + personId).execute().returnContent().asString();
    ObjectMapper mapper = new ObjectMapper();
    Person person = mapper.readValue(personStr, Person.class);
    String carDetails = Request.get(baseUrl + "/cars/" + carId).execute().returnContent().asString();
    Car car = mapper.readValue(carDetails, Car.class);
    String body = "{\n" + "\"person\": " + mapper.writeValueAsString(person) + ",\n" + "\"cars\": " + mapper.writeValueAsString(car) + "\n" + "}\n";
    return (ClassicHttpResponse) Request.post(baseUrl + "/orders/").bodyString(body, ContentType.APPLICATION_JSON).execute().returnResponse();
}
Also used : ClassicHttpResponse(org.apache.hc.core5.http.ClassicHttpResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 5 with ClassicHttpResponse

use of org.apache.hc.core5.http.ClassicHttpResponse 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)

Aggregations

ClassicHttpResponse (org.apache.hc.core5.http.ClassicHttpResponse)11 Test (org.junit.jupiter.api.Test)7 HttpEntity (org.apache.hc.core5.http.HttpEntity)2 Test (org.junit.Test)2 PactVerification (au.com.dius.pact.consumer.junit.PactVerification)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Result (com.google.refine.importing.UrlRewriter.Result)1 HttpClient (com.google.refine.util.HttpClient)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 Charset (java.nio.charset.Charset)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1