Search in sources :

Example 16 with HttpResponse

use of com.azure.core.http.HttpResponse in project lowkey-vault by nagyesta.

the class ResponseEntityTest method testGetResponseObjectShouldThrowExceptionWhenJsonProcessingExceptionIsThrownByReaderWhileMappingToSingleObject.

@Test
void testGetResponseObjectShouldThrowExceptionWhenJsonProcessingExceptionIsThrownByReaderWhileMappingToSingleObject() throws JsonProcessingException {
    // given
    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));
    final ObjectReader reader = mock(ObjectReader.class);
    when(reader.forType(eq(VaultModel.class))).thenReturn(reader);
    when(reader.readValue(anyString())).thenThrow(JsonProcessingException.class);
    final ResponseEntity underTest = new ResponseEntity(response, reader);
    // when
    Assertions.assertThrows(LowkeyVaultException.class, () -> underTest.getResponseObject(VaultModel.class));
// then + exception
}
Also used : VaultModel(com.github.nagyesta.lowkeyvault.http.management.VaultModel) HttpResponse(com.azure.core.http.HttpResponse) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 17 with HttpResponse

use of com.azure.core.http.HttpResponse in project lowkey-vault by nagyesta.

the class ResponseEntityTest method testGetResponseObjectShouldThrowExceptionWhenJsonProcessingExceptionIsThrownByReaderWhileMappingToList.

@Test
void testGetResponseObjectShouldThrowExceptionWhenJsonProcessingExceptionIsThrownByReaderWhileMappingToList() throws JsonProcessingException {
    // given
    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 = mock(ObjectReader.class);
    when(reader.forType(eq(VAULT_MODEL_LIST_TYPE_REF))).thenReturn(reader);
    when(reader.readValue(anyString())).thenThrow(JsonProcessingException.class);
    final ResponseEntity underTest = new ResponseEntity(response, reader);
    // when
    Assertions.assertThrows(LowkeyVaultException.class, () -> underTest.getResponseObject(VAULT_MODEL_LIST_TYPE_REF));
// then + exception
}
Also used : HttpResponse(com.azure.core.http.HttpResponse) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 18 with HttpResponse

use of com.azure.core.http.HttpResponse in project lowkey-vault by nagyesta.

the class ResponseEntityTest method testGetResponseCodeShouldReturnTheCodeUnchangedWhenCalled.

@ParameterizedTest
@MethodSource("responseCodeProvider")
void testGetResponseCodeShouldReturnTheCodeUnchangedWhenCalled(final int code) {
    // 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 int actual = underTest.getResponseCode();
    // then
    Assertions.assertEquals(code, actual);
    verify(response).getStatusCode();
    verify(response).getBodyAsString(eq(StandardCharsets.UTF_8));
}
Also used : HttpResponse(com.azure.core.http.HttpResponse) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

HttpResponse (com.azure.core.http.HttpResponse)18 Test (org.junit.jupiter.api.Test)10 HttpRequest (com.azure.core.http.HttpRequest)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)6 HttpHeaders (com.azure.core.http.HttpHeaders)4 VaultModel (com.github.nagyesta.lowkeyvault.http.management.VaultModel)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 QuarkusUnitTest (io.quarkus.test.QuarkusUnitTest)2 IOException (java.io.IOException)2 URL (java.net.URL)2 Mono (reactor.core.publisher.Mono)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 OperationData (bio.terra.cloudres.common.OperationData)1 ContentType (com.azure.core.http.ContentType)1 HttpMethod (com.azure.core.http.HttpMethod)1 HttpPipelineCallContext (com.azure.core.http.HttpPipelineCallContext)1