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
}
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
}
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));
}
Aggregations