aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test/java/org/onap/vid/asdc
diff options
context:
space:
mode:
authorEylon Malin <eylon.malin@intl.att.com>2019-09-01 15:02:06 +0300
committerEylon Malin <eylon.malin@intl.att.com>2019-09-01 15:02:06 +0300
commite6c30425575cd76a3955b03ab389150ed74fbb1d (patch)
treee1a668efc3bbd6b5da72ebd8b9825d5e1a96d74c /vid-app-common/src/test/java/org/onap/vid/asdc
parent406cc2fe614d089c2f7834f9a22d6dfa47b4fa16 (diff)
handle non OK response from SDC while getting model
Issue-ID: VID-378 Signed-off-by: Eylon Malin <eylon.malin@intl.att.com> Change-Id: Idc6e587abb24fbec65ed159db7008e50abee2581
Diffstat (limited to 'vid-app-common/src/test/java/org/onap/vid/asdc')
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/asdc/rest/SdcRestClientTest.java59
1 files changed, 56 insertions, 3 deletions
diff --git a/vid-app-common/src/test/java/org/onap/vid/asdc/rest/SdcRestClientTest.java b/vid-app-common/src/test/java/org/onap/vid/asdc/rest/SdcRestClientTest.java
index 5eaaf9335..13fe761c6 100644
--- a/vid-app-common/src/test/java/org/onap/vid/asdc/rest/SdcRestClientTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/asdc/rest/SdcRestClientTest.java
@@ -21,6 +21,7 @@
package org.onap.vid.asdc.rest;
+import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -33,6 +34,7 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.matches;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import static org.onap.vid.testUtils.TestUtils.mockGetRawBodyWithStringBody;
import static org.testng.AssertJUnit.fail;
import io.joshworks.restclient.http.HttpResponse;
@@ -178,10 +180,10 @@ public class SdcRestClientTest {
public void whenJavaxClientThrowException_then_getServiceToscaModelRethrowException(Class<? extends Throwable> expectedType, Consumer<SyncRestClient> setupMocks) throws Exception {
/*
Call chain is like:
- this test -> RestfulAsdcClient -> javax's Client
+ this test -> SdcRestClient -> SdcRestClient -> joshworks client which return joshworks HttpResponse
- In this test, *RestfulAsdcClient* is under test (actual implementation is used), while javax's Client is
- mocked to return pseudo-responses or - better - throw exceptions.
+ In this test, *SdcRestClient* is under test (actual implementation is used), while SdcRestClient is
+ mocked to return pseudo joshworks HttpResponse or - better - throw exceptions.
*/
/// TEST:
@@ -198,4 +200,55 @@ public class SdcRestClientTest {
fail("exception shall rethrown by getServiceToscaModel once javax client throw exception ");
}
+ @DataProvider
+ public static Object[][] badResponses() {
+ return new Object[][] {
+ {(Consumer<HttpResponse>) response -> {
+ when(response.getStatus()).thenReturn(404);
+ mockGetRawBodyWithStringBody(response,"");},
+ ""
+ },
+ {(Consumer<HttpResponse>) response -> {
+ when(response.getStatus()).thenReturn(405);
+ when(response.getRawBody()).thenThrow(ClassCastException.class);},
+ ""
+ },
+ {(Consumer<HttpResponse>) response -> {
+ when(response.getStatus()).thenReturn(500);
+ mockGetRawBodyWithStringBody(response,"some message");},
+ "some message"
+ },
+ };
+ }
+
+ @Test(dataProvider = "badResponses")
+ public void whenJavaxClientReturnBadCode_then_getServiceToscaModelThrowException(Consumer<HttpResponse> setupMocks, String exceptedBody) throws Exception {
+ /*
+ Call chain is like:
+ this test -> SdcRestClient -> SdcRestClient -> joshworks client which return joshworks HttpResponse
+
+ In this test, *SdcRestClient* is under test (actual implementation is used), while SdcRestClient is
+ mocked to return pseudo joshworks HttpResponse
+ */
+
+ HttpResponse<InputStream> mockResponse = mock(HttpResponse.class);
+ SyncRestClient syncRestClient = mock(SyncRestClient.class);
+ when(syncRestClient.getStream(anyString(), anyMap(), anyMap())).thenReturn(mockResponse);
+
+ // prepare real RestfulAsdcClient (Under test)
+
+ setupMocks.accept(mockResponse);
+
+ try {
+ new SdcRestClient(SAMPLE_BASE_URL, SAMPLE_AUTH, syncRestClient).getServiceToscaModel(UUID.randomUUID());
+ } catch (AsdcCatalogException e) {
+ assertThat(e.getMessage(), containsString(String.valueOf(mockResponse.getStatus())));
+ assertThat(e.getMessage(), containsString(exceptedBody));
+ return; //OK
+ }
+
+ fail("exception shall be thrown by getServiceToscaModel once response contains error code ");
+ }
+
+
}