aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test/java/org/onap/vid/mso
diff options
context:
space:
mode:
authorBartosz Gardziejewski <bartosz.gardziejewski@nokia.com>2019-03-25 10:07:38 +0100
committerBartosz Gardziejewski <bartosz.gardziejewski@nokia.com>2019-04-01 15:58:25 +0200
commit30794f9184dc2220a557ba5610a434c2a2bac801 (patch)
tree31831476e0bbee7f9cd85ff20b30723c456905fd /vid-app-common/src/test/java/org/onap/vid/mso
parent92c875958080d6e3039952b3ea3f8deab704ea51 (diff)
Sending workflow data from UI to SO
Change-Id: I39c78584c61eb317d4eaf2861ece810c1b60ab01 Issue-ID: VID-401 Signed-off-by: Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com>
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/MsoBusinessLogicImplTest.java48
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java44
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTestUtil.java25
3 files changed, 117 insertions, 0 deletions
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 39d777be9..11bf364fb 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
@@ -26,6 +26,9 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import io.joshworks.restclient.http.HttpResponse;
import org.apache.commons.io.IOUtils;
import org.jetbrains.annotations.NotNull;
+import org.mockito.hamcrest.MockitoHamcrest;
+import org.onap.vid.changeManagement.WorkflowRequestDetail;
+import org.onap.vid.controller.ControllersUtils;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -60,12 +63,18 @@ import java.io.IOException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.UUID;
import java.util.stream.Collectors;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+import static org.hamcrest.Matchers.allOf;
+import static org.hamcrest.Matchers.hasEntry;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
@@ -1329,6 +1338,45 @@ public class MsoBusinessLogicImplTest extends AbstractTestNGSpringContextTests {
MsoBusinessLogicImpl.RequestType.fromValue(testValue);
}
+ @Test
+ public void shouldProperlyInvokeVnfWorkflowWithValidParameters() {
+ // given
+ MsoResponseWrapper okResponse = createOkResponse();
+ WorkflowRequestDetail request = createWorkflowRequestDetail();
+ UUID serviceInstanceId = new UUID(1,10);
+ UUID vnfInstanceId = new UUID(2,20);
+ UUID workflow_UUID = new UUID(3,30);
+ String path = "/onap/so/infra/instanceManagement/v1/serviceInstances/"+serviceInstanceId+"/vnfs/"+vnfInstanceId+"/workflows/"+workflow_UUID;
+
+ given(msoInterface.invokeWorkflow(eq(request), eq(path), MockitoHamcrest.argThat(allOf(hasEntry("X-RequestorID", "testRequester"),hasEntry("X-ONAP-PartnerName", "VID"))))).willReturn(okResponse);
+
+ // when
+ MsoResponseWrapper response = msoBusinessLogic.invokeVnfWorkflow(request, "testRequester", serviceInstanceId, vnfInstanceId, workflow_UUID);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(okResponse);
+ }
+
+ private WorkflowRequestDetail createWorkflowRequestDetail() {
+ WorkflowRequestDetail workflowRequestDetail = new WorkflowRequestDetail();
+ org.onap.vid.changeManagement.RequestParameters requestParameters = new org.onap.vid.changeManagement.RequestParameters();
+ HashMap<String,String> paramsMap = new HashMap<>();
+ paramsMap.put("testKey1","testValue1");
+ paramsMap.put("testKey2","testValue2");
+
+ List<Map<String,String>> mapArray= new ArrayList<>();
+ mapArray.add(paramsMap);
+ requestParameters.setUserParams(mapArray);
+
+ CloudConfiguration cloudConfiguration = new CloudConfiguration();
+ cloudConfiguration.setCloudOwner("testOwne");
+ cloudConfiguration.setTenantId("testId");
+ cloudConfiguration.setLcpCloudRegionId("testLcpCloudId");
+
+ workflowRequestDetail.setRequestParameters(requestParameters);
+ workflowRequestDetail.setCloudConfiguration(cloudConfiguration);
+ return workflowRequestDetail;
+ }
private OperationalEnvironmentActivateInfo createTestOperationalEnvironmentActivateInfo() {
OperationalEnvironmentController.OperationalEnvironmentActivateBody operationalEnvironmentActivateBody = new OperationalEnvironmentController.OperationalEnvironmentActivateBody(
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 ff71d85fc..839e6e6c1 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
@@ -21,6 +21,8 @@
package org.onap.vid.mso.rest;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.hamcrest.Matchers.allOf;
+import static org.hamcrest.Matchers.hasEntry;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.ArgumentMatchers.eq;
@@ -33,9 +35,12 @@ import org.apache.http.ProtocolVersion;
import org.apache.http.StatusLine;
import org.apache.http.message.BasicHttpResponse;
import org.apache.http.message.BasicStatusLine;
+import org.jetbrains.annotations.NotNull;
import org.mockito.Mock;
import org.onap.portalsdk.core.util.SystemProperties;
import org.onap.vid.changeManagement.RequestDetailsWrapper;
+import org.onap.vid.changeManagement.RequestParameters;
+import org.onap.vid.changeManagement.WorkflowRequestDetail;
import org.onap.vid.client.SyncRestClient;
import org.onap.vid.controller.LocalWebConfig;
import org.onap.vid.model.RequestReferencesContainer;
@@ -43,12 +48,22 @@ import org.onap.vid.mso.MsoResponseWrapper;
import org.onap.vid.mso.MsoResponseWrapperInterface;
import org.onap.vid.mso.MsoUtil;
import org.onap.vid.mso.RestObject;
+import org.onap.vid.mso.model.CloudConfiguration;
import org.onap.vid.mso.model.RequestReferences;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.web.WebAppConfiguration;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import static org.mockito.ArgumentMatchers.refEq;
+import static org.mockito.hamcrest.MockitoHamcrest.argThat;
+
@ContextConfiguration(classes = {LocalWebConfig.class, SystemProperties.class})
@WebAppConfiguration
@@ -60,6 +75,7 @@ public class MsoRestClientTest {
@Mock
private SyncRestClient client;
+
private MsoRestClientNew restClient;
@@ -748,6 +764,34 @@ public class MsoRestClientTest {
assertThat(expectedResponse).isEqualToComparingFieldByField(response);
}
+ @Test
+ public void shouldProperlyInvokeWorkflows() {
+ // given
+ String endpoint = "testPath";
+ HttpResponse expectedResponse = createOkResponse();
+
+ WorkflowRequestDetail workflowRequestDetail = MsoRestClientTestUtil.createWorkflowRequestDetail();
+
+ RequestDetailsWrapper<WorkflowRequestDetail> requestDetailsWrapper = new RequestDetailsWrapper<>(workflowRequestDetail);
+
+ UUID requestId = UUID.randomUUID();
+
+ when(client.post(eq(baseUrl + endpoint), argThat(allOf(hasEntry("X-ONAP-RequestID", requestId.toString()),hasEntry("Content-Type", "application/json"))), refEq(requestDetailsWrapper))).
+ thenReturn(expectedResponse);
+
+ Map<String,String> extraHeaders = new HashMap<>();
+ extraHeaders.put("X-ONAP-RequestID",requestId.toString());
+ extraHeaders.put("X-ONAP-PartnerName","VID");
+ extraHeaders.put("X-RequestorID","testRequester");
+
+ // when
+ MsoResponseWrapper response = restClient.invokeWorkflow(workflowRequestDetail, endpoint, extraHeaders);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(MsoUtil.wrapResponse(expectedResponse));
+
+ }
+
private class MsoTestException extends RuntimeException{
MsoTestException(String testException) {
super(testException);
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 f10a7f14f..f66235728 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
@@ -37,8 +37,11 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.xebialabs.restito.semantics.Action;
import com.xebialabs.restito.server.StubServer;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Function;
import javax.ws.rs.core.HttpHeaders;
@@ -50,6 +53,7 @@ import org.junit.Assert;
import org.onap.portalsdk.core.util.SystemProperties;
import org.onap.vid.changeManagement.RelatedInstanceList;
import org.onap.vid.changeManagement.RequestDetailsWrapper;
+import org.onap.vid.changeManagement.WorkflowRequestDetail;
import org.onap.vid.mso.MsoResponseWrapper;
import org.onap.vid.mso.model.CloudConfiguration;
import org.onap.vid.mso.model.ModelInfo;
@@ -200,6 +204,27 @@ class MsoRestClientTestUtil implements AutoCloseable {
return requestDetails;
}
+ static WorkflowRequestDetail createWorkflowRequestDetail() {
+ WorkflowRequestDetail workflowRequestDetail = new WorkflowRequestDetail();
+ org.onap.vid.changeManagement.RequestParameters requestParameters = new org.onap.vid.changeManagement.RequestParameters();
+ HashMap<String,String> paramsMap = new HashMap<>();
+ paramsMap.put("testKey1","testValue1");
+ paramsMap.put("testKey2","testValue2");
+
+ List<Map<String,String>> mapArray= new ArrayList<>();
+ mapArray.add(paramsMap);
+ requestParameters.setUserParams(mapArray);
+
+ CloudConfiguration cloudConfiguration = new CloudConfiguration();
+ cloudConfiguration.setCloudOwner("testOwne");
+ cloudConfiguration.setTenantId("testId");
+ cloudConfiguration.setLcpCloudRegionId("testLcpCloudId");
+
+ workflowRequestDetail.setRequestParameters(requestParameters);
+ workflowRequestDetail.setCloudConfiguration(cloudConfiguration);
+ return workflowRequestDetail;
+ }
+
private void verifyServer(StubServer server, String endpoint, Method httpMethod) {
verifyHttp(server).once(
method(httpMethod),