change management integration with reduce flag
[vid.git] / vid-automation / src / main / java / vid / automation / test / test / ChangeManagementTest.java
index 4da713a..7c577ca 100644 (file)
@@ -1,11 +1,15 @@
 package vid.automation.test.test;
 
 
+import static java.util.Collections.emptyMap;
+import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals;
+import static org.apache.commons.lang3.exception.ExceptionUtils.rethrow;
 import static org.hamcrest.CoreMatchers.containsString;
 import static org.hamcrest.CoreMatchers.everyItem;
 import static org.hamcrest.CoreMatchers.hasItem;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.CoreMatchers.startsWith;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.greaterThan;
 import static org.hamcrest.collection.IsEmptyCollection.empty;
@@ -15,21 +19,28 @@ import static org.onap.vid.api.BaseApiTest.getResourceAsString;
 import static vid.automation.test.infra.Features.FLAG_FLASH_REDUCED_RESPONSE_CHANGEMG;
 import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.APPEND;
 
+import com.aventstack.extentreports.Status;
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.primitives.Ints;
+import java.io.IOException;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
+import net.javacrumbs.jsonunit.core.Option;
 import org.json.JSONException;
 import org.junit.Assert;
 import org.onap.sdc.ci.tests.datatypes.UserCredentials;
+import org.onap.sdc.ci.tests.execute.setup.ExtentTestActions;
 import org.onap.sdc.ci.tests.utilities.GeneralUIUtils;
 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubscribersGet;
+import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetTenants;
 import org.onap.simulator.presetGenerator.presets.aai.PresetBaseAAICustomQuery;
 import org.onap.simulator.presetGenerator.presets.scheduler.PresetDeleteSchedulerChangeManagement;
 import org.openqa.selenium.JavascriptExecutor;
@@ -38,6 +49,7 @@ import org.openqa.selenium.remote.RemoteWebElement;
 import org.openqa.selenium.support.ui.Select;
 import org.skyscreamer.jsonassert.JSONAssert;
 import org.skyscreamer.jsonassert.JSONCompareMode;
