use of com.github.mjeanroy.junit.servers.client.HttpResponse in project springmvc-mustache by mjeanroy.
the class IndexControllerTest method it_should_render_handlebars_template_using_model_and_mustache_view.
@Test
void it_should_render_handlebars_template_using_model_and_mustache_view(HttpClient client) {
HttpResponse response = client.prepareGet("/jane").execute();
assertThat(response.status()).isEqualTo(200);
assertThat(response.body()).contains("Hello, my name is Jane Doe");
}
use of com.github.mjeanroy.junit.servers.client.HttpResponse in project junit-servers by mjeanroy.
the class BaseHttpClientTest method testPostWithJsonBodyString.
@Test
void testPostWithJsonBodyString() {
final String endpoint = ENDPOINT;
final int status = 201;
final String rawBody = "{\"id\": 1, \"name\": \"Jane Doe\"}";
final HttpRequestBody body = jsonBody(rawBody);
final Collection<Pair> expectedHeaders = singleton(pair(CONTENT_TYPE, APPLICATION_JSON));
stubPostRequest(endpoint, status, expectedHeaders, rawBody);
final HttpResponse rsp = createDefaultClient().preparePost(endpoint).acceptJson().asXmlHttpRequest().setBody(body).execute();
assertRequest(endpoint, HttpMethod.POST);
assertThat(rsp.status()).isEqualTo(status);
assertThat(rsp.body()).isEqualTo(rawBody);
assertThat(rsp.getContentType().getFirstValue()).isEqualTo(APPLICATION_JSON);
assertThat(rsp.getContentType().getLastValue()).isEqualTo(APPLICATION_JSON);
}
use of com.github.mjeanroy.junit.servers.client.HttpResponse in project junit-servers by mjeanroy.
the class AsyncHttpResponseFactoryTest method it_should_create_http_response.
@Test
void it_should_create_http_response() {
Response delegate = new AsyncHttpResponseBuilder().build();
long duration = 1000L;
HttpResponse response = AsyncHttpResponseFactory.of(delegate, duration);
assertThat(response).isNotNull().isExactlyInstanceOf(AsyncHttpResponse.class);
assertThat(response.getRequestDuration()).isEqualTo(duration);
}
use of com.github.mjeanroy.junit.servers.client.HttpResponse in project junit-servers by mjeanroy.
the class BaseHttpClientTest method testRequestExecuteAs.
private void testRequestExecuteAs(String contentType, MapperFunction<HttpRequest, HttpResponse> func) {
// GIVEN
final String endpoint = ENDPOINT;
final int rspStatus = 200;
final Collection<Pair> headers = singleton(pair(CONTENT_TYPE, APPLICATION_JSON));
final String rspBody = "[]";
stubGetRequest(endpoint, rspStatus, headers, rspBody);
// WHEN
final HttpRequest rq = createDefaultClient().prepareGet(ENDPOINT);
final HttpResponse rsp = func.apply(rq);
// THEN
assertThat(rsp).isNotNull();
assertThat(rsp.status()).isEqualTo(rspStatus);
assertThat(rsp.body()).isEqualTo(rspBody);
assertRequestWithHeader(endpoint, HttpMethod.GET, CONTENT_TYPE, contentType);
}
use of com.github.mjeanroy.junit.servers.client.HttpResponse in project junit-servers by mjeanroy.
the class BaseHttpClientTest method testPostWithoutBodyElement.
@Test
void testPostWithoutBodyElement() {
final String endpoint = ENDPOINT;
final int status = 201;
final Collection<Pair> headers = singleton(pair(CONTENT_TYPE, APPLICATION_JSON));
final String body = "{\"id\": 1, \"name\": \"Jane Doe\"}";
stubPostRequest(endpoint, status, headers, body);
final HttpResponse rsp = createDefaultClient().preparePost(endpoint).acceptJson().asJson().asXmlHttpRequest().execute();
assertRequest(endpoint, HttpMethod.POST);
assertThat(rsp.status()).isEqualTo(status);
assertThat(rsp.body()).isEqualTo(body);
assertThat(rsp.getContentType().getFirstValue()).isEqualTo(APPLICATION_JSON);
assertThat(rsp.getContentType().getLastValue()).isEqualTo(APPLICATION_JSON);
}
Aggregations