summaryrefslogtreecommitdiffstats
path: root/certServiceClient/src/test
diff options
context:
space:
mode:
authorTomasz Wrobel <tomasz.wrobel@nokia.com>2020-03-02 13:20:50 +0100
committerTomasz Wrobel <tomasz.wrobel@nokia.com>2020-03-03 13:36:34 +0100
commitb6b482e71132f0fdf478326e26756aa119749858 (patch)
tree6f83012617b14408b8005233f1f1c51ea2016fca /certServiceClient/src/test
parentbe552bb854e00ad79d0854304226829d0f969fb6 (diff)
Add tests to HttpClient
Issue-ID: AAF-996 Signed-off-by: Tomasz Wrobel <tomasz.wrobel@nokia.com> Change-Id: I2d8883552421d055622d5d9ca55b437647c36da4
Diffstat (limited to 'certServiceClient/src/test')
-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);