From e6c30425575cd76a3955b03ab389150ed74fbb1d Mon Sep 17 00:00:00 2001 From: Eylon Malin Date: Sun, 1 Sep 2019 15:02:06 +0300 Subject: handle non OK response from SDC while getting model Issue-ID: VID-378 Signed-off-by: Eylon Malin Change-Id: Idc6e587abb24fbec65ed159db7008e50abee2581 --- .../org/onap/vid/mso/MsoBusinessLogicImplTest.java | 8 ++------ .../test/java/org/onap/vid/mso/MsoUtilTest.java | 24 ++++++---------------- 2 files changed, 8 insertions(+), 24 deletions(-) (limited to 'vid-app-common/src/test/java/org/onap/vid/mso') diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java index ffabc18a2..c0683425b 100644 --- a/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java @@ -55,7 +55,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.joshworks.restclient.http.HttpResponse; import java.io.IOException; import java.net.URL; -import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; @@ -97,6 +96,7 @@ import org.onap.vid.mso.rest.Request; import org.onap.vid.mso.rest.RequestDetails; import org.onap.vid.mso.rest.RequestDetailsWrapper; import org.onap.vid.mso.rest.Task; +import org.onap.vid.testUtils.TestUtils; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.test.context.ContextConfiguration; @@ -1442,11 +1442,7 @@ public class MsoBusinessLogicImplTest extends AbstractTestNGSpringContextTests { HttpResponse httpResponse = mockForGetOrchestrationRequest(); when(httpResponse.getStatus()).thenReturn(statusCode); when(httpResponse.getBody()).thenReturn(body); - try { - when(httpResponse.getRawBody()).thenReturn(IOUtils.toInputStream(body, StandardCharsets.UTF_8.name())); - } catch (IOException e) { - throw new RuntimeException(e); - } + TestUtils.mockGetRawBodyWithStringBody(httpResponse, body); return httpResponse; } diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/MsoUtilTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/MsoUtilTest.java index 650bda13b..10456bebf 100644 --- a/vid-app-common/src/test/java/org/onap/vid/mso/MsoUtilTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/mso/MsoUtilTest.java @@ -21,17 +21,13 @@ package org.onap.vid.mso; -import io.joshworks.restclient.http.HttpResponse; -import org.apache.http.HttpResponseFactory; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.DefaultHttpResponseFactory; -import org.apache.http.message.BasicStatusLine; -import org.testng.annotations.Test; - import static org.apache.http.HttpStatus.SC_OK; -import static org.apache.http.HttpVersion.HTTP_1_1; import static org.assertj.core.api.Assertions.assertThat; +import io.joshworks.restclient.http.HttpResponse; +import org.onap.vid.testUtils.TestUtils; +import org.testng.annotations.Test; + public class MsoUtilTest { @Test @@ -51,7 +47,7 @@ public class MsoUtilTest { @Test public void shouldWrapHttpResponse() throws Exception { // given - HttpResponse httpResponse = createTestHttpResponse(SC_OK, null); + HttpResponse httpResponse = TestUtils.createTestHttpResponse(SC_OK, null); // when MsoResponseWrapper result = MsoUtil.wrapResponse(httpResponse); // then @@ -63,7 +59,7 @@ public class MsoUtilTest { public void shouldWrapHttpResponseWithEntity() throws Exception { // given String entity = "entity"; - HttpResponse httpResponse = createTestHttpResponse(SC_OK, entity); + HttpResponse httpResponse = TestUtils.createTestHttpResponse(SC_OK, entity); // when MsoResponseWrapper result = MsoUtil.wrapResponse(httpResponse); // then @@ -71,12 +67,4 @@ public class MsoUtilTest { assertThat(result.getStatus()).isEqualTo(SC_OK); } - private HttpResponse createTestHttpResponse(int statusCode, String entity) throws Exception { - HttpResponseFactory factory = new DefaultHttpResponseFactory(); - org.apache.http.HttpResponse response = factory.newHttpResponse(new BasicStatusLine(HTTP_1_1, statusCode, null), null); - if (entity != null) { - response.setEntity(new StringEntity(entity)); - } - return new HttpResponse<>(response, String.class, null); - } } -- cgit 1.2.3-korg