use of com.azure.core.http.HttpMethod in project lowkey-vault by nagyesta.
the class ApacheHttpClientTest method testConstructorShouldConvertValuesWhenCalled.
@ParameterizedTest
@MethodSource("validProvider")
void testConstructorShouldConvertValuesWhenCalled(final String body, final Function<URI, URI> hostOverrideFunction, final String expectedHost) throws IOException {
// given
final HttpMethod method = HttpMethod.POST;
final URL url = new URL("https://localhost");
final HttpHeaders headers = new HttpHeaders(Map.of(HEADER_1, HEADER_VALUE_1, HEADER_2, HEADER_VALUE_2));
final HttpClient client = mock(HttpClient.class);
final HttpRequest azureRequest;
if (body != null) {
azureRequest = new HttpRequest(method, url, headers, Flux.defer(() -> Flux.just(ByteBuffer.wrap(body.getBytes(StandardCharsets.UTF_8)))));
} else {
azureRequest = new HttpRequest(method, url, headers, null);
}
final org.apache.http.HttpResponse response = ApacheHttpResponseTest.responseMock();
final ArgumentCaptor<HttpUriRequest> captor = ArgumentCaptor.forClass(HttpUriRequest.class);
when(client.execute(captor.capture())).thenReturn(response);
final ApacheHttpClient underTest = new ApacheHttpClient(client, hostOverrideFunction);
// when
final HttpResponse actual = underTest.send(azureRequest).block();
// then
Assertions.assertNotNull(actual);
ApacheHttpResponseTest.verifyResponse((ApacheHttpResponse) actual);
Assertions.assertEquals(expectedHost, captor.getValue().getURI().getHost());
}
use of com.azure.core.http.HttpMethod in project lowkey-vault by nagyesta.
the class ApacheHttpRequestTest method testConstructorShouldConvertValuesWhenCalled.
@Test
void testConstructorShouldConvertValuesWhenCalled() throws MalformedURLException, URISyntaxException {
// given
final HttpMethod method = HttpMethod.POST;
final URL url = new URL("https://localhost");
final HttpHeaders headers = new HttpHeaders(Map.of(HEADER_1, HEADER_VALUE_1, HEADER_2, HEADER_VALUE_2));
// when
final ApacheHttpRequest actual = new ApacheHttpRequest(method, url, headers, Function.identity());
// then
Assertions.assertEquals(method.toString(), actual.getMethod());
Assertions.assertEquals(url.toURI(), actual.getURI());
Assertions.assertEquals(HEADER_VALUE_1, actual.getHeaders(HEADER_1)[0].getValue());
Assertions.assertEquals(HEADER_VALUE_2, actual.getHeaders(HEADER_2)[0].getValue());
}
use of com.azure.core.http.HttpMethod in project camel-quarkus by apache.
the class VertxHttpClient method toVertxHttpRequest.
private Mono<VertxHttpRequest> toVertxHttpRequest(HttpRequest request) {
return Mono.from(convertBodyToBuffer(request)).map(buffer -> {
HttpMethod httpMethod = request.getHttpMethod();
io.vertx.core.http.HttpMethod requestMethod = io.vertx.core.http.HttpMethod.valueOf(httpMethod.name());
URL url = request.getUrl();
if (url.getPath().isEmpty()) {
try {
// Azure API documentation states:
//
// The URI must always include the forward slash (/) to separate the host name
// from the path and query portions of the URI.
//
url = new URL(url.getProtocol(), url.getHost(), url.getPort(), "/" + url.getFile());
} catch (MalformedURLException e) {
throw new IllegalStateException(e);
}
}
io.vertx.ext.web.client.HttpRequest<Buffer> delegate = client.requestAbs(requestMethod, url.toString());
if (request.getHeaders() != null) {
request.getHeaders().stream().forEach(httpHeader -> delegate.putHeader(httpHeader.getName(), httpHeader.getValuesList()));
}
return new VertxHttpRequest(delegate, buffer);
});
}
Aggregations