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);
}
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)));
}
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\"}")));
}
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();
}
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}}")));
}
Aggregations