aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test/java/org/onap/vid/mso
diff options
context:
space:
mode:
Diffstat (limited to 'vid-app-common/src/test/java/org/onap/vid/mso')
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicTest.java71
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/MsoOperationalEnvironmentTest.java215
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/MsoUtilTest.java53
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/RestMsoImplementationTest.java20
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/rest/AsyncRequestStatusTest.java91
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java78
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestId.java280
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/rest/RelatedInstanceTest.java93
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/rest/RelatedModelTest.java93
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/rest/RequestDetailsTest.java182
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/rest/TestSuite.java12
11 files changed, 1188 insertions, 0 deletions
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicTest.java
new file mode 100644
index 000000000..4a0685786
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicTest.java
@@ -0,0 +1,71 @@
+package org.onap.vid.mso;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.portalsdk.core.util.SystemProperties;
+import org.onap.vid.controller.MsoConfig;
+import org.onap.vid.mso.MsoBusinessLogicImpl;
+import org.onap.vid.mso.MsoInterface;
+import org.onap.vid.mso.MsoResponseWrapper;
+import org.onap.vid.mso.rest.RequestDetails;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
+import org.springframework.test.context.web.WebAppConfiguration;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.net.URL;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+
+@Test
+@ContextConfiguration(classes = { SystemProperties.class, MsoConfig.class })
+@WebAppConfiguration
+public class MsoBusinessLogicTest extends AbstractTestNGSpringContextTests {
+
+ @InjectMocks
+ private MsoBusinessLogicImpl msoBusinessLogic;
+
+ @Mock
+ private MsoInterface msoClient;
+
+ @BeforeMethod
+ public void initMocks(){
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void testCreateInstance() throws Exception {
+ String instanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
+ final RequestDetails requestDetails = setRequestDetails("mso_request_create_configuration.json");
+ Mockito.doReturn(getOkResponse(instanceId)).when(msoClient).createConfigurationInstance(requestDetails, "/serviceInstances/v6/3f93c7cb-2fd0-4557-9514-e189b7b04f9d/configurations");
+ final MsoResponseWrapper msoResponseWrapper = msoBusinessLogic.createConfigurationInstance(requestDetails, instanceId);
+
+ assertNotNull(msoResponseWrapper);
+ assertEquals(202, msoResponseWrapper.getStatus());
+ }
+
+ private MsoResponseWrapper getOkResponse(String instanceId){
+ MsoResponseWrapper responseWrapper = new MsoResponseWrapper();
+ String entity = " \"body\": {\n" +
+ " \"requestReferences\": {\n" +
+ " \"instanceId\": \""+instanceId+"\",\n" +
+ " \"requestId\": \"b6dc9806-b094-42f7-9386-a48de8218ce8\"\n" +
+ " }";
+ responseWrapper.setEntity(entity);
+ responseWrapper.setStatus(202);
+ return responseWrapper;
+ }
+
+ private RequestDetails setRequestDetails(String bodyFileName)throws Exception {
+ final URL resource = this.getClass().getResource("/payload_jsons/" + bodyFileName);
+ ObjectMapper mapper = new ObjectMapper();
+ RequestDetails requestDetails = mapper.readValue(resource, RequestDetails.class);
+ return requestDetails;
+
+ }
+}
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/MsoOperationalEnvironmentTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/MsoOperationalEnvironmentTest.java
new file mode 100644
index 000000000..fcf246c99
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/MsoOperationalEnvironmentTest.java
@@ -0,0 +1,215 @@
+package org.onap.vid.mso;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableListMultimap;
+import org.apache.commons.io.IOUtils;
+import org.openecomp.portalsdk.core.util.SystemProperties;
+import org.onap.vid.changeManagement.RequestDetailsWrapper;
+import org.onap.vid.controller.MsoConfig;
+import org.onap.vid.controller.OperationalEnvironmentController;
+import org.onap.vid.controller.OperationalEnvironmentController.*;
+import org.onap.vid.controller.WebConfig;
+import org.onap.vid.mso.MsoBusinessLogic;
+import org.onap.vid.mso.model.OperationalEnvironmentActivateInfo;
+import org.onap.vid.mso.model.OperationalEnvironmentDeactivateInfo;
+import org.onap.vid.mso.rest.OperationalEnvironment.OperationEnvironmentRequestDetails;
+import org.onap.vid.mso.rest.RequestDetails;
+import org.onap.vid.properties.AsdcClientConfiguration;
+import org.skyscreamer.jsonassert.JSONAssert;
+import org.skyscreamer.jsonassert.JSONCompareMode;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
+import org.springframework.test.context.web.WebAppConfiguration;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import javax.inject.Inject;
+import java.io.IOException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+@Test
+@ContextConfiguration(classes = { WebConfig.class, AsdcClientConfiguration.class, SystemProperties.class, MsoConfig.class })
+@WebAppConfiguration
+public class MsoOperationalEnvironmentTest extends AbstractTestNGSpringContextTests {
+
+ @Inject
+ private MsoBusinessLogic msoBusinessLogic;
+
+ @Test(dataProvider = "getOperationalEnvironmentActivationPermutations")
+ public void testJsonResultOfOperationalEnvironmentActivationRequestDetails(HashMap<String, String> permutation) throws IOException {
+
+ // Convert 'manifest' to model
+ final OperationalEnvironmentManifest manifest = new ObjectMapper().readerFor(OperationalEnvironmentManifest.class).readValue(permutation.get("<manifest>"));
+
+ // build OperationalEnvironmentActivateInfo
+ OperationalEnvironmentActivateInfo inputUnderTest = createOperationalEnvironmentActivateInfo("<instanceId>", permutation.get("<userId>"), manifest, permutation.get("<relatedInstanceId>"), permutation.get("<relatedInstanceName>"), permutation.get("<workloadContext>"));
+
+ // transform to RequestDetails, and serialize to json
+ // -> actually, the function "msoBusinessLogic.createOperationalEnvironmentActivationRequestDetails"
+ // is the code under test here
+ final RequestDetailsWrapper<RequestDetails> operationalEnvironmentActivationRequestDetails = msoBusinessLogic.createOperationalEnvironmentActivationRequestDetails(inputUnderTest);
+
+ String expected = buildExpectation("payload_jsons/activateOperationalEnvironmentsPayloadToMso.json", permutation);
+
+ assertThatExpectationIsLikeObject(expected, operationalEnvironmentActivationRequestDetails);
+ }
+
+ @DataProvider
+ private Object[][] getOperationalEnvironmentActivationPermutations() throws IOException {
+ final String manifest = "" +
+ "{" +
+ " \"serviceModelList\": [" +
+ " {" +
+ " \"serviceModelVersionId\": \"uuid2\"," +
+ " \"recoveryAction\": \"retry\"" +
+ " }" +
+ " ]" +
+ "}";
+
+
+ final ImmutableListMultimap<String, String> options = ImmutableListMultimap.<String, String>builder()
+ .putAll("<instanceId>", "instanceId")
+ .putAll("<userId>", "1", "0198adb8-87fd-46ef-94ae-258816629c8b")
+ .putAll("<relatedInstanceId>", "relatedInstanceId", "2744cf56-4f00-4e48-917b-c3bd3b1f8984")
+ .putAll("<relatedInstanceName>", "relatedInstanceName", "Brooklynn Puanani")
+ .putAll("<workloadContext>", "workloadContext", "VNF_E2E-extreme")
+ .putAll("<manifest>", manifest)
+ .build();
+
+ List<HashMap<String, String>> permutations = permuteOptions(options);
+
+ return permutations.stream().map(m -> new Object[] { m }).collect(Collectors.toList()).toArray(new Object[0][0]);
+ }
+
+ @Test(dataProvider = "getOperationalEnvironmentCreationPermutations")
+ public void testJsonResultOfOperationalEnvironmentCreationRequestDetails(HashMap<String, String> permutation) throws IOException {
+
+ // build OperationalEnvironmentCreateBody
+ OperationalEnvironmentController.OperationalEnvironmentCreateBody inputUnderTest = createOperationalEnvironmentCreateBody(permutation.get("<instanceName>"), permutation.get("<ecompInstanceId>"), permutation.get("<ecompInstanceName>"), permutation.get("<operationalEnvType>"), permutation.get("<tenantContext>"), permutation.get("<workloadContext>"));
+
+ // transform to RequestDetails, and serialize to json
+ // -> actually, the function "msoBusinessLogic.createOperationalEnvironmentActivationRequestDetails"
+ // is the code under test here
+ final RequestDetailsWrapper<OperationEnvironmentRequestDetails> operationalEnvironmentCreationRequestDetails = msoBusinessLogic.convertParametersToRequestDetails(inputUnderTest, permutation.get("<userId>"));
+
+ String expected = buildExpectation("payload_jsons/createOperationalEnvironmentsPayloadToMso.json", permutation);
+
+ assertThatExpectationIsLikeObject(expected, operationalEnvironmentCreationRequestDetails);
+ }
+
+ @DataProvider
+ private Object[][] getOperationalEnvironmentCreationPermutations() throws IOException {
+
+ final ImmutableListMultimap<String, String> options = ImmutableListMultimap.<String, String>builder()
+ // instanceName, ecompInstanceId, ecompInstanceName, operationalEnvType, tenantContext, workloadContext
+ .putAll("<userId>", "1", "ceb60bba-7c18-49cd-a8f6-83ff2e1430b0", "Storm Landebert")
+ .putAll("<instanceName>", "instanceName", "Slavica Hadrien")
+ .putAll("<ecompInstanceId>", "ecompInstanceId", "58ec6753-957f-4124-8f92-c1c0bd2464a4")
+ .putAll("<ecompInstanceName>", "ecompInstanceName", "Bente Keelin")
+ .putAll("<operationalEnvType>", "operationalEnvType", "VNF")
+ .putAll("<tenantContext>", "tenantContext", "Production")
+ .putAll("<workloadContext>", "workloadContext", "E2E-extreme")
+ .build();
+
+ List<HashMap<String, String>> permutations = permuteOptions(options);
+
+ return permutations.stream().map(m -> new Object[] { m }).collect(Collectors.toList()).toArray(new Object[0][0]);
+ }
+
+ @Test(dataProvider = "getOperationalEnvironmentDeactivationPermutations")
+ public void testJsonResultOfOperationalEnvironmentDeactivationRequestDetails(HashMap<String, String> permutation) throws IOException {
+
+ OperationalEnvironmentDeactivateInfo inputUnderTest = createOperationalEnvironmentDeactivateInfo("operationalEnvId>", permutation.get("<userId>"));
+
+ final RequestDetailsWrapper<RequestDetails> operationalEnvironmentDeactivationRequestDetails = msoBusinessLogic.createOperationalEnvironmentDeactivationRequestDetails(inputUnderTest);
+
+ String expected = buildExpectation("payload_jsons/deactivateOperationalEnvironmentsPayloadToMso.json", permutation);
+
+ assertThatExpectationIsLikeObject(expected, operationalEnvironmentDeactivationRequestDetails);
+ }
+
+ @DataProvider
+ private Object[][] getOperationalEnvironmentDeactivationPermutations() throws IOException {
+
+ final ImmutableListMultimap<String, String> options = ImmutableListMultimap.<String, String>builder()
+ .putAll("<userId>", "instanceName", "Slavica Hadrien")
+ .build();
+
+ List<HashMap<String, String>> permutations = permuteOptions(options);
+
+ return permutations.stream().map(m -> new Object[] { m }).collect(Collectors.toList()).toArray(new Object[0][0]);
+ }
+
+ private List<HashMap<String, String>> permuteOptions(ImmutableListMultimap<String, String> options) {
+ // try any value, where the other keys are on the default one (index zero)
+ // result it's not the whole world of permutations, but rather a skim set, which its
+ // size is as the number of unique values in "options"
+
+ HashMap<String, String> baseMutation = new HashMap<>();
+ for (String key : options.keySet()) {
+ baseMutation.put(key, options.get(key).get(0));
+ }
+
+ List<HashMap<String, String>> res = new LinkedList<>();
+ res.add(baseMutation);
+
+ for (String key : options.keySet()) {
+ final ImmutableList<String> entry = options.get(key);
+ for (String value : entry.subList(1, entry.size())) { // skip the first option at index zero
+ HashMap<String, String> mutation = new HashMap<>();
+ mutation.putAll(baseMutation);
+ mutation.put(key, value);
+ res.add(mutation);
+ }
+ }
+ return res;
+ }
+
+ private void assertThatExpectationIsLikeObject(String expected, Object requestDetails) throws JsonProcessingException {
+ final String requestDetailsAsString = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT).writeValueAsString(requestDetails);
+
+ // assert for exact match
+ try {
+ JSONAssert.assertEquals("built mso request is not ok", expected, requestDetailsAsString, JSONCompareMode.STRICT);
+ } catch (AssertionError | Exception e) {
+ System.out.println("requestDetailsAsString: \n" + requestDetailsAsString);
+ System.out.println("expected: \n" + expected);
+ throw e;
+ }
+ }
+
+ private String buildExpectation(String modelFileName, HashMap<String, String> permutation) throws IOException {
+ // load expected result, and populate it with current input 'permutation' values
+ final URL resource = this.getClass().getResource("/" + modelFileName);
+ String expected = IOUtils.toString(resource, "UTF-8");
+
+ for (Map.Entry<String, String> stringStringEntry : permutation.entrySet()) {
+ expected = expected.replaceAll(stringStringEntry.getKey(), stringStringEntry.getValue());
+ }
+ return expected;
+ }
+
+
+
+ private OperationalEnvironmentActivateInfo createOperationalEnvironmentActivateInfo(String operationalEnvId, String userId, OperationalEnvironmentManifest manifest, String relatedInstanceId, String relatedInstanceName, String workloadContext) {
+ OperationalEnvironmentController.OperationalEnvironmentActivateBody body = new OperationalEnvironmentController.OperationalEnvironmentActivateBody(relatedInstanceId, relatedInstanceName, workloadContext, manifest);
+ return new OperationalEnvironmentActivateInfo(body, userId, operationalEnvId);
+ }
+
+ private OperationalEnvironmentDeactivateInfo createOperationalEnvironmentDeactivateInfo(String operationalEnvId, String userId) {
+ return new OperationalEnvironmentDeactivateInfo(userId, operationalEnvId);
+ }
+
+ private OperationalEnvironmentController.OperationalEnvironmentCreateBody createOperationalEnvironmentCreateBody(String instanceName, String ecompInstanceId, String ecompInstanceName, String operationalEnvType, String tenantContext, String workloadContext) {
+ return new OperationalEnvironmentController.OperationalEnvironmentCreateBody(instanceName, ecompInstanceId, ecompInstanceName, operationalEnvType, tenantContext, workloadContext);
+ }
+
+}
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
new file mode 100644
index 000000000..3356fddfc
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/MsoUtilTest.java
@@ -0,0 +1,53 @@
+package org.onap.vid.mso;
+
+import org.apache.poi.hssf.record.formula.functions.T;
+import org.glassfish.jersey.client.ClientResponse;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class MsoUtilTest {
+
+ private MsoUtil createTestSubject() {
+ return new MsoUtil();
+ }
+
+ @Test
+ public void testWrapResponse() throws Exception {
+ String body = "";
+ int statusCode = 0;
+ MsoResponseWrapper result;
+
+ // default test
+ result = MsoUtil.wrapResponse(body, statusCode);
+ }
+
+
+ @Test
+ public void testWrapResponse_2() throws Exception {
+ RestObject<String> rs = null;
+ MsoResponseWrapper result;
+
+ // test 1
+ result = MsoUtil.wrapResponse(rs);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testConvertPojoToString() throws Exception {
+ T t = null;
+ String result;
+
+ // test 1
+ t = null;
+ result = MsoUtil.convertPojoToString(t);
+ Assert.assertEquals("", result);
+ }
+
+ @Test
+ public void testMain() throws Exception {
+ String[] args = new String[] { "" };
+
+ // default test
+ MsoUtil.main(args);
+ }
+} \ No newline at end of file
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/RestMsoImplementationTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/RestMsoImplementationTest.java
new file mode 100644
index 000000000..a3fa7bca3
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/RestMsoImplementationTest.java
@@ -0,0 +1,20 @@
+package org.onap.vid.mso;
+
+import org.junit.Test;
+
+public class RestMsoImplementationTest {
+
+ private RestMsoImplementation createTestSubject() {
+ return new RestMsoImplementation();
+ }
+
+// @Test
+// public void testInitMsoClient() throws Exception {
+// RestMsoImplementation testSubject;
+//
+// // default test
+// testSubject = createTestSubject();
+// testSubject.initMsoClient();
+// }
+
+} \ No newline at end of file
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/AsyncRequestStatusTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/AsyncRequestStatusTest.java
new file mode 100644
index 000000000..ba939580a
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/AsyncRequestStatusTest.java
@@ -0,0 +1,91 @@
+package org.onap.vid.mso.rest;
+
+import org.junit.Test;
+import org.onap.vid.domain.mso.InstanceIds;
+import org.onap.vid.domain.mso.RequestStatus;
+
+
+public class AsyncRequestStatusTest {
+
+ private AsyncRequestStatus createTestSubject() {
+ return new AsyncRequestStatus();
+ }
+
+
+ @Test
+ public void testGetInstanceIds() throws Exception {
+ AsyncRequestStatus testSubject;
+ InstanceIds result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getInstanceIds();
+ }
+
+
+ @Test
+ public void testSetInstanceIds() throws Exception {
+ AsyncRequestStatus testSubject;
+ InstanceIds instanceIds = null;
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.setInstanceIds(instanceIds);
+ }
+
+
+ @Test
+ public void testGetRequestStatus() throws Exception {
+ AsyncRequestStatus testSubject;
+ RequestStatus result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getRequestStatus();
+ }
+
+
+ @Test
+ public void testSetRequestStatus() throws Exception {
+ AsyncRequestStatus testSubject;
+ RequestStatus requestStatus = null;
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.setRequestStatus(requestStatus);
+ }
+
+
+ @Test
+ public void testToString() throws Exception {
+ AsyncRequestStatus testSubject;
+ String result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.toString();
+ }
+
+
+ @Test
+ public void testHashCode() throws Exception {
+ AsyncRequestStatus testSubject;
+ int result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.hashCode();
+ }
+
+
+ @Test
+ public void testEquals() throws Exception {
+ AsyncRequestStatus testSubject;
+ Object other = null;
+ boolean result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.equals(other);
+ }
+} \ No newline at end of file
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
new file mode 100644
index 000000000..ef261055a
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java
@@ -0,0 +1,78 @@
+//package org.onap.vid.mso.rest;
+//
+//import com.fasterxml.jackson.databind.ObjectMapper;
+//import org.json.JSONObject;
+//import org.junit.Assert;
+//import org.openecomp.portalsdk.core.util.SystemProperties;
+//import org.onap.vid.changeManagement.RequestDetails;
+//import org.onap.vid.controller.LocalWebConfig;
+//import org.onap.vid.domain.mso.CloudConfiguration;
+//import org.onap.vid.domain.mso.ModelInfo;
+//import org.onap.vid.domain.mso.RequestInfo;
+//import org.onap.vid.domain.mso.RequestParameters;
+//import org.onap.vid.mso.MsoBusinessLogic;
+//import org.onap.vid.mso.MsoBusinessLogicImpl;
+//import org.onap.vid.mso.rest.MsoRestClientNew;
+//import org.springframework.test.context.ContextConfiguration;
+//import org.springframework.test.context.web.WebAppConfiguration;
+//import org.testng.annotations.Test;
+//
+//
+//@ContextConfiguration(classes = {LocalWebConfig.class, SystemProperties.class})
+//@WebAppConfiguration
+//public class MsoRestClientTest {
+//
+//
+// private MsoBusinessLogic msoBusinessLogic = new MsoBusinessLogicImpl(new MsoRestClientNew());
+// private ObjectMapper om = new ObjectMapper();
+//
+// @Test
+// public void createInPlaceMsoRequest() {
+// String result = null;
+// try {
+// RequestDetails requestDetails = generateMockMsoRequest();
+// result = om.writeValueAsString(msoBusinessLogic.generateInPlaceMsoRequest(requestDetails));
+//
+// } catch (Exception e) {
+// e.printStackTrace();
+//
+// }
+// if (result == null) {
+// Assert.fail("Failed to create mso request");
+// }
+// JSONObject jsonObj = new JSONObject(result);
+// Assert.assertNotNull(jsonObj.getJSONObject("requestDetails"));
+//
+//
+// }
+//
+// private RequestDetails generateMockMsoRequest() {
+// RequestDetails requestDetails = new RequestDetails();
+// requestDetails.setVnfInstanceId("vnf-instance-id");
+// requestDetails.setVnfName("vnf-name");
+// CloudConfiguration cloudConfiguration = new CloudConfiguration();
+// cloudConfiguration.setTenantId("tenant-id");
+// cloudConfiguration.setLcpCloudRegionId("lcp-region");
+// requestDetails.setCloudConfiguration(cloudConfiguration);
+// ModelInfo modelInfo = new ModelInfo();
+// modelInfo.setModelInvariantId("model-invarient-id");
+// modelInfo.setModelCustomizationName("modelCustomizationName");
+// requestDetails.setModelInfo(modelInfo);
+// RequestInfo requestInfo = new RequestInfo();
+// requestInfo.setRequestorId("ok883e");
+// requestInfo.setSource("VID");
+// requestDetails.setRequestInfo(requestInfo);
+// RequestParameters requestParameters = new RequestParameters();
+// requestParameters.setSubscriptionServiceType("subscriber-service-type");
+// requestParameters.setAdditionalProperty("a", 1);
+// requestParameters.setAdditionalProperty("b", 2);
+// requestParameters.setAdditionalProperty("c", 3);
+// requestParameters.setAdditionalProperty("d", 4);
+// String payload = "{\"existing-software-version\": \"3.1\",\"new-software-version\": \"3.2\", \"operations-timeout\": \"3600\"}";
+// requestParameters.setAdditionalProperty("payload", payload);
+//
+// requestDetails.setRequestParameters(requestParameters);
+// return requestDetails;
+// }
+//
+//}
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestId.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestId.java
new file mode 100644
index 000000000..51071a859
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestId.java
@@ -0,0 +1,280 @@
+package org.onap.vid.mso.rest;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import org.apache.commons.lang3.reflect.FieldUtils;
+import org.mockito.*;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.onap.vid.aai.util.AAIRestInterface;
+import org.onap.vid.asdc.rest.RestfulAsdcClient;
+import org.onap.vid.changeManagement.RequestDetailsWrapper;
+import org.onap.vid.controller.filter.PromiseEcompRequestIdFilter;
+import org.onap.vid.mso.RestMsoImplementation;
+import org.onap.vid.mso.RestObject;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.Invocation;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.GenericType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.util.List;
+import java.util.Set;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static java.util.UUID.randomUUID;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.*;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.*;
+
+
+public class OutgoingRequestId {
+
+
+ @InjectMocks
+ private RestMsoImplementation restMsoImplementation;
+
+ @InjectMocks
+ private AAIRestInterface aaiRestInterface;
+
+ private RestfulAsdcClient restfulAsdcClient = new RestfulAsdcClient.Builder(mock(Client.class), null).build();
+
+ @Captor
+ private ArgumentCaptor<MultivaluedMap<String, Object>> multivaluedMapArgumentCaptor;
+
+ @BeforeClass
+ public void initMocks() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @BeforeMethod
+ private void putRequestInSpringContext() {
+ RequestContextHolder.setRequestAttributes(new ServletRequestAttributes((HttpServletRequest) PromiseEcompRequestIdFilter.wrapIfNeeded(new MockHttpServletRequest())));
+ }
+
+ @DataProvider
+ public Object[][] sdcMethods() {
+ return Stream.<ThrowingConsumer<RestfulAsdcClient>>of(
+
+ client -> client.getResource(randomUUID()),
+ client -> client.getResourceArtifact(randomUUID(), randomUUID()),
+ RestfulAsdcClient::getResources,
+ client -> client.getResources(ImmutableMap.of()),
+ client -> client.getResourceToscaModel(randomUUID()),
+ client -> client.getService(randomUUID()),
+ client -> client.getServiceArtifact(randomUUID(), randomUUID()),
+ RestfulAsdcClient::getServices,
+ client -> client.getServices(ImmutableMap.of()),
+ client -> client.getServiceToscaModel(randomUUID())
+
+ ).map(l -> ImmutableList.of(l).toArray()).collect(Collectors.toList()).toArray(new Object[][]{});
+ }
+
+ @Test(dataProvider = "sdcMethods")
+ public void sdc(Consumer<RestfulAsdcClient> f) throws Exception {
+ final Mocks mocks = setAndGetMocksInsideRestImpl(restfulAsdcClient);
+
+ f.accept(restfulAsdcClient);
+
+ verifyRequestIdHeaderWasAdded(mocks.getFakeBuilder());
+ }
+
+ @DataProvider
+ public Object[][] msoMethods() {
+ return Stream.<ThrowingConsumer<RestMsoImplementation>>of(
+
+ client -> client.Get(new Object(), "whatever source id", "/any path", new RestObject<>()),
+ client -> client.GetForObject("whatever source id", "/any path", Object.class),
+ client -> client.Post(new Object(), "some payload", "whatever source id", "/any path", new RestObject<>()),
+ client -> client.PostForObject("some payload", "whatever source id", "/any path", Object.class),
+ client -> client.Put(Object.class, new RequestDetailsWrapper(), "whatever source id", "/any path", new RestObject<>())
+
+ ).map(l -> ImmutableList.of(l).toArray()).collect(Collectors.toList()).toArray(new Object[][]{});
+ }
+
+ @Test(dataProvider = "msoMethods")
+ public void mso(Consumer<RestMsoImplementation> f) throws Exception {
+ final Mocks mocks = setAndGetMocksInsideRestImpl(restMsoImplementation.getClass());
+
+ f.accept(restMsoImplementation);
+
+ verifyRequestIdHeaderWasAdded(mocks.getFakeBuilder());
+ }
+
+ @DataProvider
+ public Object[][] aaiMethods() {
+ return Stream.<ThrowingConsumer<AAIRestInterface>>of(
+
+ client -> client.RestGet("from app id", "some transId", "/any path", false),
+ client -> client.Delete("whatever source id", "some transId", "/any path"),
+ client -> client.RestPost("from app id", "some transId", "/any path", "some payload", false),
+ client -> client.RestPut("from app id", "some transId", "/any path", "some payload", false)
+
+ ).map(l -> ImmutableList.of(l).toArray()).collect(Collectors.toList()).toArray(new Object[][]{});
+ }
+
+ @Test(dataProvider = "aaiMethods")
+ public void aai(Consumer<AAIRestInterface> f) throws Exception {
+ final Mocks mocks = setAndGetMocksInsideRestImpl(aaiRestInterface.getClass());
+
+ f.accept(aaiRestInterface);
+
+ verifyRequestIdHeaderWasAdded(mocks.getFakeBuilder());
+ }
+
+// @Test(dataProvider = "schedulerMethods")
+// public void scheduler(Consumer<AAIRestInterface> f) throws Exception {
+//
+// This test os not feasible in the wat acheduler is implemented today,
+// as Scheduler's client is rewritten in every call.
+//
+// :-(
+//
+// }
+
+ private void verifyRequestIdHeaderWasAdded(Invocation.Builder fakeBuilder) {
+ final String requestIdHeader = "x-ecomp-requestid";
+ final String uuidRegex = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
+
+ // Checks that the builder was called with either one of header("x-ecomp-requestid", uuid)
+ // or the plural brother: headers(Map.of("x-ecomp-requestid", Set.of(uuid))
+
+ Object requestId;
+ // The 'verify()' will capture the request id. If no match -- AssertionError will
+ // catch for a second chance -- another 'verify()'.
+ try {
+ ArgumentCaptor<Object> argumentCaptor = ArgumentCaptor.forClass(Object.class);
+ Mockito.verify(fakeBuilder)
+ .header(
+ Matchers.argThat(equalToIgnoringCase(requestIdHeader)),
+ argumentCaptor.capture()
+ );
+ requestId = argumentCaptor.getValue();
+
+ } catch (AssertionError e) {
+ Mockito.verify(fakeBuilder).headers(multivaluedMapArgumentCaptor.capture());
+
+ final MultivaluedMap<String, Object> headersMap = multivaluedMapArgumentCaptor.getValue();
+ final String thisRequestIdHeader = getFromSetCaseInsensitive(headersMap.keySet(), requestIdHeader);
+
+ assertThat(headersMap.keySet(), hasItem(thisRequestIdHeader));
+ requestId = headersMap.getFirst(thisRequestIdHeader);
+ }
+
+ assertThat("header '" + requestIdHeader + "' should be a uuid", requestId,
+ allOf(instanceOf(String.class), hasToString(matchesPattern(uuidRegex))));
+ }
+
+ private String getFromSetCaseInsensitive(Set<String> set, String key) {
+ return set.stream()
+ .filter(anotherString -> anotherString.equalsIgnoreCase(key))
+ .findFirst()
+ .orElse(key);
+ }
+
+ private Mocks setAndGetMocksInsideRestImpl(Class<?> clazz) throws IllegalAccessException {
+ Mocks mocks = new Mocks();
+ Client fakeClient = mocks.getFakeClient();
+
+ FieldUtils.writeStaticField(clazz, "client", fakeClient, true);
+
+ return mocks;
+ }
+
+ private Mocks setAndGetMocksInsideRestImpl(Object instance) throws IllegalAccessException {
+ Mocks mocks = new Mocks();
+ Client fakeClient = mocks.getFakeClient();
+
+ FieldUtils.writeField(instance, "client", fakeClient, true);
+
+ return mocks;
+ }
+
+ private static class Mocks {
+ private final Client fakeClient;
+ private final Invocation.Builder fakeBuilder;
+
+ Client getFakeClient() {
+ return fakeClient;
+ }
+
+ Invocation.Builder getFakeBuilder() {
+ return fakeBuilder;
+ }
+
+ Mocks() {
+ final MockSettings mockSettings = withSettings().defaultAnswer(new TriesToReturnMockByType());
+
+ fakeClient = mock(Client.class, mockSettings);
+ fakeBuilder = mock(Invocation.Builder.class, mockSettings);
+ final WebTarget fakeWebTarget = mock(WebTarget.class, mockSettings);
+ final Response fakeResponse = mock(Response.class, mockSettings);
+
+ TriesToReturnMockByType.setAvailableMocks(
+ fakeClient,
+ fakeWebTarget,
+ fakeBuilder,
+ fakeResponse
+ );
+
+ Mockito.when(fakeBuilder.get(any(Class.class))).thenReturn(null);
+ Mockito.when(fakeBuilder.get(eq(InputStream.class))).thenReturn(new ByteArrayInputStream(new byte[]{}));
+ Mockito.when(fakeBuilder.get(any(GenericType.class))).thenReturn(null);
+
+ Mockito.when(fakeResponse.getStatus()).thenReturn(200);
+ }
+ }
+
+ @FunctionalInterface
+ public interface ThrowingConsumer<T> extends Consumer<T> {
+ @Override
+ default void accept(T t) {
+ try {
+ acceptThrows(t);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ void acceptThrows(T t) throws Exception;
+ }
+
+ /*
+ inspired out from newer Mockito version
+ returns a mock from given list if it's a matching return-type
+ */
+ public static class TriesToReturnMockByType implements Answer<Object>, Serializable {
+ private final Answer<Object> defaultReturn = RETURNS_DEFAULTS;
+ private static List<Object> availableMocks = ImmutableList.of();
+
+ static void setAvailableMocks(Object... mocks) {
+ availableMocks = ImmutableList.copyOf(mocks);
+ }
+
+ public Object answer(InvocationOnMock invocation) throws Throwable {
+ Class<?> methodReturnType = invocation.getMethod().getReturnType();
+
+ return availableMocks.stream()
+ .filter(mock -> methodReturnType.isAssignableFrom(mock.getClass()))
+ //.peek(m -> System.out.println("found a mock: " + m.getClass().getName()))
+ .findFirst()
+ .orElse(defaultReturn.answer(invocation));
+ }
+ }
+
+}
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/RelatedInstanceTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/RelatedInstanceTest.java
new file mode 100644
index 000000000..4b35430e0
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/RelatedInstanceTest.java
@@ -0,0 +1,93 @@
+package org.onap.vid.mso.rest;
+
+import java.util.Map;
+
+import org.junit.Test;
+import org.onap.vid.domain.mso.ModelInfo;
+
+
+public class RelatedInstanceTest {
+
+ private RelatedInstance createTestSubject() {
+ return new RelatedInstance();
+ }
+
+
+ @Test
+ public void testGetModelInfo() throws Exception {
+ RelatedInstance testSubject;
+ ModelInfo result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getModelInfo();
+ }
+
+
+ @Test
+ public void testSetModelInfo() throws Exception {
+ RelatedInstance testSubject;
+ ModelInfo modelInfo = null;
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.setModelInfo(modelInfo);
+ }
+
+
+ @Test
+ public void testToString() throws Exception {
+ RelatedInstance testSubject;
+ String result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.toString();
+ }
+
+
+ @Test
+ public void testGetAdditionalProperties() throws Exception {
+ RelatedInstance testSubject;
+ Map<String, Object> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getAdditionalProperties();
+ }
+
+
+ @Test
+ public void testSetAdditionalProperty() throws Exception {
+ RelatedInstance testSubject;
+ String name = "";
+ Object value = null;
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.setAdditionalProperty(name, value);
+ }
+
+
+ @Test
+ public void testHashCode() throws Exception {
+ RelatedInstance testSubject;
+ int result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.hashCode();
+ }
+
+
+ @Test
+ public void testEquals() throws Exception {
+ RelatedInstance testSubject;
+ Object other = null;
+ boolean result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.equals(other);
+ }
+} \ No newline at end of file
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/RelatedModelTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/RelatedModelTest.java
new file mode 100644
index 000000000..91d61bd9f
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/RelatedModelTest.java
@@ -0,0 +1,93 @@
+package org.onap.vid.mso.rest;
+
+import java.util.Map;
+
+import org.junit.Test;
+import org.onap.vid.domain.mso.ModelInfo;
+
+
+public class RelatedModelTest {
+
+ private RelatedModel createTestSubject() {
+ return new RelatedModel();
+ }
+
+
+ @Test
+ public void testGetModelInfo() throws Exception {
+ RelatedModel testSubject;
+ ModelInfo result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getModelInfo();
+ }
+
+
+ @Test
+ public void testSetModelInfo() throws Exception {
+ RelatedModel testSubject;
+ ModelInfo modelInfo = null;
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.setModelInfo(modelInfo);
+ }
+
+
+ @Test
+ public void testToString() throws Exception {
+ RelatedModel testSubject;
+ String result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.toString();
+ }
+
+
+ @Test
+ public void testGetAdditionalProperties() throws Exception {
+ RelatedModel testSubject;
+ Map<String, Object> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getAdditionalProperties();
+ }
+
+
+ @Test
+ public void testSetAdditionalProperty() throws Exception {
+ RelatedModel testSubject;
+ String name = "";
+ Object value = null;
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.setAdditionalProperty(name, value);
+ }
+
+
+ @Test
+ public void testHashCode() throws Exception {
+ RelatedModel testSubject;
+ int result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.hashCode();
+ }
+
+
+ @Test
+ public void testEquals() throws Exception {
+ RelatedModel testSubject;
+ Object other = null;
+ boolean result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.equals(other);
+ }
+} \ No newline at end of file
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/RequestDetailsTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/RequestDetailsTest.java
new file mode 100644
index 000000000..153e16561
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/RequestDetailsTest.java
@@ -0,0 +1,182 @@
+package org.onap.vid.mso.rest;
+
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+import org.onap.vid.domain.mso.*;
+
+
+public class RequestDetailsTest {
+
+ private RequestDetails createTestSubject() {
+ return new RequestDetails();
+ }
+
+
+ @Test
+ public void testGetCloudConfiguration() throws Exception {
+ RequestDetails testSubject;
+ CloudConfiguration result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getCloudConfiguration();
+ }
+
+
+ @Test
+ public void testSetCloudConfiguration() throws Exception {
+ RequestDetails testSubject;
+ CloudConfiguration cloudConfiguration = null;
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.setCloudConfiguration(cloudConfiguration);
+ }
+
+
+ @Test
+ public void testGetModelInfo() throws Exception {
+ RequestDetails testSubject;
+ ModelInfo result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getModelInfo();
+ }
+
+
+ @Test
+ public void testSetModelInfo() throws Exception {
+ RequestDetails testSubject;
+ ModelInfo modelInfo = null;
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.setModelInfo(modelInfo);
+ }
+
+
+ @Test
+ public void testGetRelatedInstanceList() throws Exception {
+ RequestDetails testSubject;
+ List<RelatedModel> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getRelatedInstanceList();
+ }
+
+
+ @Test
+ public void testSetRelatedInstanceList() throws Exception {
+ RequestDetails testSubject;
+ List<RelatedModel> relatedInstanceList = null;
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.setRelatedInstanceList(relatedInstanceList);
+ }
+
+
+ @Test
+ public void testGetRequestInfo() throws Exception {
+ RequestDetails testSubject;
+ RequestInfo result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getRequestInfo();
+ }
+
+
+ @Test
+ public void testSetRequestInfo() throws Exception {
+ RequestDetails testSubject;
+ RequestInfo requestInfo = null;
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.setRequestInfo(requestInfo);
+ }
+
+
+ @Test
+ public void testGetSubscriberInfo() throws Exception {
+ RequestDetails testSubject;
+ SubscriberInfo result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getSubscriberInfo();
+ }
+
+
+ @Test
+ public void testSetSubscriberInfo() throws Exception {
+ RequestDetails testSubject;
+ SubscriberInfo subscriberInfo = null;
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.setSubscriberInfo(subscriberInfo);
+ }
+
+
+ @Test
+ public void testToString() throws Exception {
+ RequestDetails testSubject;
+ String result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.toString();
+ }
+
+
+ @Test
+ public void testGetAdditionalProperties() throws Exception {
+ RequestDetails testSubject;
+ Map<String, Object> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getAdditionalProperties();
+ }
+
+
+ @Test
+ public void testSetAdditionalProperty() throws Exception {
+ RequestDetails testSubject;
+ String name = "";
+ Object value = null;
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.setAdditionalProperty(name, value);
+ }
+
+
+ @Test
+ public void testHashCode() throws Exception {
+ RequestDetails testSubject;
+ int result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.hashCode();
+ }
+
+
+ @Test
+ public void testEquals() throws Exception {
+ RequestDetails testSubject;
+ Object other = null;
+ boolean result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.equals(other);
+ }
+} \ No newline at end of file
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/TestSuite.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/TestSuite.java
new file mode 100644
index 000000000..72633daef
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/TestSuite.java
@@ -0,0 +1,12 @@
+package org.onap.vid.mso.rest;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses(
+
+{ RelatedModelTest.class, AsyncRequestStatusTest.class, RequestDetailsTest.class,
+ RelatedInstanceTest.class })
+public class TestSuite { // nothing
+}