use of com.azure.core.http.HttpResponse in project lowkey-vault by nagyesta.
the class ResponseEntityTest method testGetResponseObjectShouldMapResponseBodyUsingObjectReaderWhenCalledWithList.
@Test
void testGetResponseObjectShouldMapResponseBodyUsingObjectReaderWhenCalledWithList() {
// given
final VaultModel vaultModel = new VaultModel(URI.create(HTTPS_DEFAULT_LOCALHOST_8443), null, null, null, null);
final List<VaultModel> expected = Collections.singletonList(vaultModel);
final HttpResponse response = mock(HttpResponse.class);
when(response.getStatusCode()).thenReturn(HttpStatus.SC_OK);
when(response.getBodyAsString(eq(StandardCharsets.UTF_8))).thenReturn(Mono.just(VAULT_MODEL_LIST));
final ObjectReader reader = new ObjectMapper().reader();
final ResponseEntity underTest = new ResponseEntity(response, reader);
// when
final List<VaultModel> actual = underTest.getResponseObject(VAULT_MODEL_LIST_TYPE_REF);
// then
Assertions.assertEquals(expected, actual);
verify(response).getStatusCode();
verify(response).getBodyAsString(eq(StandardCharsets.UTF_8));
}
use of com.azure.core.http.HttpResponse 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.HttpResponse in project camel-quarkus by apache.
the class VertxHttpClientTests method testFlowableBackpressure.
@Test
public void testFlowableBackpressure() {
HttpResponse response = getResponse("/long");
StepVerifierOptions stepVerifierOptions = StepVerifierOptions.create();
stepVerifierOptions.initialRequest(0);
StepVerifier.create(response.getBody(), stepVerifierOptions).expectNextCount(0).thenRequest(1).expectNextCount(1).thenRequest(3).expectNextCount(3).thenRequest(Long.MAX_VALUE).thenConsumeWhile(ByteBuffer::hasRemaining).verifyComplete();
}
use of com.azure.core.http.HttpResponse in project terra-cloud-resource-lib by DataBiosphere.
the class AzureResponseLogger method logResponse.
@Override
public Mono<HttpResponse> logResponse(ClientLogger clientLogger, HttpResponseLoggingContext loggingOptions) {
final HttpResponse response = loggingOptions.getHttpResponse();
final HttpRequest request = response.getRequest();
// Always add request method and request URL
JsonObject requestDataJson = new JsonObject();
requestDataJson.addProperty("requestMethod", request.getHttpMethod().toString());
requestDataJson.addProperty("requestUrl", request.getUrl().toString());
// Optionally add rich request data if provided in the logging context
Optional<ResourceManagerRequestData> requestData = Optional.ofNullable(loggingOptions.getContext()).flatMap(c -> c.getData(CLOUD_RESOURCE_REQUEST_DATA_KEY)).map(o -> (ResourceManagerRequestData) o);
requestData.ifPresent(d -> requestDataJson.add("requestBody", d.serialize()));
// verbose.
if (logger.isDebugEnabled()) {
logBody(request.getHeaders(), request.getBody(), s -> requestDataJson.addProperty("rawRequestBody", s));
logBody(response.getHeaders(), response.buffer().getBody(), s -> requestDataJson.addProperty("rawResponseBody", s));
}
// Build OperationData object.
OperationData operationData = OperationData.builder().setDuration(Optional.ofNullable(loggingOptions.getResponseDuration()).orElse(Duration.ZERO)).setTryCount(OptionalInt.of(loggingOptions.getTryCount())).setExecutionException(Optional.empty()).setHttpStatusCode(OptionalInt.of(response.getStatusCode())).setCloudOperation(requestData.map(ResourceManagerRequestData::cloudOperation).orElse(ResourceManagerOperation.AZURE_RESOURCE_MANAGER_UNKNOWN_OPERATION)).setRequestData(requestDataJson).build();
// Invoke OperationAnnotator to record the operation.
operationAnnotator.recordOperation(operationData);
return Mono.justOrEmpty(response);
}
use of com.azure.core.http.HttpResponse in project camel-quarkus by apache.
the class VertxHttpClientTests method testFlowableWhenServerReturnsBodyAndNoErrorsWhenHttp500Returned.
@Test
public void testFlowableWhenServerReturnsBodyAndNoErrorsWhenHttp500Returned() {
HttpResponse response = getResponse("/error");
assertEquals(500, response.getStatusCode());
StepVerifier.create(response.getBodyAsString()).expectNext("error").expectComplete().verify(Duration.ofSeconds(20));
}
Aggregations