aboutsummaryrefslogtreecommitdiffstats
path: root/certServiceClient/src/test/java/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'certServiceClient/src/test/java/org/onap')
-rw-r--r--certServiceClient/src/test/java/org/onap/aaf/certservice/client/httpclient/HttpClientTest.java32
1 files changed, 32 insertions, 0 deletions
diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/httpclient/HttpClientTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/httpclient/HttpClientTest.java
index f65aefdf..461b7a34 100644
--- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/httpclient/HttpClientTest.java
+++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/httpclient/HttpClientTest.java
@@ -29,6 +29,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.onap.aaf.certservice.client.api.ExitCode;
import org.onap.aaf.certservice.client.httpclient.exception.CertServiceApiResponseException;
+import org.onap.aaf.certservice.client.httpclient.exception.HttpClientException;
import org.onap.aaf.certservice.client.httpclient.model.CertServiceResponse;
import java.io.ByteArrayInputStream;
@@ -113,6 +114,37 @@ class HttpClientTest {
assertEquals(ExitCode.CERT_SERVICE_API_CONNECTION_EXCEPTION.getValue(), exception.applicationExitCode());
}
+ @Test
+ void shouldThrowHttpClientException_WhenCannotExecuteRequestToAPI() throws Exception{
+
+ //given
+ when(closeableHttpClient.execute(any(HttpGet.class))).thenThrow(IOException.class);
+
+ //when
+ HttpClientException exception =
+ assertThrows(HttpClientException.class,
+ () -> httpClient.retrieveCertServiceData(CA_NAME, CSR, ""));
+
+ //then
+ assertEquals(ExitCode.HTTP_CLIENT_EXCEPTION.getValue(), exception.applicationExitCode());
+ }
+
+ @Test
+ void shouldThrowHttpClientException_WhenCannotParseResponseToString() throws Exception{
+
+ //given
+ mockServerResponse(HTTP_OK, CORRECT_RESPONSE);
+ when(httpEntity.getContent()).thenThrow(IOException.class);
+
+ //when
+ HttpClientException exception =
+ assertThrows(HttpClientException.class,
+ () -> httpClient.retrieveCertServiceData(CA_NAME, CSR, ""));
+
+ //then
+ assertEquals(ExitCode.HTTP_CLIENT_EXCEPTION.getValue(), exception.applicationExitCode());
+ }
+
private void mockServerResponse(int serverCodeResponse, String stringResponse)
throws IOException {
when(statusLine.getStatusCode()).thenReturn(serverCodeResponse);