+import org.testng.ITestResult;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeClass;
@@ -60,6 +72,7 @@ import vid.automation.test.utils.DB_CONFIG;
 public class ChangeManagementTest extends VidBaseTestCase {
 
     public static final String SCHEDULED_ID = "0b87fe60-50b0-4bac-a0a7-49e951b0ba9e";
+    private final String SCHEDULE_ERROR_PREFIX = "Portal not found. Cannot send: ";
 
     @Test
     public void testLeftPanelChangeManagementButton() {
@@ -81,7 +94,15 @@ public class ChangeManagementTest extends VidBaseTestCase {
         Assert.assertTrue(Exists.byId(Constants.ChangeManagement.newModalSubscriberInputId));
         Assert.assertTrue(Exists.byId(Constants.ChangeManagement.newModalServiceTypeInputId));
         Assert.assertTrue(Exists.byId(Constants.ChangeManagement.newModalVNFNameInputId));
-        Assert.assertTrue(Exists.byId(Constants.ChangeManagement.newModalVNFTypeInputId));
+
+        if (Features.FLAG_FLASH_CLOUD_REGION_AND_NF_ROLE_OPTIONAL_SEARCH.isActive()) {
+            Assert.assertTrue(Exists.byId(Constants.ChangeManagement.newModalVNFTypeInputId1));
+            Assert.assertTrue(Exists.byId(Constants.ChangeManagement.newModalVNFCloudRegion));
+            Assert.assertTrue(Exists.byId(Constants.ChangeManagement.newModalVNFSearchVNF));
+        } else {
+            Assert.assertTrue(Exists.byId(Constants.ChangeManagement.newModalVNFTypeInputId));
+        }
+
         Assert.assertTrue(Exists.byId(Constants.ChangeManagement.newModalFromVNFVersionInputId));
         Assert.assertTrue(Exists.byId(Constants.ChangeManagement.newModalWorkFlowInputId));
         Assert.assertTrue(Exists.byId(Constants.generalSubmitButtonId));
@@ -93,6 +114,7 @@ public class ChangeManagementTest extends VidBaseTestCase {
         String subscriberName = VNF_DATA_WITH_IN_PLACE.subscriberName;
         String serviceType = VNF_DATA_WITH_IN_PLACE.serviceType;
         String vnfType = VNF_DATA_WITH_IN_PLACE.vnfType;
+        String cloudRegion = VNF_DATA_WITH_IN_PLACE.cloudRegion;
         String vnfSourceVersion = VNF_DATA_WITH_IN_PLACE.vnfSourceVersion;
         ChangeManagementPage.openNewChangeManagementModal();
         Wait.angularHttpRequestsLoaded();
@@ -103,8 +125,15 @@ public class ChangeManagementTest extends VidBaseTestCase {
         SelectOption.byIdAndVisibleText(Constants.ChangeManagement.newModalServiceTypeInputId, serviceType);
         Wait.angularHttpRequestsLoaded();
 
-        SelectOption.byIdAndVisibleText(Constants.ChangeManagement.newModalVNFTypeInputId, vnfType);
+        if (Features.FLAG_FLASH_CLOUD_REGION_AND_NF_ROLE_OPTIONAL_SEARCH.isActive()) {
+            Input.text(vnfType, Constants.ChangeManagement.newModalVNFTypeInputId);
+            SelectOption.byIdAndVisibleText(Constants.ChangeManagement.newModalVNFCloudRegion, cloudRegion);
+            Click.byId(Constants.ChangeManagement.newModalVNFSearchVNF);
+        } else {
+            SelectOption.byIdAndVisibleText(Constants.ChangeManagement.newModalVNFTypeInputId, vnfType);
+        }
         Wait.angularHttpRequestsLoaded();
+
         SelectOption.byIdAndVisibleText(Constants.ChangeManagement.newModalFromVNFVersionInputId, vnfSourceVersion);
         Wait.angularHttpRequestsLoaded();
         Click.byId(Constants.ChangeManagement.newModalVNFNameInputId);
@@ -147,6 +176,7 @@ public class ChangeManagementTest extends VidBaseTestCase {
         static String subscriberName = "Emanuel";
         static String serviceType = "vRichardson";
         static String vnfType = "vMobileDNS";
+        static String cloudRegion = "AAIAIC25 (AIC)";
         static String vnfSourceVersion = "1.0";
         static String vnfName = "zolson3amdns02test2";
         static String vnfTargetVersion = "5.0";
@@ -198,18 +228,30 @@ public class ChangeManagementTest extends VidBaseTestCase {
             String globalCustomerId = "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb";
             String serviceType = "vRichardson";
             SimulatorApi.registerExpectationFromPreset(new PresetBaseAAICustomQuery(
-                SIMPLE,
-                "/business/customers/customer/" + globalCustomerId + "/service-subscriptions/service-subscription/"
-                    + serviceType + "/service-instances",
-                "query/vnfs-fromServiceInstance-filter"
+                    SIMPLE,
+                    "/business/customers/customer/" + globalCustomerId + "/service-subscriptions/service-subscription/"
+                            + serviceType + "/service-instances",
+                    "query/vnfs-fromServiceInstance-filterByCloudRegion?nfRole=vMobileDNS&cloudRegionID=092eb9e8e4b7412e8787dd091bc58e86"
             ) {
                 @Override
                 public Object getResponseBody() {
                     return getResourceAsString(
-                        AAI_VNFS_FOR_CHANGE_MANAGEMENT_JSON_BY_PARAMS);
+                            AAI_VNFS_FOR_CHANGE_MANAGEMENT_JSON_BY_PARAMS);
                 }
             }, APPEND);
         }
+
+
+        SimulatorApi.registerExpectationFromPreset(new PresetAAIGetSubscribersGet(), SimulatorApi.RegistrationStrategy.APPEND);
+
+        if (Features.FLAG_FLASH_CLOUD_REGION_AND_NF_ROLE_OPTIONAL_SEARCH.isActive()) {
+            SimulatorApi.registerExpectationFromPreset(new PresetAAIGetTenants(
+                    VNF_DATA_WITH_IN_PLACE.subscriberId,
+                    VNF_DATA_WITH_IN_PLACE.serviceType,
+                    "presets_templates/PresetAAIGetTenants_service_type_vWINIFRED.json"), SimulatorApi.RegistrationStrategy.APPEND);
+
+        }
+
         registerDefaultTablesData();
         resetGetServicesCache();
     }
@@ -323,6 +365,7 @@ public class ChangeManagementTest extends VidBaseTestCase {
         GeneralUIUtils.ultimateWait();
         WebElement cancelPendingConfirmationMessage = Get.byTestId("btn-cancel-workflow");
         assertThat(cancelPendingConfirmationMessage.getText(), containsString("Are you sure you want to delete workflow"));
+        screenshot("delete workflow");
     }
 
     private void clickAndAssertClickOnCancelWorkflowButtonOnPendingPopUp() {
@@ -336,6 +379,7 @@ public class ChangeManagementTest extends VidBaseTestCase {
                 Click.byClass("pull-right modal-close");
             }
         }
+        screenshot("cancel workflow");
         Click.byClassAndVisibleText("btn", "OK");
     }
 
@@ -379,7 +423,10 @@ public class ChangeManagementTest extends VidBaseTestCase {
     }
 
     @AfterMethod(alwaysRun = true)
-    public void closeForm() {
+    public void screenshotAndCloseForm(ITestResult testResult) {
+
+        screenshot(testResult.getName() + (testResult.isSuccess() ? "" : " FAIL"));
+
         // Tries closing left-out popups, if any
         // If none -- catch clause will swallow the exception
         try {
@@ -392,6 +439,14 @@ public class ChangeManagementTest extends VidBaseTestCase {
         Wait.modalToDisappear();
     }
 
+    protected void screenshot(String testName) {
+        try {
+            ExtentTestActions.addScreenshot(Status.INFO, "ChangeManagementTest." + testName, testName);
+        } catch (IOException e) {
+            rethrow(e);
+        }
+    }
+
     @Test
     public void testWorkflowVNFInPlaceSoftwareUpdateShows3Fields() {
 
@@ -484,10 +539,33 @@ public class ChangeManagementTest extends VidBaseTestCase {
         };
     }
 
-    // Deleted testVidToMsoCallbackDataWithInPlaceSWUpdate test. It was using assertThatVidToMsoCallbackDataIsOk which is no longer valid.
+    @Test(dataProvider = "dataForUpdateWorkflowPartialWithInPlace")
+    public void testVidToMsoCallbackDataWithInPlaceSWUpdate(String operationsTimeout, String existingSwVersion, String newSwVersion) {
 
+        openAndFill1stScreenWithWorkflowVNFInPlaceSoftwareUpdate();
+        fillVNFInPlace3Fields(operationsTimeout, existingSwVersion, newSwVersion);
+
+        assertThatVidToPortalCallbackDataIsOk(VNF_DATA_WITH_IN_PLACE.workflowName, ImmutableMap.of(
+                "existingSoftwareVersion", existingSwVersion,
+                "newSoftwareVersion", newSwVersion,
+                "operationTimeout", operationsTimeout
+        ));
+    }
+
+    @Test
+    public void testUploadConfigUpdateFile() {
+        String fileName = "configuration_file.csv";
+        updateConfigFile(fileName);
+        Assert.assertEquals(Get.byId(Constants.ChangeManagement.newModalConfigUpdateInputId + "-label").getText(), fileName);
+        Assert.assertTrue(Get.byId(Constants.generalSubmitButtonId).isEnabled());
+        assertThatVidToPortalCallbackDataIsOk("VNF Config Update", ImmutableMap.of(
+                "configUpdateFile",
+                "{\"request-parameters\":{\"vm\":[{\"vnfc\":["
+                        + "{\"vnfc-name\":\"ibcx0001vm001dbg001\",\"vnfc-function-code\":\"dbg\"}],\"vm-name\":\"ibcx0001vm001\"},"
+                        + "{\"vnfc\":[{\"vnfc-name\":\"ibcx0001vm002dbg001\"}],\"vm-name\":\"ibcx0001vm002\"}]},\"configuration-parameters\":{\"node0_hostname\":\"dbtx0001vm001\"}}"
+        ));
+    }
 
-    // Deleted testUploadConfigUpdateFile test. It was using assertThatVidToMsoCallbackDataIsOk which is no longer valid.
     @FeatureTogglingTest(value = Features.FLAG_FLASH_CLOUD_REGION_AND_NF_ROLE_OPTIONAL_SEARCH, flagActive = false)
     @Test
     public void testUploadConfigUpdateNonCsvFile() {
@@ -516,7 +594,14 @@ public class ChangeManagementTest extends VidBaseTestCase {
         };
     }
 
-    // Deleted testVidToMsoCallbackData test. It was using assertThatVidToMsoCallbackDataIsOk which is no longer valid.
+    @Test
+    public void testVidToMsoCallbackData() {
+        String workflow = "Replace";
+
+        openAndFill1stScreen(VNF_DATA_WITH_IN_PLACE.vnfName, VNF_DATA_WITH_IN_PLACE.vnfTargetVersion, workflow);
+
+        assertThatVidToPortalCallbackDataIsOk(workflow, emptyMap());
+    }
 
     private void assertThatVidToMsoCallbackDataIsOk(String workflow, String payload) {
         Assert.assertTrue(Get.byId(Constants.generalSubmitButtonId).isEnabled());
@@ -537,6 +622,43 @@ public class ChangeManagementTest extends VidBaseTestCase {
         Click.byId(Constants.generalCancelButtonId);
     }
 
+    private void assertThatVidToPortalCallbackDataIsOk(String workflowName, Map<String, String> workflowParams) {
+        screenshot("submit to scheduler");
+        Assert.assertTrue(Get.byId(Constants.generalSubmitButtonId).isEnabled());
+        Click.byId(Constants.generalSubmitButtonId);
+
+        String errorMessage = GeneralUIUtils.getWebElementByTestID("error-message", 2).getText();
+
+        String modelInvariantId = "72e465fe-71b1-4e7b-b5ed-9496118ff7a8";
+        String vnfInstanceId = "8e5e3ba1-3fe6-4d86-966e-f9f03dab4855";
+
+        assertThat(errorMessage, startsWith(SCHEDULE_ERROR_PREFIX));
+        assertThat(errorMessage.replace(SCHEDULE_ERROR_PREFIX, ""), jsonEquals(
+                ImmutableMap.of(
+                        "widgetName", "Portal-Common-Scheduler",
+                        "widgetParameter", "",
+                        "widgetData", ImmutableMap.builder()
+                                .put("vnfNames", ImmutableList.of(ImmutableMap.of(
+                                        "id", vnfInstanceId,
+                                        "invariant-id", modelInvariantId
+                                )))
+                                .put("workflowParameters", emptyMap())
+                                .put("subscriberId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb")
+                                .put("fromVNFVersion", "" + "76e908e0-5201-44d2-a3e2-9e6128d05820" + "")
+                                .put("workflow", "" + workflowName + "")
+                                .put("policyYN", "Y")
+                                .put("sniroYN", "Y")
+                                .put("testApi", "VNF_API")
+                                .put("vnfType", "vMobileDNS")
+                                .putAll(workflowParams)
+                                .build()
+                )
+        ).when(Option.IGNORING_EXTRA_FIELDS));
+
+
+        Click.byId(Constants.generalCancelButtonId);
+    }
+
     @Test(enabled = false)
     public void testUpdateWorkflowNow() {
 
@@ -705,7 +827,7 @@ public class ChangeManagementTest extends VidBaseTestCase {
         Wait.modalToDisappear();
     }
 
-    @Test(enabled = false)
+    @Test
     public void testSuccessCancelPendingWorkflow() {
         ChangeManagementPage.openChangeManagementPage();
         Wait.angularHttpRequestsLoaded();
@@ -715,6 +837,7 @@ public class ChangeManagementTest extends VidBaseTestCase {
         Assert.assertTrue(Exists.modal());
         Assert.assertTrue(Exists.byId(Constants.ChangeManagement.pendingModalHeaderId));
         Assert.assertTrue(Exists.byClass(Constants.ChangeManagement.pendingModalCancelWorkflowButtonClass));
+        screenshot("pendingModalCancelWorkflow");
         Click.byClass(Constants.ChangeManagement.pendingModalCancelWorkflowButtonClass);
         Wait.angularHttpRequestsLoaded();
 
@@ -722,6 +845,7 @@ public class ChangeManagementTest extends VidBaseTestCase {
         Assert.assertTrue(Exists.modal());
         Assert.assertTrue(Exists.byId(Constants.ChangeManagement.alertModalHeaderId));
         Assert.assertTrue(Exists.byClassAndText(Constants.generalModalTitleClass, "Success"));
+        screenshot("successCancelWorkflow");
         Click.byClass(Constants.generalCloseModalButtonClass);
         Wait.modalToDisappear();
         //TODO check the workflow deleted from table/changed to deleted action