Search in sources :

Example 1 with HttpHeaders

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")));
}
Also used : HttpRequest(com.azure.core.http.HttpRequest) HttpResponse(com.azure.core.http.HttpResponse) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) MalformedURLException(java.net.MalformedURLException) URL(java.net.URL) Mock(org.mockito.Mock) HttpPipelineNextPolicy(com.azure.core.http.HttpPipelineNextPolicy) Mono(reactor.core.publisher.Mono) Mockito.when(org.mockito.Mockito.when) HttpHeaders(com.azure.core.http.HttpHeaders) Test(org.junit.jupiter.api.Test) HttpRequest(com.azure.core.http.HttpRequest) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) HttpPipelineCallContext(com.azure.core.http.HttpPipelineCallContext) Assertions(org.junit.jupiter.api.Assertions) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) URI(java.net.URI) Mockito.mock(org.mockito.Mockito.mock) HttpHeaders(com.azure.core.http.HttpHeaders) HttpResponse(com.azure.core.http.HttpResponse) URL(java.net.URL) Test(org.junit.jupiter.api.Test)

Example 2 with HttpHeaders

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));
}
Also used : HttpRequest(com.azure.core.http.HttpRequest) HttpHeaders(com.azure.core.http.HttpHeaders) HttpHeader(com.azure.core.http.HttpHeader) HttpClient(com.azure.core.http.HttpClient) QuarkusUnitTest(io.quarkus.test.QuarkusUnitTest) Test(org.junit.jupiter.api.Test)

Example 3 with HttpHeaders

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;
}
Also used : HttpHeaders(com.azure.core.http.HttpHeaders)

Example 4 with HttpHeaders

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());
}
Also used : PollResponse(com.azure.core.util.polling.PollResponse) HttpResponse(com.azure.core.http.HttpResponse) Response(com.azure.core.http.rest.Response) HttpHeaders(com.azure.core.http.HttpHeaders) HttpResponse(com.azure.core.http.HttpResponse) BlobStorageException(com.azure.storage.blob.models.BlobStorageException) Test(org.junit.jupiter.api.Test)

Example 5 with HttpHeaders

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());
}
Also used : Test(org.junit.jupiter.api.Test) TelemetryClient(com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HttpPipeline(com.azure.core.http.HttpPipeline) URISyntaxException(java.net.URISyntaxException) Map(java.util.Map) MockHttpResponse(com.microsoft.applicationinsights.agent.internal.MockHttpResponse) HashMap(java.util.HashMap) Mono(reactor.core.publisher.Mono) HttpHeaders(com.azure.core.http.HttpHeaders) URI(java.net.URI) HttpPipelineBuilder(com.azure.core.http.HttpPipelineBuilder) HttpHeaders(com.azure.core.http.HttpHeaders) HashMap(java.util.HashMap) HttpPipeline(com.azure.core.http.HttpPipeline) HttpPipelineBuilder(com.azure.core.http.HttpPipelineBuilder) TelemetryClient(com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient) MockHttpResponse(com.microsoft.applicationinsights.agent.internal.MockHttpResponse) Test(org.junit.jupiter.api.Test)

Aggregations

HttpHeaders (com.azure.core.http.HttpHeaders)12 Test (org.junit.jupiter.api.Test)6 HttpRequest (com.azure.core.http.HttpRequest)4 HttpResponse (com.azure.core.http.HttpResponse)4 Mono (reactor.core.publisher.Mono)4 HttpPipeline (com.azure.core.http.HttpPipeline)3 HttpPipelineBuilder (com.azure.core.http.HttpPipelineBuilder)3 URI (java.net.URI)3 URL (java.net.URL)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 HttpHeader (com.azure.core.http.HttpHeader)2 HttpMethod (com.azure.core.http.HttpMethod)2 MockHttpResponse (com.microsoft.applicationinsights.agent.internal.MockHttpResponse)2 TelemetryClient (com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient)2 URISyntaxException (java.net.URISyntaxException)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 CLOUD_RESOURCE_REQUEST_DATA_KEY (bio.terra.cloudres.azure.resourcemanager.common.Defaults.CLOUD_RESOURCE_REQUEST_DATA_KEY)1 ClientConfig (bio.terra.cloudres.common.ClientConfig)1 OperationAnnotator (bio.terra.cloudres.common.OperationAnnotator)1