use of com.azure.core.http.HttpHeaders in project vividus by vividus-framework.
the class ResponseCapturingHttpPipelinePolicyTests method shouldCaptureResponseData.
@SuppressWarnings("unchecked")
@Test
void shouldCaptureResponseData() throws MalformedURLException {
HttpResponse response = mock(HttpResponse.class);
Mono<HttpResponse> mono = mock(Mono.class);
Mono<String> body = Mono.just(BODY);
when(response.getBodyAsString()).thenReturn(body);
HttpHeaders headers = mock(HttpHeaders.class);
when(response.getHeaders()).thenReturn(headers);
Map<String, String> headersMap = Map.of("header", "value");
when(headers.toMap()).thenReturn(headersMap);
HttpRequest request = mock(HttpRequest.class);
URL url = URI.create(URL).toURL();
when(request.getUrl()).thenReturn(url).thenReturn(URI.create("https://google.com").toURL());
when(response.getRequest()).thenReturn(request);
when(response.getStatusCode()).thenReturn(SC_OK);
when(mono.doOnSuccess(argThat(c -> {
c.accept(response);
return true;
}))).thenReturn(mono);
when(next.process()).thenReturn(mono);
underTest.process(context, next);
underTest.process(context, next);
Map<String, Object> captured = underTest.getResponses();
Assertions.assertAll(() -> assertEquals(headersMap, captured.get("headers")), () -> assertEquals(body, captured.get(BODY)), () -> assertEquals(SC_OK, captured.get("status-code")), () -> assertEquals(URL, captured.get("url")));
}
use of com.azure.core.http.HttpHeaders in project camel-quarkus by apache.
the class VertxHttpClientTests method validateHeadersReturnAsIs.
@Test
public void validateHeadersReturnAsIs() {
HttpClient client = new VertxHttpClientProvider().createInstance();
final String singleValueHeaderName = "singleValue";
final String singleValueHeaderValue = "value";
final String multiValueHeaderName = "Multi-value";
final List<String> multiValueHeaderValue = Arrays.asList("value1", "value2");
HttpHeaders headers = new HttpHeaders().set(singleValueHeaderName, singleValueHeaderValue).set(multiValueHeaderName, multiValueHeaderValue);
StepVerifier.create(client.send(new HttpRequest(HttpMethod.GET, url(server, RETURN_HEADERS_AS_IS_PATH), headers, Flux.empty()))).assertNext(response -> {
Assertions.assertEquals(200, response.getStatusCode());
HttpHeaders responseHeaders = response.getHeaders();
HttpHeader singleValueHeader = responseHeaders.get(singleValueHeaderName);
assertEquals(singleValueHeaderName, singleValueHeader.getName());
assertEquals(singleValueHeaderValue, singleValueHeader.getValue());
HttpHeader multiValueHeader = responseHeaders.get("Multi-value");
assertEquals(multiValueHeaderName, multiValueHeader.getName());
}).expectComplete().verify(Duration.ofSeconds(10));
}
use of com.azure.core.http.HttpHeaders in project camel-quarkus by apache.
the class VertxHttpResponse method fromVertxHttpHeaders.
private HttpHeaders fromVertxHttpHeaders(MultiMap headers) {
HttpHeaders azureHeaders = new HttpHeaders();
headers.names().forEach(name -> azureHeaders.set(name, headers.getAll(name)));
return azureHeaders;
}
use of com.azure.core.http.HttpHeaders in project bulk-scan-processor by hmcts.
the class BlobManagerTest method tryMoveFileToRejectedContainer_retry_delete_when_lease_lost.
@Test
void tryMoveFileToRejectedContainer_retry_delete_when_lease_lost() {
// given
given(inputContainerClient.getBlobClient(INPUT_FILE_NAME)).willReturn(inputBlobClient);
given(rejectedContainerClient.getBlobClient(INPUT_FILE_NAME)).willReturn(rejectedBlobClient);
given(blobServiceClient.getBlobContainerClient(INPUT_CONTAINER_NAME)).willReturn(inputContainerClient);
given(blobServiceClient.getBlobContainerClient(REJECTED_CONTAINER_NAME)).willReturn(rejectedContainerClient);
given(rejectedBlobClient.exists()).willReturn(Boolean.FALSE);
mockBeginCopy("http://retry", UUID.randomUUID().toString());
HttpResponse response = mock(HttpResponse.class);
given(response.getStatusCode()).willReturn(412);
HttpHeaders httpHeaders = mock(HttpHeaders.class);
given(response.getHeaders()).willReturn(httpHeaders);
given(httpHeaders.getValue(ERROR_CODE)).willReturn(BlobErrorCode.LEASE_LOST.toString());
willThrow(new BlobStorageException(BlobErrorCode.LEASE_LOST.toString(), response, null)).willReturn(mock(Response.class)).given(inputBlobClient).deleteWithResponse(any(), any(), any(), any());
// when
blobManager.tryMoveFileToRejectedContainer(INPUT_FILE_NAME, INPUT_CONTAINER_NAME);
// then
verify(rejectedBlobClient).beginCopy(any(), any(), any(), any(), any(), any(), any());
verify(inputBlobClient, times(2)).deleteWithResponse(any(), any(), any(), any());
}
use of com.azure.core.http.HttpHeaders in project ApplicationInsights-Java by microsoft.
the class QuickPulseDataFetcherTests method endpointChangesWithRedirectHeaderAndGetNewPingInterval.
@Test
void endpointChangesWithRedirectHeaderAndGetNewPingInterval() {
Map<String, String> headers = new HashMap<>();
headers.put("x-ms-qps-service-polling-interval-hint", "1000");
headers.put("x-ms-qps-service-endpoint-redirect", "https://new.endpoint.com");
headers.put("x-ms-qps-subscribed", "true");
HttpHeaders httpHeaders = new HttpHeaders(headers);
TelemetryClient telemetryClient = TelemetryClient.createForTest();
telemetryClient.setInstrumentationKey("fake-key");
HttpPipeline httpPipeline = new HttpPipelineBuilder().httpClient(request -> Mono.just(new MockHttpResponse(request, 200, httpHeaders))).build();
QuickPulsePingSender quickPulsePingSender = new QuickPulsePingSender(httpPipeline, telemetryClient, "machine1", "instance1", "qpid123");
QuickPulseHeaderInfo quickPulseHeaderInfo = quickPulsePingSender.ping(null);
assertThat(QuickPulseStatus.QP_IS_ON).isEqualTo(quickPulseHeaderInfo.getQuickPulseStatus());
assertThat(1000).isEqualTo(quickPulseHeaderInfo.getQpsServicePollingInterval());
assertThat("https://new.endpoint.com").isEqualTo(quickPulseHeaderInfo.getQpsServiceEndpointRedirect());
}
Aggregations