use of com.azure.core.http.HttpResponse 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.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 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 ApplicationInsights-Java by microsoft.
the class QuickPulseDataSender method run.
@Override
public void run() {
while (true) {
HttpRequest post;
try {
post = sendQueue.take();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
}
if (quickPulseHeaderInfo.getQuickPulseStatus() != QuickPulseStatus.QP_IS_ON) {
continue;
}
long sendTime = System.nanoTime();
try (HttpResponse response = httpPipeline.send(post).block()) {
if (response == null) {
// this shouldn't happen, the mono should complete with a response or a failure
throw new AssertionError("http response mono returned empty");
}
// response body is not consumed below
LazyHttpClient.consumeResponseBody(response);
if (networkHelper.isSuccess(response)) {
QuickPulseHeaderInfo quickPulseHeaderInfo = networkHelper.getQuickPulseHeaderInfo(response);
switch(quickPulseHeaderInfo.getQuickPulseStatus()) {
case QP_IS_OFF:
case QP_IS_ON:
lastValidTransmission = sendTime;
this.quickPulseHeaderInfo = quickPulseHeaderInfo;
break;
case ERROR:
onPostError(sendTime);
break;
}
}
}
}
}
use of com.azure.core.http.HttpResponse in project lowkey-vault by nagyesta.
the class ResponseEntityTest method testIsSuccessfulShouldReturnTrueWhenResponseCodeIs2xx.
@ParameterizedTest
@MethodSource("responseCodeProvider")
void testIsSuccessfulShouldReturnTrueWhenResponseCodeIs2xx(final int code, final boolean expected) {
// given
final HttpResponse response = mock(HttpResponse.class);
when(response.getStatusCode()).thenReturn(code);
when(response.getBodyAsString(eq(StandardCharsets.UTF_8))).thenReturn(Mono.empty());
final ResponseEntity underTest = new ResponseEntity(response, mock(ObjectReader.class));
// when
final boolean actual = underTest.isSuccessful();
// then
Assertions.assertEquals(expected, actual);
verify(response).getStatusCode();
verify(response).getBodyAsString(eq(StandardCharsets.UTF_8));
}
Aggregations