summaryrefslogtreecommitdiffstats
path: root/vid-app-common
diff options
context:
space:
mode:
authorWojciech Sliwka <wojciech.sliwka@nokia.com>2019-03-18 10:25:06 +0000
committerGerrit Code Review <gerrit@onap.org>2019-03-18 10:25:06 +0000
commitb324a34d09bcfec4fa66f39184f1a42a0101ff84 (patch)
tree2e8159275b5407f8182ae1238656d691b44515eb /vid-app-common
parenta036637a4d466662128cde1823816578e76c69e0 (diff)
parent4fe07922c0c85e9814f444d1aff7fbd4a294db19 (diff)
Merge "Fix getManualTasks double-addition of baseUrl"
Diffstat (limited to 'vid-app-common')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/mso/rest/MsoRestClientNew.java36
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientNewTest.java67
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java36
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTestUtil.java4
4 files changed, 66 insertions, 77 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/rest/MsoRestClientNew.java b/vid-app-common/src/main/java/org/onap/vid/mso/rest/MsoRestClientNew.java
index b47981ecf..8dac0ce1b 100644
--- a/vid-app-common/src/main/java/org/onap/vid/mso/rest/MsoRestClientNew.java
+++ b/vid-app-common/src/main/java/org/onap/vid/mso/rest/MsoRestClientNew.java
@@ -22,6 +22,13 @@ package org.onap.vid.mso.rest;
import com.google.common.collect.ImmutableMap;
import io.joshworks.restclient.http.HttpResponse;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
import org.apache.commons.codec.binary.Base64;
import org.eclipse.jetty.util.security.Password;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
@@ -31,17 +38,15 @@ import org.onap.vid.changeManagement.MsoRequestDetails;
import org.onap.vid.changeManagement.RequestDetailsWrapper;
import org.onap.vid.client.SyncRestClient;
import org.onap.vid.model.RequestReferencesContainer;
-import org.onap.vid.mso.*;
+import org.onap.vid.mso.MsoInterface;
+import org.onap.vid.mso.MsoProperties;
+import org.onap.vid.mso.MsoResponseWrapper;
+import org.onap.vid.mso.MsoResponseWrapperInterface;
+import org.onap.vid.mso.MsoUtil;
+import org.onap.vid.mso.RestMsoImplementation;
+import org.onap.vid.mso.RestObject;
import org.onap.vid.utils.Logging;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
/**
* Created by pickjonathan on 21/06/2017.
@@ -220,13 +225,7 @@ public class MsoRestClientNew extends RestMsoImplementation implements MsoInterf
return MsoUtil.wrapResponse(response);
}
- public MsoResponseWrapper getManualTasks(String endpoint) {
- String path = baseUrl + endpoint;
-
- HttpResponse<String> response = client.get(path, commonHeaders, new HashMap<>(), String.class);
- return MsoUtil.wrapResponse(response);
- }
-
+ @Override
public MsoResponseWrapper getManualTasksByRequestId(String t, String sourceId, String endpoint, RestObject restObject) {
String methodName = "getManualTasksByRequestId";
logger.debug(methodName + START);
@@ -234,9 +233,10 @@ public class MsoRestClientNew extends RestMsoImplementation implements MsoInterf
try {
String path = baseUrl + endpoint;
- MsoResponseWrapper w =getManualTasks(path);
- logger.debug(EELFLoggerDelegate.debugLogger, methodName + " w=" + w.getResponse());
+ HttpResponse<String> response = client.get(path, commonHeaders, new HashMap<>(), String.class);
+ MsoResponseWrapper w = MsoUtil.wrapResponse(response);
+ logger.debug(EELFLoggerDelegate.debugLogger, methodName + " w=" + w.getResponse());
return w;
} catch (Exception e) {
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientNewTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientNewTest.java
index f58462dd6..12fd4a519 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientNewTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientNewTest.java
@@ -20,8 +20,18 @@
*/
package org.onap.vid.mso.rest;
+import static org.onap.vid.controller.MsoController.SVC_INSTANCE_ID;
+import static org.onap.vid.controller.MsoController.VNF_INSTANCE_ID;
+
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xebialabs.restito.server.StubServer;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Properties;
+import java.util.UUID;
import org.glassfish.grizzly.http.util.HttpStatus;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -37,17 +47,6 @@ import org.onap.vid.mso.MsoResponseWrapperInterface;
import org.onap.vid.mso.RestObject;
import org.springframework.test.context.ContextConfiguration;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Properties;
-import java.util.UUID;
-
-import static org.onap.vid.controller.MsoController.SVC_INSTANCE_ID;
-import static org.onap.vid.controller.MsoController.VNF_INSTANCE_ID;
-
@ContextConfiguration(classes = {SystemProperties.class})
public class MsoRestClientNewTest {
@@ -280,16 +279,39 @@ public class MsoRestClientNewTest {
}
@Test
- public void testGetManualTasks() {
+ public void testGetManualTasksByRequestId() {
String p = props.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
String path = p + "/" + UUID.randomUUID();
+ String validResponse = ""
+ + "{ "
+ + " \"taskList\": [ "
+ + " { "
+ + " \"taskId\": \"daf4dd84-b77a-42da-a051-3239b7a9392c\", "
+ + " \"type\": \"fallout\", "
+ + " \"nfRole\": \"vEsmeralda\", "
+ + " \"subscriptionServiceType\": \"Emanuel\", "
+ + " \"originalRequestId\": \"d352c70d-5ef8-4977-9ea8-4c8cbe860422\", "
+ + " \"originalRequestorId\": \"ss835w\", "
+ + " \"errorSource\": \"A&AI\", "
+ + " \"errorCode\": \"404\", "
+ + " \"errorMessage\": \"Failed in A&AI 404\", "
+ + " \"validResponses\": [ "
+ + " \"rollback\", "
+ + " \"abort\", "
+ + " \"skip\", "
+ + " \"resume\", "
+ + " \"retry\" "
+ + " ] "
+ + " } "
+ + " ] "
+ + "}";
try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
server,
path,
HttpStatus.OK_200,
- CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
- closure.executeGet(msoRestClient()::getManualTasks);
+ validResponse,validResponse)) {
+ closure.executeGet(endpoint -> msoRestClient().getManualTasksByRequestId(null, null, endpoint, null));
}
}
@@ -311,23 +333,6 @@ public class MsoRestClientNewTest {
}
@Test
- public void testGetManualTasksByRequestId() throws Exception {
- MsoRestClientNew testSubject;
- String t = "";
- String sourceId = "";
- String endpoint = "";
- RestObject restObject = null;
- MsoResponseWrapper result;
-
- // default test
- try {
- testSubject = createTestSubject();
- result = testSubject.getManualTasksByRequestId(t, sourceId, endpoint, restObject);
- } catch (Exception e) {
- }
- }
-
- @Test
public void testCompleteManualTask() throws Exception {
MsoRestClientNew testSubject;
RequestDetails requestDetails = null;
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java
index 7caafed00..ff71d85fc 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java
@@ -20,6 +20,13 @@
*/
package org.onap.vid.mso.rest;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+
import io.joshworks.restclient.http.HttpResponse;
import io.joshworks.restclient.http.JsonMapper;
import org.apache.http.ProtocolVersion;
@@ -42,14 +49,6 @@ import org.springframework.test.context.web.WebAppConfiguration;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-import static org.mockito.ArgumentMatchers.any;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.anyMap;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.when;
-import static org.mockito.MockitoAnnotations.initMocks;
-
@ContextConfiguration(classes = {LocalWebConfig.class, SystemProperties.class})
@WebAppConfiguration
@@ -391,22 +390,6 @@ public class MsoRestClientTest {
}
@Test
- public void shouldProperlyGetManualTasks() {
- // given
- String endpoint = "testEndpoint";
- HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
- MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
-
- when( client.get( eq(baseUrl+endpoint),anyMap(),anyMap(),eq(String.class) ) ).thenReturn(httpResponse);
-
- // when
- MsoResponseWrapper response = restClient.getManualTasks(endpoint);
-
- // then
- assertThat(response).isEqualToComparingFieldByField(expectedResponse);
- }
-
- @Test
public void shouldProperlyGetManualTasksByRequestId() {
// given
RestObject restObject = generateMockMsoRestObject();
@@ -415,8 +398,7 @@ public class MsoRestClientTest {
HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
- /// WUT 'baseUrl+baseUrl+endpoint'
- when( client.get( eq(baseUrl+baseUrl+endpoint),anyMap(),anyMap(),eq(String.class) ) ).thenReturn(httpResponse);
+ when( client.get( eq(baseUrl+endpoint),anyMap(),anyMap(),eq(String.class) ) ).thenReturn(httpResponse);
// when
MsoResponseWrapper response = restClient.getManualTasksByRequestId(null,null,endpoint,restObject);
@@ -428,7 +410,7 @@ public class MsoRestClientTest {
@Test(expectedExceptions = MsoTestException.class)
public void shouldThrowExceptionWhenGetManualTasksByRequestIdGetsWrongParameter() {
// given
- when( client.get( eq(baseUrl+baseUrl),anyMap(),anyMap(),eq(String.class) ) ).thenThrow(new MsoTestException("testsException"));
+ when( client.get( eq(baseUrl),anyMap(),anyMap(),eq(String.class) ) ).thenThrow(new MsoTestException("testsException"));
// when
restClient.getManualTasksByRequestId(null,null,"",null);
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTestUtil.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTestUtil.java
index 1720e0467..f10a7f14f 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTestUtil.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTestUtil.java
@@ -31,6 +31,7 @@ import static com.xebialabs.restito.semantics.Condition.method;
import static com.xebialabs.restito.semantics.Condition.post;
import static com.xebialabs.restito.semantics.Condition.uri;
import static com.xebialabs.restito.semantics.Condition.withHeader;
+import static net.javacrumbs.jsonunit.JsonAssert.assertJsonEquals;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xebialabs.restito.semantics.Action;
@@ -42,7 +43,6 @@ import java.util.function.BiFunction;
import java.util.function.Function;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
-
import org.glassfish.grizzly.http.Method;
import org.glassfish.grizzly.http.util.HttpStatus;
import org.json.JSONObject;
@@ -116,6 +116,7 @@ class MsoRestClientTestUtil implements AutoCloseable {
MsoResponseWrapper response = func.apply(sampleRequestDetails, endpoint);
Assert.assertEquals(expectedStatus.getStatusCode(), response.getStatus());
+ assertJsonEquals(expectedResponseStr, response.getEntity());
verifyServer(server, endpoint, Method.DELETE);
}
@@ -127,6 +128,7 @@ class MsoRestClientTestUtil implements AutoCloseable {
MsoResponseWrapper response = func.apply(endpoint);
Assert.assertEquals(expectedStatus.getStatusCode(), response.getStatus());
+ assertJsonEquals(expectedResponseStr, response.getEntity());
verifyServer(server, endpoint, Method.GET);
}