diff options
author | Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com> | 2021-01-26 07:43:22 +0100 |
---|---|---|
committer | Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com> | 2021-01-28 10:16:25 +0100 |
commit | ed18ea83def89626ba42cbe3f38d96e50aabd2f6 (patch) | |
tree | 7fbfe76c003d8da7f9e4472340555c4ddd2cabf9 /pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImplTest.java | |
parent | ef730fbed8743def93b864800928653a9e330457 (diff) |
Add message from VES to PNF simulator response when performing one time event request
Signed-off-by: Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com>
Change-Id: I0a12263daafacc52643838ff80482e4c7168b7ea
Issue-ID: INT-1804
Diffstat (limited to 'pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImplTest.java')
-rw-r--r-- | pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImplTest.java | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImplTest.java b/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImplTest.java index 9eaab5c..cfb03d0 100644 --- a/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImplTest.java +++ b/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImplTest.java @@ -21,6 +21,7 @@ package org.onap.pnfsimulator.simulator.client; import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; import org.apache.http.client.HttpClient; import org.apache.http.conn.socket.PlainConnectionSocketFactory; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; @@ -33,11 +34,15 @@ import java.net.MalformedURLException; import java.security.GeneralSecurityException; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import static org.onap.pnfsimulator.simulator.client.HttpTestUtils.createMockedHttpEntity; +import static org.onap.pnfsimulator.simulator.client.HttpTestUtils.createStatusLine; class HttpClientAdapterImplTest { @@ -55,12 +60,17 @@ class HttpClientAdapterImplTest { @Test void sendShouldSuccessfullySendRequestGivenValidUrl() throws IOException { - assertAdapterSentRequest("http://valid-url:8080"); + assertAdapterSentRequest("http://valid-url:8080", HttpStatus.SC_FORBIDDEN, HttpTestUtils.HTTP_MESSAGE_FORBIDDEN); } @Test void sendShouldSuccessfullySendRequestGivenValidUrlUsingHttps() throws IOException { - assertAdapterSentRequest("https://valid-url:8443"); + assertAdapterSentRequest("https://valid-url:8443", HttpStatus.SC_ACCEPTED, HttpTestUtils.HTTP_MESSAGE_ACCEPTER); + } + + @Test + void sendShouldFailToSendRequestGivenInvalidUrlUsingAdnShouldInformUser() throws IOException { + assertAdapterInformsUserWhenServiceIsUnavailable("https://invalid-url:8080"); } @Test @@ -88,13 +98,29 @@ class HttpClientAdapterImplTest { } } - private void assertAdapterSentRequest(String targetUrl) throws IOException { + private void assertAdapterSentRequest(String targetUrl, int responseCode, String responseMessage) throws IOException { HttpClientAdapter adapter = new HttpClientAdapterImpl(httpClient, targetUrl); doReturn(httpResponse).when(httpClient).execute(any()); + doReturn(createStatusLine(responseCode)).when(httpResponse).getStatusLine(); + doReturn(createMockedHttpEntity(responseMessage)).when(httpResponse).getEntity(); + + HttpResponseAdapter response = adapter.send("test-msg"); + + verify(httpClient).execute(any()); + assertEquals(responseCode, response.getCode()); + assertEquals(responseMessage, response.getMessage()); + } - adapter.send("test-msg"); + private void assertAdapterInformsUserWhenServiceIsUnavailable(String targetUrl) throws IOException { + HttpClientAdapter adapter = new HttpClientAdapterImpl(httpClient, targetUrl); + String exceptionMessage = "test message"; + doThrow(new IOException(exceptionMessage)).when(httpClient).execute(any()); + + HttpResponseAdapter response = adapter.send("test-msg"); verify(httpClient).execute(any()); - verify(httpResponse).getStatusLine(); + assertEquals(421, response.getCode()); + assertEquals(String.format("Fail to connect with ves: %s", exceptionMessage), response.getMessage()); } + } |