View Interface definition on VFC
[sdc.git] / integration-tests / src / test / java / org / onap / sdc / frontend / ci / tests / execute / sanity / ServiceTemplateDesignUiTests.java
index 79a634e..a2dbd57 100644 (file)
@@ -58,14 +58,15 @@ import org.onap.sdc.frontend.ci.tests.exception.UnzipException;
 import org.onap.sdc.frontend.ci.tests.execute.setup.DriverFactory;
 import org.onap.sdc.frontend.ci.tests.execute.setup.ExtentTestActions;
 import org.onap.sdc.frontend.ci.tests.execute.setup.SetupCDTest;
+import org.onap.sdc.frontend.ci.tests.flow.AddComponentInputFlow;
 import org.onap.sdc.frontend.ci.tests.flow.AddComponentPropertyFlow;
 import org.onap.sdc.frontend.ci.tests.flow.AddNodeToCompositionFlow;
 import org.onap.sdc.frontend.ci.tests.flow.CreateDirectiveNodeFilterFlow;
 import org.onap.sdc.frontend.ci.tests.flow.CreateSubstitutionFilterFlow;
 import org.onap.sdc.frontend.ci.tests.flow.CreateVfFlow;
 import org.onap.sdc.frontend.ci.tests.flow.CreateVfcFlow;
-import org.onap.sdc.frontend.ci.tests.flow.DownloadCsarArtifactFlow;
 import org.onap.sdc.frontend.ci.tests.flow.DownloadToscaTemplateFlow;
+import org.onap.sdc.frontend.ci.tests.flow.DownloadCsarArtifactFlow;
 import org.onap.sdc.frontend.ci.tests.flow.EditComponentPropertiesFlow;
 import org.onap.sdc.frontend.ci.tests.flow.composition.CreateRelationshipFlow;
 import org.onap.sdc.frontend.ci.tests.flow.exception.UiTestFlowRuntimeException;
@@ -77,7 +78,7 @@ import org.onap.sdc.frontend.ci.tests.pages.ResourcePropertiesPage;
 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionDetailSideBarComponent;
 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionDetailSideBarComponent.CompositionDetailTabName;
 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionInformationTab;
-import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionInterfaceOperationsModal;
+import org.onap.sdc.frontend.ci.tests.pages.component.workspace.InterfaceDefinitionOperationsModal;
 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionInterfaceOperationsTab;
 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionPage;
 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.RelationshipWizardInterfaceOperation.InterfaceOperationsData;
