Search in sources :

Example 1 with ByteArrayHttpEntity

use of org.mule.runtime.http.api.domain.entity.ByteArrayHttpEntity in project mule by mulesoft.

the class HttpResponseBuilderTestCase method complexResponse.

@Test
public void complexResponse() {
    HttpResponse response = builder.entity(new ByteArrayHttpEntity("test".getBytes())).statusCode(418).reasonPhrase("I'm a teapot").addHeader(header, value).build();
    assertThat(response.getStatusCode(), is(418));
    assertThat(response.getReasonPhrase(), is("I'm a teapot"));
    assertThat(response.getEntity(), is(instanceOf(ByteArrayHttpEntity.class)));
    assertThat(response.getHeaderNames(), hasItems(equalToIgnoringCase(header)));
    assertThat(response.getHeaderValuesIgnoreCase(header), hasItems(value));
}
Also used : HttpResponse(org.mule.runtime.http.api.domain.message.response.HttpResponse) ByteArrayHttpEntity(org.mule.runtime.http.api.domain.entity.ByteArrayHttpEntity) Test(org.junit.Test)

Example 2 with ByteArrayHttpEntity

use of org.mule.runtime.http.api.domain.entity.ByteArrayHttpEntity in project mule by mulesoft.

the class HttpRequestBuilderTestCase method complexResponse.

@Test
public void complexResponse() {
    MultiMap<String, String> paramMap = new MultiMap<>();
    paramMap.put(name, value);
    HttpRequest request = builder.entity(new ByteArrayHttpEntity("test".getBytes())).uri(URI_VALUE).method(POST).queryParams(paramMap).headers(paramMap).addHeader(name.toUpperCase(), value.toUpperCase()).build();
    assertThat(request.getUri(), is(URI.create(URI_VALUE)));
    assertThat(request.getMethod(), is(POST.name()));
    assertThat(request.getEntity(), is(instanceOf(ByteArrayHttpEntity.class)));
    assertThat(request.getHeaderNames(), hasItems(name));
    assertThat(request.getHeaderValues(name), hasItems(value, value.toUpperCase()));
    MultiMap<String, String> requestQueryParams = request.getQueryParams();
    assertThat(requestQueryParams.keySet(), hasItems(name));
    assertThat(requestQueryParams.getAll(name), hasItems(value));
}
Also used : HttpRequest(org.mule.runtime.http.api.domain.message.request.HttpRequest) MultiMap(org.mule.runtime.api.util.MultiMap) UriCache.getUriFromString(org.mule.runtime.http.api.utils.UriCache.getUriFromString) Matchers.containsString(org.hamcrest.Matchers.containsString) ByteArrayHttpEntity(org.mule.runtime.http.api.domain.entity.ByteArrayHttpEntity) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 ByteArrayHttpEntity (org.mule.runtime.http.api.domain.entity.ByteArrayHttpEntity)2 Matchers.containsString (org.hamcrest.Matchers.containsString)1 MultiMap (org.mule.runtime.api.util.MultiMap)1 HttpRequest (org.mule.runtime.http.api.domain.message.request.HttpRequest)1 HttpResponse (org.mule.runtime.http.api.domain.message.response.HttpResponse)1 UriCache.getUriFromString (org.mule.runtime.http.api.utils.UriCache.getUriFromString)1