@@ -108,6 +109,7 @@ public class ServiceTemplateDesignUiTests extends SetupCDTest {
     private ComponentPage componentPage;
     private Map<String, String> propertiesToBeAddedMap;
     private ResourceCreatePage resourceCreatePage;
+    private Map<String, String> inputsToBeAddedMap;
     private final List<ServiceDependencyProperty> substitutionFilterProperties = new ArrayList<>();
     private final String interfaceName = "Standard";
     private final String interfaceOperationName = "create";
@@ -167,6 +169,28 @@ public class ServiceTemplateDesignUiTests extends SetupCDTest {
         downloadAndVerifyCsarPackage(componentPage);
     }
 
+    @Test(dependsOnMethods = "addRelationshipTemplate")
+    public void createMetadataForServiceProperty() throws Exception {
+        homePage.isLoaded();
+        componentPage = (ComponentPage) homePage.clickOnComponent(vfResourceCreateData.getName());
+        componentPage.isLoaded();
+        final ResourcePropertiesAssignmentPage propertiesAssignmentPage = componentPage.goToPropertiesAssignment();
+
+        propertiesAssignmentPage.isLoaded();
+        propertiesAssignmentPage.selectInputTab();
+        final var propertyName = propertiesAssignmentPage.getInputPropertyNames().get(0);
+        final var key = "Key";
+        final var value = "Test";
+        propertiesAssignmentPage.setInputPropertyMetadata(propertyName, key, value);
+
+        final var topologyTemplate = getMapEntry(downloadToscaTemplate(), "topology_template");
+        final var inputs = getMapEntry(topologyTemplate, "inputs");
+        final var serviceProperty = getMapEntry(inputs, propertyName);
+        final var servicePropertyMetadata = getMapEntry(serviceProperty, "metadata");
+        assertNotNull(servicePropertyMetadata, String.format("Metadata not found for property %s", propertyName));
+        assertEquals(servicePropertyMetadata.get(key), value, "Created service property metadata has invalid value");
+    }
+
     @Test(dependsOnMethods = "addRelationshipTemplate")
     public void addOutputsToVF_test() throws UnzipException, IOException {
         homePage.isLoaded();
@@ -223,8 +247,8 @@ public class ServiceTemplateDesignUiTests extends SetupCDTest {
         compositionPage.isLoaded();
         ExtentTestActions.addScreenshot(Status.INFO, "select-VFC-node", "Selecting Node on composition");
         compositionPage.selectNode(vfcs.get(1).getName());
-        final CompositionInterfaceOperationsModal.InterfaceOperationsData interfaceOperationsData =
-            new CompositionInterfaceOperationsModal.InterfaceOperationsData("IT for updating an Interface Operation",
+        final InterfaceDefinitionOperationsModal.InterfaceOperationsData interfaceOperationsData =
+            new InterfaceDefinitionOperationsModal.InterfaceOperationsData("IT for updating an Interface Operation",
                 "MyIntegrationTestImplementationName", "My_IT_InputName", "My_IT_InputValue");
         updateInterfaceOperation(compositionPage, interfaceOperationsData);
         componentPage = compositionPage.goToGeneral();
@@ -260,8 +284,10 @@ public class ServiceTemplateDesignUiTests extends SetupCDTest {
         componentPage.isLoaded();
         final ResourcePropertiesPage vfcPropertiesPage = componentPage.goToProperties();
         vfcPropertiesPage.isLoaded();
-        final List<String> propertyNames = vfcPropertiesPage.getPropertyNames();
-        final ServiceDependencyProperty serviceDependencyProperty = new ServiceDependencyProperty(propertyNames.get(0), value, operator);
+        final Map<String, String> propertyNamesAndTypes = vfcPropertiesPage.getPropertyNamesAndTypes();
+        final List<String> propertyNames = propertyNamesAndTypes.keySet().stream().collect(Collectors.toList());
+        final ServiceDependencyProperty serviceDependencyProperty =
+                new ServiceDependencyProperty(propertyNames.get(0), propertyNamesAndTypes.get(propertyNames.get(0)), value, operator);
 
         homePage.getTopNavComponent().clickOnHome();
         homePage.isLoaded();
@@ -286,6 +312,26 @@ public class ServiceTemplateDesignUiTests extends SetupCDTest {
         verifyToscaTemplateHasDirectiveNodeFilter(yaml, serviceDependencyProperty, vfcNameInComposition);
     }
 
+    @Test(dependsOnMethods = "addComponentProperty")
+    public void declareInputFromProperties() throws Exception {
+        componentPage = (ComponentPage) homePage.clickOnComponent(vfResourceCreateData.getName());
+        componentPage.isLoaded();
+
+        ResourcePropertiesAssignmentPage propertiesAssignmentPage = componentPage.goToPropertiesAssignment();
+        propertiesAssignmentPage.isLoaded();
+
+        declareInputToBaseService(propertiesAssignmentPage, "property1");
+        declareInputToInstanceProperties(propertiesAssignmentPage, "resourceSubtype");
+        verifyToscaTemplateHasDeclareInput(downloadToscaTemplate());
+    }
+
+    @Test(dependsOnMethods = "createBaseService")
+    public void addComponentInputs() throws Exception {
+        inputsToBeAddedMap = loadInputsToAdd();
+        addInput(inputsToBeAddedMap);
+        verifyToscaTemplateAddInput(downloadToscaTemplate());
+    }
+
     private void checkMetadata(final Map<String, Object> map, final ResourceCreateData createdData) {
         final Map<String, Object> metadata = getMapEntry(map, "metadata");
 
@@ -328,7 +374,7 @@ public class ServiceTemplateDesignUiTests extends SetupCDTest {
      * @throws IOException
      */
     private void updateInterfaceOperation(final CompositionPage compositionPage,
-        final CompositionInterfaceOperationsModal.InterfaceOperationsData interfaceOperationsData) throws IOException {
+        final InterfaceDefinitionOperationsModal.InterfaceOperationsData interfaceOperationsData) throws IOException {
         final CompositionDetailSideBarComponent detailSideBar = compositionPage.getDetailSideBar();
         detailSideBar.isLoaded();
         final CompositionInterfaceOperationsTab compositionInterfaceOperationsTab =
@@ -337,7 +383,7 @@ public class ServiceTemplateDesignUiTests extends SetupCDTest {
         ExtentTestActions.takeScreenshot(Status.INFO, "compositionInterfaceOperationsTab",
             "Composition Interface Operations Tab loaded");
         assertTrue(compositionInterfaceOperationsTab.isOperationPresent(interfaceOperationName));
-        final CompositionInterfaceOperationsModal compositionInterfaceOperationsModal = compositionInterfaceOperationsTab
+        final InterfaceDefinitionOperationsModal compositionInterfaceOperationsModal = compositionInterfaceOperationsTab
             .clickOnOperation(interfaceOperationName);
         compositionInterfaceOperationsModal.isLoaded();
         ExtentTestActions.takeScreenshot(Status.INFO, "update-interface-operation-modal", "Loading Interface Operations Modal");
@@ -359,13 +405,13 @@ public class ServiceTemplateDesignUiTests extends SetupCDTest {
      * @param interfaceOperationsData The Updated Interface Definition
      */
     private void validateUpdatedInterfaceOperation(final CompositionDetailSideBarComponent detailSideBar,
-                                                   final CompositionInterfaceOperationsModal.InterfaceOperationsData interfaceOperationsData) {
+                                                   final InterfaceDefinitionOperationsModal.InterfaceOperationsData interfaceOperationsData) {
         final CompositionInterfaceOperationsTab compositionInterfaceOperationsTab = (CompositionInterfaceOperationsTab) detailSideBar
             .selectTab(CompositionDetailTabName.INTERFACE_OPERATIONS);
         compositionInterfaceOperationsTab.isLoaded();
         assertTrue(compositionInterfaceOperationsTab.isOperationPresent(interfaceOperationName));
         assertTrue(compositionInterfaceOperationsTab.isDescriptionPresent());
-        final CompositionInterfaceOperationsModal compositionInterfaceOperationsModal = compositionInterfaceOperationsTab
+        final InterfaceDefinitionOperationsModal compositionInterfaceOperationsModal = compositionInterfaceOperationsTab
             .clickOnOperation(interfaceOperationName);
         compositionInterfaceOperationsModal.isLoaded();
         ExtentTestActions.takeScreenshot(Status.INFO, "validate-updated-interface-operation",
@@ -382,7 +428,7 @@ public class ServiceTemplateDesignUiTests extends SetupCDTest {
     }
 
     private void verifyToscaTemplateHasUpdatedInterfaceOperation(final Map<?, ?> toscaTemplateYaml,
-        final CompositionInterfaceOperationsModal.InterfaceOperationsData interfaceOperationsData) {
+        final InterfaceDefinitionOperationsModal.InterfaceOperationsData interfaceOperationsData) {
 
         assertNotNull(toscaTemplateYaml, "No contents in TOSCA Template");
         final Map<String, Object> topologyTemplateTosca = getMapEntry((Map<String, Object>) toscaTemplateYaml, "topology_template");
@@ -431,6 +477,23 @@ public class ServiceTemplateDesignUiTests extends SetupCDTest {
         return loadYamlObject(filesFromZip.get(resourceEntryOpt.get()));
     }
 
+    private void declareInputToBaseService(ResourcePropertiesAssignmentPage propertiesAssignmentPage, String propertyName){
+        propertiesAssignmentPage.selectProperty(propertyName);
+        propertiesAssignmentPage.clickOnDeclareInput();
+        propertiesAssignmentPage.clickInputTab(propertyName);
+        propertiesAssignmentPage.isInputPresent(vfResourceCreateData.getName() + "_" + propertyName);
+    }
+
+    private void declareInputToInstanceProperties(ResourcePropertiesAssignmentPage propertiesAssignmentPage, String propertyName){
+        propertiesAssignmentPage.selectPropertiesTab();
+        propertiesAssignmentPage.loadCompositionTab();
+        propertiesAssignmentPage.loadComponentInstanceProperties(vfcs.get(0).getName().concat(" 0"));
+        propertiesAssignmentPage.selectProperty(propertyName);
+        propertiesAssignmentPage.clickOnDeclareInput();
+        propertiesAssignmentPage.clickInputTab(propertyName);
+        propertiesAssignmentPage.isInputPresent(vfResourceCreateData.getName() + "_" + vfcs.get(0).getName());
+    }
+
     private CreateVfFlow createVF() {
         final ResourceCreateData vfCreateData = createVfFormData();
         final CreateVfFlow createVfFlow = new CreateVfFlow(webDriver, vfCreateData);
@@ -549,6 +612,17 @@ public class ServiceTemplateDesignUiTests extends SetupCDTest {
         addComponentPropertyFlow.run(componentPage.goToPropertiesAssignment());
     }
 
+    /**
+     * Adds a input to the base service
+     * @param inputMap map of inputs to be added
+     */
+    private void addInput(final Map<String, String> inputMap) {
+        componentPage = (ComponentPage) homePage.clickOnComponent(vfResourceCreateData.getName());
+        componentPage.isLoaded();
+        final AddComponentInputFlow addComponentInputFlow = new AddComponentInputFlow(webDriver, inputMap);
+        addComponentInputFlow.run(componentPage.goToPropertiesAssignment());
+    }
+
     /**
      * Edits a property to add a value
      * @param propertyMap map of properties to be edited
@@ -718,7 +792,40 @@ public class ServiceTemplateDesignUiTests extends SetupCDTest {
         return expectedDefinitionFolderFileList;
     }
 
-    private Map<String, Object> getMapEntry(final Map<String, Object> yamlObj, final String entryName) {
+    private void verifyToscaTemplateHasDeclareInput(Map<?, ?> yaml) {
+        assertNotNull(yaml, "No contents in TOSCA Template");
+        final Map<String, Object> toscaYaml = (Map<String, Object>) yaml;
+        final Map<String, Object> topologyTemplateTosca = getMapEntry(toscaYaml, "topology_template");
+        assertThat(String.format("'%s' should contain a topology_template entry", toscaYaml), topologyTemplateTosca,
+            notNullValue());
+        final Map<String, Object> inputsTosca = getMapEntry(topologyTemplateTosca, "inputs");
+        assertThat(String.format("'%s' should contain a inputs entry", toscaYaml), inputsTosca, notNullValue());
+        assertEquals(2, inputsTosca.keySet().stream()
+            .filter(s -> (s.contains("resourceSubtype") || s.contains("property1"))).count());
+        final Map<String, Object> substitutionMapping = getMapEntry(topologyTemplateTosca, "substitution_mappings");
+        assertThat(String.format("'%s' should contain a substitution_mappings entry", toscaYaml), substitutionMapping,
+            notNullValue());
+        final Map<String, Object> substitutionMappingProperties = getMapEntry(substitutionMapping, "properties");
+        assertThat(String.format("'%s' should contain a properties entry", toscaYaml), substitutionMappingProperties,
+            notNullValue());
+        assertEquals(2, substitutionMappingProperties.keySet().stream()
+            .filter(s -> (s.contains("resourceSubtype") || s.contains("property1"))).count());
+    }
+
+    private void verifyToscaTemplateAddInput(Map<?, ?> yaml) {
+        final Map<String, String> inputMap = loadInputsToAdd();
+        assertNotNull(yaml, "No contents in TOSCA Template");
+        final Map<String, Object> toscaYaml = (Map<String, Object>) yaml;
+        final Map<String, Object> topologyTemplateTosca = getMapEntry(toscaYaml, "topology_template");
+        assertThat(String.format("'%s' should contain a topology_template entry", toscaYaml), topologyTemplateTosca,
+            notNullValue());
+        final Map<String, Object> inputsTosca = getMapEntry(topologyTemplateTosca, "inputs");
+        assertThat(String.format("'%s' should contain a inputs entry", toscaYaml), inputsTosca, notNullValue());
+        assertEquals(3, inputsTosca.keySet().stream()
+            .filter(s -> inputMap.containsKey(s)).count());
+    }
+
+    private Map<String, Object> getMapEntry(final Map<?, ?> yamlObj, final String entryName) {
         try {
             return (Map<String, Object>) yamlObj.get(entryName);
         } catch (final Exception e) {
@@ -759,6 +866,14 @@ public class ServiceTemplateDesignUiTests extends SetupCDTest {
         return propertyMap;
     }
 
+    private Map<String, String> loadInputsToAdd() {
+        final Map<String, String> inputMap = new HashMap<>();
+        inputMap.put("input1", "string");
+        inputMap.put("input2", "integer");
+        inputMap.put("input3", "boolean");
+        return inputMap;
+    }
+
     private void loadSubstitutionFilterProperties() {
         final ResourcePropertiesAssignmentPage propertiesPage = componentPage.goToPropertiesAssignment();
         propertiesPage.isLoaded();
@@ -768,7 +883,7 @@ public class ServiceTemplateDesignUiTests extends SetupCDTest {
         assertThat(String.format("The Component '%s' should have properties", vfResourceCreateData.getName()), propertyNamesAndTypes,
             not(anEmptyMap()));
         propertyNamesAndTypes.forEach((name, type)
-            -> substitutionFilterProperties.add(new ServiceDependencyProperty(name, getPropertyValueByType(type), LogicalOperator.EQUALS)));
+            -> substitutionFilterProperties.add(new ServiceDependencyProperty(name, type, getPropertyValueByType(type), LogicalOperator.EQUALS)));
     }
 
     private String getPropertyValueByType(final String type) {
@@ -782,9 +897,9 @@ public class ServiceTemplateDesignUiTests extends SetupCDTest {
             case "boolean":
                 return "TRUE";
             case "list":
-                return "[value1, value2]";
+                return "[\"value1\", \"value2\"]";
             case "map":
-                return "MyKey: MyValue";
+                return "{\"MyKey\": \"MyValue\"}";
             default:
                 throw new UnsupportedOperationException("Not yet implemented for " + type);
         }
@@ -812,7 +927,7 @@ public class ServiceTemplateDesignUiTests extends SetupCDTest {
                 substitutionFilterMap.containsKey(substitutionFilterProperty.getName()));
             final Map<?, ?> substitutionFilterValue = (Map<?, ?>) ((List<?>) substitutionFilterMap.get(substitutionFilterProperty.getName())).get(0);
             assertThat("Substitution Filter Value should not be empty", substitutionFilterMap, not(anEmptyMap()));
-            final String expectedSubstitutionPropertyValue = substitutionFilterProperty.getValue();
+            final String expectedSubstitutionPropertyValue = substitutionFilterProperty.getValue().replaceAll("[\"{}]", "");
             final String actualSubstitutionPropertyValue = substitutionFilterValue.values().stream().findFirst().get() instanceof Map
                 ? substitutionFilterValue.values().stream().findFirst().get().toString().replace("=", ": ")
                 .replaceAll("\\{(.*?)\\}", "$1").trim()