Support for multiple directives
[sdc.git] / integration-tests / src / test / java / org / onap / sdc / frontend / ci / tests / execute / sanity / ServiceTemplateDesignUiTests.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 Nordix Foundation
4  *  ================================================================================
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  *
16  *  SPDX-License-Identifier: Apache-2.0
17  *  ============LICENSE_END=========================================================
18  */
19
20 package org.onap.sdc.frontend.ci.tests.execute.sanity;
21
22 import static org.hamcrest.MatcherAssert.assertThat;
23 import static org.hamcrest.Matchers.anEmptyMap;
24 import static org.hamcrest.Matchers.empty;
25 import static org.hamcrest.Matchers.emptyString;
26 import static org.hamcrest.Matchers.equalToIgnoringCase;
27 import static org.hamcrest.Matchers.hasSize;
28 import static org.hamcrest.Matchers.is;
29 import static org.hamcrest.Matchers.not;
30 import static org.hamcrest.Matchers.notNullValue;
31 import static org.junit.jupiter.api.Assertions.assertEquals;
32 import static org.junit.jupiter.api.Assertions.assertNotEquals;
33 import static org.junit.jupiter.api.Assertions.assertNotNull;
34 import static org.junit.jupiter.api.Assertions.assertTrue;
35 import static org.junit.jupiter.api.Assertions.fail;
36
37 import java.io.IOException;
38 import java.util.ArrayList;
39 import java.util.Arrays;
40 import java.util.HashMap;
41 import java.util.List;
42 import java.util.Map;
43 import java.util.Map.Entry;
44 import java.util.Optional;
45 import java.util.stream.Collectors;
46
47 import org.onap.sdc.backend.ci.tests.data.providers.OnboardingDataProviders;
48 import org.onap.sdc.backend.ci.tests.datatypes.enums.ComponentType;
49 import org.onap.sdc.backend.ci.tests.datatypes.enums.ResourceCategoryEnum;
50 import org.onap.sdc.backend.ci.tests.utils.general.ElementFactory;
51 import org.onap.sdc.frontend.ci.tests.datatypes.ComponentData;
52 import org.onap.sdc.frontend.ci.tests.datatypes.DirectiveType;
53 import org.onap.sdc.frontend.ci.tests.datatypes.LogicalOperator;
54 import org.onap.sdc.frontend.ci.tests.datatypes.ResourceCreateData;
55 import org.onap.sdc.frontend.ci.tests.datatypes.ServiceDependencyProperty;
56 import org.onap.sdc.frontend.ci.tests.datatypes.composition.RelationshipInformation;
57 import org.onap.sdc.frontend.ci.tests.exception.UnzipException;
58 import org.onap.sdc.frontend.ci.tests.execute.setup.DriverFactory;
59 import org.onap.sdc.frontend.ci.tests.execute.setup.ExtentTestActions;
60 import org.onap.sdc.frontend.ci.tests.execute.setup.SetupCDTest;
61 import org.onap.sdc.frontend.ci.tests.flow.AddComponentInputFlow;
62 import org.onap.sdc.frontend.ci.tests.flow.AddComponentPropertyFlow;
63 import org.onap.sdc.frontend.ci.tests.flow.AddNodeToCompositionFlow;
64 import org.onap.sdc.frontend.ci.tests.flow.CreateDirectiveNodeFilterFlow;
65 import org.onap.sdc.frontend.ci.tests.flow.CreateSubstitutionFilterFlow;
66 import org.onap.sdc.frontend.ci.tests.flow.CreateVfFlow;
67 import org.onap.sdc.frontend.ci.tests.flow.CreateVfcFlow;
68 import org.onap.sdc.frontend.ci.tests.flow.DownloadToscaTemplateFlow;
69 import org.onap.sdc.frontend.ci.tests.flow.DownloadCsarArtifactFlow;
70 import org.onap.sdc.frontend.ci.tests.flow.EditComponentPropertiesFlow;
71 import org.onap.sdc.frontend.ci.tests.flow.composition.CreateRelationshipFlow;
72 import org.onap.sdc.frontend.ci.tests.flow.exception.UiTestFlowRuntimeException;
73 import org.onap.sdc.frontend.ci.tests.pages.AttributesOutputsPage;
74 import org.onap.sdc.frontend.ci.tests.pages.ComponentPage;
75 import org.onap.sdc.frontend.ci.tests.pages.ResourceCreatePage;
76 import org.onap.sdc.frontend.ci.tests.pages.ResourcePropertiesAssignmentPage;
77 import org.onap.sdc.frontend.ci.tests.pages.ResourcePropertiesPage;
78 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionDetailSideBarComponent;
79 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionDetailSideBarComponent.CompositionDetailTabName;
80 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionInformationTab;
81 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.InterfaceDefinitionOperationsModal;
82 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionInterfaceOperationsTab;
83 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionPage;
84 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.RelationshipWizardInterfaceOperation.InterfaceOperationsData;
85 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.ToscaArtifactsPage;
86 import org.onap.sdc.frontend.ci.tests.pages.home.HomePage;
87 import org.onap.sdc.frontend.ci.tests.utilities.FileHandling;
88 import org.openecomp.sdc.be.model.ComponentInstance;
89 import org.openqa.selenium.WebDriver;
90 import org.slf4j.Logger;
91 import org.slf4j.LoggerFactory;
92 import org.testng.annotations.BeforeMethod;
93 import org.testng.annotations.Test;
94 import org.yaml.snakeyaml.Yaml;
95
96 import com.aventstack.extentreports.Status;
97
98 public class ServiceTemplateDesignUiTests extends SetupCDTest {
99
100     private static final Logger LOGGER = LoggerFactory.getLogger(ServiceTemplateDesignUiTests.class);
101
102     private WebDriver webDriver;
103     private HomePage homePage;
104     private List<ResourceCreateData> vfcs = new ArrayList<>();
105     private ResourceCreateData vfResourceCreateData;
106     private ComponentInstance networkFunctionInstance;
107     private ComponentInstance networkServiceInstance;
108     private AddNodeToCompositionFlow addNodeToCompositionFlow;
109     private ComponentPage componentPage;
110     private Map<String, String> propertiesToBeAddedMap;
111     private ResourceCreatePage resourceCreatePage;
112     private Map<String, String> inputsToBeAddedMap;
113     private final List<ServiceDependencyProperty> substitutionFilterProperties = new ArrayList<>();
114     private final String interfaceName = "Standard";
115     private final String interfaceOperationName = "create";
116     private final String implementationName = "IntegrationTest";
117     private final String inputName = "InputName1";
118     private final String inputValue = "InputValue1";
119
120     @BeforeMethod
121     public void init() {
122         webDriver = DriverFactory.getDriver();
123         homePage = new HomePage(webDriver);
124     }
125
126     @Test(dataProviderClass = OnboardingDataProviders.class, dataProvider = "vfcList")
127     public void importAndCertifyVfc(final String rootFolder, final String vfcFilename) {
128         setLog(vfcFilename);
129         final String resourceName = ElementFactory.addRandomSuffixToName(ElementFactory.getResourcePrefix());
130         final CreateVfcFlow createVfcFlow = createVFC(rootFolder + vfcFilename, resourceName);
131         vfcs.stream().filter(vfc -> vfc.getName().startsWith(resourceName)).findFirst().orElseThrow(
132             () -> new UiTestFlowRuntimeException(String.format("VFCs List should contain a VFC with the expected name %s", resourceName)));
133         final ResourceCreatePage vfcResourceCreatePage = createVfcFlow.getLandedPage()
134             .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected ResourceCreatePage"));
135         vfcResourceCreatePage.isLoaded();
136         vfcResourceCreatePage.certifyComponent();
137         ExtentTestActions.takeScreenshot(Status.INFO, "vfc-certified",
138             String.format("VFC '%s' was certified", resourceName));
139     }
140
141     @Test(dependsOnMethods = "importAndCertifyVfc")
142     public void createBaseService() {
143         final CreateVfFlow createVfFlow = createVF();
144        resourceCreatePage = createVfFlow.getLandedPage()
145             .orElseThrow(() -> new UiTestFlowRuntimeException("Expecting a ResourceCreatePage"));
146         resourceCreatePage.isLoaded();
147     }
148
149     @Test(dependsOnMethods = "createBaseService")
150     public void addComponentProperty() throws UnzipException {
151         propertiesToBeAddedMap = loadPropertiesToAdd();
152         addProperty(propertiesToBeAddedMap);
153         componentPage = addValueToProperty(loadPropertiesToEdit());
154         componentPage.isLoaded();
155         downloadAndVerifyCsarPackageAfterAddProperty(componentPage);
156     }
157
158     @Test(dependsOnMethods = "createBaseService")
159     public void addRelationshipTemplate() throws UnzipException {
160         homePage.isLoaded();
161         resourceCreatePage = (ResourceCreatePage) homePage.clickOnComponent(vfResourceCreateData.getName());
162         resourceCreatePage.isLoaded();
163         addNodeToCompositionFlow = addNodeToCompositionAndCreateRelationship();
164         final CompositionPage compositionPage = addNodeToCompositionFlow.getLandedPage()
165             .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected return CompositionPage"));
166         compositionPage.isLoaded();
167         componentPage = compositionPage.goToGeneral();
168         componentPage.isLoaded();
169         downloadAndVerifyCsarPackage(componentPage);
170     }
171
172     @Test(dependsOnMethods = "addRelationshipTemplate")
173     public void createMetadataForServiceProperty() throws Exception {
174         homePage.isLoaded();
175         componentPage = (ComponentPage) homePage.clickOnComponent(vfResourceCreateData.getName());
176         componentPage.isLoaded();
177         final ResourcePropertiesAssignmentPage propertiesAssignmentPage = componentPage.goToPropertiesAssignment();
178
179         propertiesAssignmentPage.isLoaded();
180         propertiesAssignmentPage.selectInputTab();
181         final var propertyName = propertiesAssignmentPage.getInputPropertyNames().get(0);
182         final var key = "Key";
183         final var value = "Test";
184         propertiesAssignmentPage.setInputPropertyMetadata(propertyName, key, value);
185
186         final var topologyTemplate = getMapEntry(downloadToscaTemplate(), "topology_template");
187         final var inputs = getMapEntry(topologyTemplate, "inputs");
188         final var serviceProperty = getMapEntry(inputs, propertyName);
189         final var servicePropertyMetadata = getMapEntry(serviceProperty, "metadata");
190         assertNotNull(servicePropertyMetadata, String.format("Metadata not found for property %s", propertyName));
191         assertEquals(servicePropertyMetadata.get(key), value, "Created service property metadata has invalid value");
192     }
193
194     @Test(dependsOnMethods = "addRelationshipTemplate")
195     public void addOutputsToVF_test() throws UnzipException, IOException {
196         homePage.isLoaded();
197         final ComponentPage resourceCreatePage = (ComponentPage) homePage.clickOnComponent(vfResourceCreateData.getName());
198         resourceCreatePage.isLoaded();
199
200         final AttributesOutputsPage attributesOutputsPage = resourceCreatePage.goToAttributesOutputs();
201         attributesOutputsPage.isLoaded();
202
203         final ComponentInstance createdComponentInstance = addNodeToCompositionFlow.getCreatedComponentInstance()
204             .orElseThrow(() -> new UiTestFlowRuntimeException("Expecting a ComponentInstance"));
205
206         attributesOutputsPage.clickOnAttributeNavigation(createdComponentInstance.getName());
207         assertTrue(attributesOutputsPage.isAttributePresent("attr_1"));
208         attributesOutputsPage.declareOutput("attr_1");
209         attributesOutputsPage.clickOnOutputsTab();
210         assertTrue(attributesOutputsPage.isOutputPresent("attr_1"));
211
212         attributesOutputsPage.clickOnAttributesTab();
213         assertTrue(attributesOutputsPage.isAttributePresent("attr_2"));
214         attributesOutputsPage.declareOutput("attr_2");
215         attributesOutputsPage.clickOnOutputsTab();
216         assertTrue(attributesOutputsPage.isOutputPresent("attr_2"));
217
218         attributesOutputsPage.clickOnAttributesTab();
219         assertTrue(attributesOutputsPage.isAttributePresent("attr_3"));
220         attributesOutputsPage.declareOutput("attr_3");
221         attributesOutputsPage.clickOnOutputsTab();
222         assertTrue(attributesOutputsPage.isOutputPresent("attr_3"));
223
224         attributesOutputsPage.deleteOutput(createdComponentInstance.getName() + "_attr_2");
225         attributesOutputsPage.clickOnAttributesTab();
226         assertTrue(attributesOutputsPage.isAttributePresent("attr_2"));
227         attributesOutputsPage.clickOnOutputsTab();
228         assertTrue(attributesOutputsPage.isOutputDeleted("attr_2"));
229
230         attributesOutputsPage.clickOnAttributesTab();
231         ExtentTestActions.addScreenshot(Status.INFO, "AttributesTab", "The Attribute's list : ");
232
233         attributesOutputsPage.clickOnOutputsTab();
234         ExtentTestActions.addScreenshot(Status.INFO, "OutputsTab", "The Output's list : ");
235
236         Map<String, Object> yamlObject = downloadToscaArtifact(attributesOutputsPage);
237         checkMetadata(yamlObject, vfResourceCreateData);
238         checkTopologyTemplate(yamlObject);
239     }
240
241     @Test(dependsOnMethods = "addRelationshipTemplate")
242     public void updateInterfaceOperation() throws Exception {
243         homePage.isLoaded();
244         componentPage = (ComponentPage) homePage.clickOnComponent(vfResourceCreateData.getName());
245         componentPage.isLoaded();
246         final CompositionPage compositionPage = componentPage.goToComposition();
247         compositionPage.isLoaded();
248         ExtentTestActions.addScreenshot(Status.INFO, "select-VFC-node", "Selecting Node on composition");
249         compositionPage.selectNode(vfcs.get(1).getName());
250         final InterfaceDefinitionOperationsModal.InterfaceOperationsData interfaceOperationsData =
251             new InterfaceDefinitionOperationsModal.InterfaceOperationsData("IT for updating an Interface Operation",
252                 "MyIntegrationTestImplementationName", "My_IT_InputName", "My_IT_InputValue");
253         updateInterfaceOperation(compositionPage, interfaceOperationsData);
254         componentPage = compositionPage.goToGeneral();
255         componentPage.isLoaded();
256         verifyToscaTemplateHasUpdatedInterfaceOperation(downloadToscaTemplate(), interfaceOperationsData);
257     }
258
259     @Test(dependsOnMethods = "addComponentProperty")
260     public void createSubstitutionFilter() throws Exception {
261         componentPage = (ComponentPage) homePage.clickOnComponent(vfResourceCreateData.getName());
262         componentPage.isLoaded();
263         loadSubstitutionFilterProperties();
264         final CompositionPage compositionPage = componentPage.goToComposition();
265         compositionPage.isLoaded();
266         substitutionFilterProperties.forEach(substitutionFilterProperty -> {
267             final CreateSubstitutionFilterFlow createSubstitutionFilterFlow = new CreateSubstitutionFilterFlow(webDriver, substitutionFilterProperty);
268             createSubstitutionFilterFlow.run(compositionPage);
269         });
270         componentPage = compositionPage.goToGeneral();
271         componentPage.isLoaded();
272         verifyToscaTemplateHasSubstitutionFilter(downloadToscaTemplate());
273     }
274
275     @Test(dependsOnMethods = "createBaseService")
276     public void createDirectiveNodeFilterTest() throws Exception {
277         final ResourceCreateData vfcResourceCreateData = vfcs.get(1);
278         final String vfcNameInComposition = vfcResourceCreateData.getName().concat(" 0");
279         final String value = "Test";
280         final LogicalOperator operator = LogicalOperator.EQUALS;
281         homePage.isLoaded();
282         componentPage = (ComponentPage) homePage.clickOnComponent(vfcResourceCreateData.getName());
283
284         componentPage.isLoaded();
285         final ResourcePropertiesPage vfcPropertiesPage = componentPage.goToProperties();
286         vfcPropertiesPage.isLoaded();
287         final Map<String, String> propertyNamesAndTypes = vfcPropertiesPage.getPropertyNamesAndTypes();
288         final List<String> propertyNames = propertyNamesAndTypes.keySet().stream().collect(Collectors.toList());
289         final ServiceDependencyProperty serviceDependencyProperty =
290                 new ServiceDependencyProperty(propertyNames.get(0), propertyNamesAndTypes.get(propertyNames.get(0)), value, operator);
291
292         homePage.getTopNavComponent().clickOnHome();
293         homePage.isLoaded();
294         homePage.clickOnComponent(vfResourceCreateData.getName());
295
296         componentPage.isLoaded();
297         final CompositionPage compositionPage = componentPage.goToComposition();
298         compositionPage.isLoaded();
299         compositionPage.selectNode(vfcNameInComposition);
300
301         final CreateDirectiveNodeFilterFlow createDirectiveNodeFilterFlow =
302                 new CreateDirectiveNodeFilterFlow(webDriver, 2, serviceDependencyProperty);
303         createDirectiveNodeFilterFlow.run(componentPage);
304
305         verifyAvailableDirectiveTypes(createDirectiveNodeFilterFlow.getDirectiveOptions());
306
307         verifyAvailablePropertyNames(propertyNames, createDirectiveNodeFilterFlow.getPropertyOptions());
308
309         componentPage = compositionPage.goToGeneral();
310         componentPage.isLoaded();
311         final Map<?, ?> yaml = downloadToscaTemplate();
312         verifyToscaTemplateHasDirectiveNodeFilter(yaml, serviceDependencyProperty, vfcNameInComposition);
313     }
314
315     @Test(dependsOnMethods = "addComponentProperty")
316     public void declareInputFromProperties() throws Exception {
317         componentPage = (ComponentPage) homePage.clickOnComponent(vfResourceCreateData.getName());
318         componentPage.isLoaded();
319
320         ResourcePropertiesAssignmentPage propertiesAssignmentPage = componentPage.goToPropertiesAssignment();
321         propertiesAssignmentPage.isLoaded();
322
323         declareInputToBaseService(propertiesAssignmentPage, "property1");
324         declareInputToInstanceProperties(propertiesAssignmentPage, "resourceSubtype");
325         verifyToscaTemplateHasDeclareInput(downloadToscaTemplate());
326     }
327
328     @Test(dependsOnMethods = "createBaseService")
329     public void addComponentInputs() throws Exception {
330         inputsToBeAddedMap = loadInputsToAdd();
331         addInput(inputsToBeAddedMap);
332         verifyToscaTemplateAddInput(downloadToscaTemplate());
333     }
334
335     private void checkMetadata(final Map<String, Object> map, final ResourceCreateData createdData) {
336         final Map<String, Object> metadata = getMapEntry(map, "metadata");
337
338         assertEquals(createdData.getName(), metadata.get("name"));
339         assertEquals(createdData.getDescription(), metadata.get("description"));
340         assertEquals("Generic", metadata.get("category"));
341         assertThat((String) metadata.get("type"), not(emptyString()));
342         assertEquals(createdData.getCategory(), metadata.get("subcategory"));
343         assertEquals(createdData.getVendorName(), metadata.get("resourceVendor"));
344         assertEquals(createdData.getVendorRelease(), metadata.get("resourceVendorRelease"));
345         assertEquals(createdData.getVendorModelNumber(), metadata.get("reourceVendorModelNumber"));
346     }
347
348     private void checkTopologyTemplate(final Map<String, Object> map) {
349         final Map<String, Object> mapEntry = getMapEntry(map, "topology_template");
350         assertNotNull(mapEntry);
351
352         final Map<String, Object> inputs = getMapEntry(mapEntry, "inputs");
353         assertThat(inputs, not(anEmptyMap()));
354
355         final Map<String, Object> outputs = getMapEntry(mapEntry, "outputs");
356         assertThat(outputs, not(anEmptyMap()));
357         assertEquals(2, outputs.keySet().stream().filter(s -> (s.contains("_attr_1") || s.contains("_attr_3")) && !s.contains("_attr_2")).count());
358
359         final Map<String, Object> nodeTemplates = getMapEntry(mapEntry, "node_templates");
360         assertThat(nodeTemplates, not(anEmptyMap()));
361
362         final Map<String, Object> substitutionMappings = getMapEntry(mapEntry, "substitution_mappings");
363         assertThat(substitutionMappings, not(anEmptyMap()));
364
365         final Map<String, Object> attributes = getMapEntry(substitutionMappings, "attributes");
366         assertThat(attributes, not(anEmptyMap()));
367         assertEquals(2, attributes.keySet().stream().filter(s -> (s.contains("_attr_1") || s.contains("_attr_3")) && !s.contains("_attr_2")).count());
368     }
369
370     /**
371      * Updates an Interface operation from a selected Node (VFC)
372      * @param compositionPage the composition page
373      * @param interfaceOperationsData the interface definition
374      * @throws IOException
375      */
376     private void updateInterfaceOperation(final CompositionPage compositionPage,
377         final InterfaceDefinitionOperationsModal.InterfaceOperationsData interfaceOperationsData) throws IOException {
378         final CompositionDetailSideBarComponent detailSideBar = compositionPage.getDetailSideBar();
379         detailSideBar.isLoaded();
380         final CompositionInterfaceOperationsTab compositionInterfaceOperationsTab =
381             (CompositionInterfaceOperationsTab) detailSideBar.selectTab(CompositionDetailTabName.INTERFACE_OPERATIONS);
382         compositionInterfaceOperationsTab.isLoaded();
383         ExtentTestActions.takeScreenshot(Status.INFO, "compositionInterfaceOperationsTab",
384             "Composition Interface Operations Tab loaded");
385         assertTrue(compositionInterfaceOperationsTab.isOperationPresent(interfaceOperationName));
386         final InterfaceDefinitionOperationsModal compositionInterfaceOperationsModal = compositionInterfaceOperationsTab
387             .clickOnOperation(interfaceOperationName);
388         compositionInterfaceOperationsModal.isLoaded();
389         ExtentTestActions.takeScreenshot(Status.INFO, "update-interface-operation-modal", "Loading Interface Operations Modal");
390         compositionInterfaceOperationsModal.addInput();
391         compositionInterfaceOperationsModal.updateInterfaceOperation(interfaceOperationsData);
392         compositionInterfaceOperationsTab.isLoaded();
393         ExtentTestActions.addScreenshot(Status.INFO, "updated-interface-operation",
394             "The Interface operation from the selected Node was successfully updated");
395         // Gives time for UI to load the Updated Interface Operation
396         final CompositionInformationTab compositionInformationTab =
397             (CompositionInformationTab) detailSideBar.selectTab(CompositionDetailTabName.INFORMATION);
398         compositionInformationTab.isLoaded();
399         validateUpdatedInterfaceOperation(detailSideBar, interfaceOperationsData);
400     }
401
402     /**
403      * Validates if the Updated Interface Operation has the expected values
404      * @param detailSideBar The composition Page
405      * @param interfaceOperationsData The Updated Interface Definition
406      */
407     private void validateUpdatedInterfaceOperation(final CompositionDetailSideBarComponent detailSideBar,
408                                                    final InterfaceDefinitionOperationsModal.InterfaceOperationsData interfaceOperationsData) {
409         final CompositionInterfaceOperationsTab compositionInterfaceOperationsTab = (CompositionInterfaceOperationsTab) detailSideBar
410             .selectTab(CompositionDetailTabName.INTERFACE_OPERATIONS);
411         compositionInterfaceOperationsTab.isLoaded();
412         assertTrue(compositionInterfaceOperationsTab.isOperationPresent(interfaceOperationName));
413         assertTrue(compositionInterfaceOperationsTab.isDescriptionPresent());
414         final InterfaceDefinitionOperationsModal compositionInterfaceOperationsModal = compositionInterfaceOperationsTab
415             .clickOnOperation(interfaceOperationName);
416         compositionInterfaceOperationsModal.isLoaded();
417         ExtentTestActions.takeScreenshot(Status.INFO, "validate-updated-interface-operation",
418             "Loading the Interface Operations Modal for validating");
419         assertThat("The Interface Operation Description should match", interfaceOperationsData.getDescription(),
420             equalToIgnoringCase(compositionInterfaceOperationsModal.getDescription()));
421         assertThat("The Interface Operation Implementation Name should match", interfaceOperationsData.getImplementationName(),
422             equalToIgnoringCase(compositionInterfaceOperationsModal.getImplementationName()));
423         assertThat("The Interface Operation Input key should match", interfaceOperationsData.getInputName(),
424             equalToIgnoringCase(compositionInterfaceOperationsModal.getInputName()));
425         assertThat("The Interface Operation Input Value should match", interfaceOperationsData.getInputValue(),
426             equalToIgnoringCase(compositionInterfaceOperationsModal.getInputValue()));
427         compositionInterfaceOperationsModal.clickOnCancel();
428     }
429
430     private void verifyToscaTemplateHasUpdatedInterfaceOperation(final Map<?, ?> toscaTemplateYaml,
431         final InterfaceDefinitionOperationsModal.InterfaceOperationsData interfaceOperationsData) {
432
433         assertNotNull(toscaTemplateYaml, "No contents in TOSCA Template");
434         final Map<String, Object> topologyTemplateTosca = getMapEntry((Map<String, Object>) toscaTemplateYaml, "topology_template");
435         assertThat("Should contain a topology_template entry", toscaTemplateYaml, is(notNullValue()));
436         final Map<String, Object> nodeTemplatesTosca = getMapEntry(topologyTemplateTosca, "node_templates");
437         assertThat("Should contain a node_templates entry", nodeTemplatesTosca, is(notNullValue()));
438         final Optional<Entry<String, Object>> nodeWithInterfaceOperation = nodeTemplatesTosca.entrySet().stream()
439             .filter(s -> s.getKey().startsWith(vfcs.get(1).getName())).findFirst();
440         assertThat("Should contain a node (VFC)", nodeWithInterfaceOperation.isPresent(), is(true));
441         final Map<String, Object> interfacesEntry = (Map<String, Object>) nodeWithInterfaceOperation.get().getValue();
442         assertThat("The Interfaces Entry should not be empty", interfacesEntry, not(anEmptyMap()));
443         final Map<String, Object> interfaceOperations = (Map<String, Object>) interfacesEntry.get("interfaces");
444         assertThat("The Interface Entry should have operations", interfaceOperations, not(anEmptyMap()));
445         final Map<String, Object> interfaceNameMap = (Map<String, Object>) interfaceOperations.get(interfaceName);
446         assertThat(String.format("'%s' should contain a Interface Name entry '%s'", interfaceNameMap, interfaceName),
447             interfaceOperations, not(anEmptyMap()));
448         final Map<String, Object> updatedInterfaceOperation = (Map<String, Object>) interfaceNameMap.get(interfaceOperationName);
449         assertThat(String.format("'%s' should contain a Interface Operation Name '%s'", updatedInterfaceOperation, interfaceOperationName),
450             updatedInterfaceOperation, not(anEmptyMap()));
451         assertThat("The Interface Operation Description should match",
452             updatedInterfaceOperation.get("description").equals(interfaceOperationsData.getDescription()));
453         assertThat("The Interface Operation Implementation Name should match",
454             updatedInterfaceOperation.get("implementation").equals(interfaceOperationsData.getImplementationName()));
455         final Map<String, Object> updatedInterfaceOperationInput = (Map<String, Object>) updatedInterfaceOperation.get("inputs");
456         assertThat("The Interface Operation Input Key should match",
457             updatedInterfaceOperationInput.containsKey(interfaceOperationsData.getInputName()));
458         assertThat("The Interface Operation Input Value should match",
459             updatedInterfaceOperationInput.containsValue(interfaceOperationsData.getInputValue()));
460     }
461
462     private Map<String, Object> downloadToscaArtifact(final ComponentPage resourceCreatePage) throws UnzipException {
463         final DownloadCsarArtifactFlow downloadCsarArtifactFlow = downloadToscaCsar(resourceCreatePage);
464         final ToscaArtifactsPage toscaArtifactsPage = downloadCsarArtifactFlow.getLandedPage()
465             .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected ToscaArtifactsPage"));
466
467         assertThat("No artifact download was found", toscaArtifactsPage.getDownloadedArtifactList(), not(empty()));
468         final String downloadedCsarName = toscaArtifactsPage.getDownloadedArtifactList().get(0);
469         final String downloadFolderPath = getConfig().getDownloadAutomationFolder();
470         final Map<String, byte[]> filesFromZip = FileHandling.getFilesFromZip(downloadFolderPath, downloadedCsarName);
471         final Optional<String> resourceEntryOpt = filesFromZip.keySet().stream()
472             .filter(s -> s.equals("Definitions/" + downloadedCsarName.replace("-csar.csar", "-template.yml")))
473             .findFirst();
474         if (resourceEntryOpt.isEmpty()) {
475             fail("Could not find the resource package in Definitions");
476         }
477         return loadYamlObject(filesFromZip.get(resourceEntryOpt.get()));
478     }
479
480     private void declareInputToBaseService(ResourcePropertiesAssignmentPage propertiesAssignmentPage, String propertyName){
481         propertiesAssignmentPage.selectProperty(propertyName);
482         propertiesAssignmentPage.clickOnDeclareInput();
483         propertiesAssignmentPage.clickInputTab(propertyName);
484         propertiesAssignmentPage.isInputPresent(vfResourceCreateData.getName() + "_" + propertyName);
485     }
486
487     private void declareInputToInstanceProperties(ResourcePropertiesAssignmentPage propertiesAssignmentPage, String propertyName){
488         propertiesAssignmentPage.selectPropertiesTab();
489         propertiesAssignmentPage.loadCompositionTab();
490         propertiesAssignmentPage.loadComponentInstanceProperties(vfcs.get(0).getName().concat(" 0"));
491         propertiesAssignmentPage.selectProperty(propertyName);
492         propertiesAssignmentPage.clickOnDeclareInput();
493         propertiesAssignmentPage.clickInputTab(propertyName);
494         propertiesAssignmentPage.isInputPresent(vfResourceCreateData.getName() + "_" + vfcs.get(0).getName());
495     }
496
497     private CreateVfFlow createVF() {
498         final ResourceCreateData vfCreateData = createVfFormData();
499         final CreateVfFlow createVfFlow = new CreateVfFlow(webDriver, vfCreateData);
500         createVfFlow.run(homePage);
501         return createVfFlow;
502     }
503
504     private ResourceCreateData createVfFormData() {
505         vfResourceCreateData = new ResourceCreateData();
506         vfResourceCreateData.setRandomName(ElementFactory.getResourcePrefix() + "-VF");
507         vfResourceCreateData.setCategory(ResourceCategoryEnum.GENERIC_ABSTRACT.getSubCategory());
508         vfResourceCreateData.setTagList(Arrays.asList(vfResourceCreateData.getName(), "createVF"));
509         vfResourceCreateData.setDescription("aDescription");
510         vfResourceCreateData.setVendorName("EST");
511         vfResourceCreateData.setVendorRelease("4.1.1");
512         vfResourceCreateData.setVendorModelNumber("0001");
513         return vfResourceCreateData;
514     }
515
516     private CreateVfcFlow createVFC(final String vfcFullFilename, final String resourceName) {
517         final ResourceCreateData vfcCreateData = createVfcFormData(resourceName);
518         final CreateVfcFlow createVfcFlow = new CreateVfcFlow(webDriver, vfcCreateData, vfcFullFilename);
519         createVfcFlow.run(homePage);
520         ExtentTestActions.takeScreenshot(Status.INFO, "vfc-created", String.format("VFC '%s' was created", resourceName));
521         assertThat(vfcs, notNullValue());
522         vfcs.add(vfcCreateData);
523         return createVfcFlow;
524     }
525
526     private ResourceCreateData createVfcFormData(final String resourceName) {
527         final ResourceCreateData vfcCreateData = new ResourceCreateData();
528         vfcCreateData.setRandomName(resourceName);
529         vfcCreateData.setCategory(ResourceCategoryEnum.GENERIC_NETWORK_ELEMENTS.getSubCategory());
530         vfcCreateData.setTagList(Arrays.asList(vfcCreateData.getName(), "importVFC"));
531         vfcCreateData.setDescription("aDescription");
532         vfcCreateData.setVendorName("EST");
533         vfcCreateData.setVendorRelease("4.1.1");
534         vfcCreateData.setVendorModelNumber("0001");
535         return vfcCreateData;
536     }
537
538     private AddNodeToCompositionFlow addNodeToCompositionAndCreateRelationship() {
539         assertThat(vfcs, hasSize(2));
540         final ComponentData parentComponent = new ComponentData();
541         parentComponent.setName(vfResourceCreateData.getName());
542         parentComponent.setVersion("0.1");
543         parentComponent.setComponentType(ComponentType.RESOURCE);
544
545         // Adds networkFunction to VF composition
546         final ComponentData networkFunction = new ComponentData();
547         networkFunction.setName(vfcs.get(0).getName());
548         networkFunction.setVersion("1.0");
549         networkFunction.setComponentType(ComponentType.RESOURCE);
550         final CompositionPage compositionPage = resourceCreatePage.goToComposition();
551         compositionPage.isLoaded();
552         AddNodeToCompositionFlow addNodeToCompositionFlow = addNodeToComposition(parentComponent, networkFunction, compositionPage);
553         networkFunctionInstance = addNodeToCompositionFlow.getCreatedComponentInstance()
554             .orElseThrow(() -> new UiTestFlowRuntimeException("Could not get the created component instance"));
555
556         // Adds networkService to VF composition
557         final ComponentData networkService = new ComponentData();
558         networkService.setName(vfcs.get(1).getName());
559         networkService.setVersion("1.0");
560         networkService.setComponentType(ComponentType.RESOURCE);
561         addNodeToCompositionFlow = addNodeToComposition(parentComponent, networkService, compositionPage);
562         networkServiceInstance = addNodeToCompositionFlow.getCreatedComponentInstance()
563             .orElseThrow(() -> new UiTestFlowRuntimeException("Could not get the created component instance"));
564
565         // Creates a dependsOn relationship from networkServiceInstance to networkFunctionInstance
566         createRelationship(compositionPage, networkFunctionInstance.getName(), "tosca.capabilities.Node",
567             networkServiceInstance.getName(), "tosca.capabilities.Node");
568
569         return addNodeToCompositionFlow;
570     }
571
572     public AddNodeToCompositionFlow addNodeToComposition(final ComponentData parentComponent,
573                                                          final ComponentData resourceToAdd,
574                                                          CompositionPage compositionPage) {
575         final AddNodeToCompositionFlow addNodeToCompositionFlow = new AddNodeToCompositionFlow(webDriver, parentComponent, resourceToAdd);
576         compositionPage = (CompositionPage) addNodeToCompositionFlow.run(compositionPage)
577             .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected CompositionPage"));
578         compositionPage.isLoaded();
579         ExtentTestActions.takeScreenshot(Status.INFO, "node-added-to-composition",
580             String.format("Resource '%s' was added to composition", resourceToAdd.getName()));
581         return addNodeToCompositionFlow;
582     }
583
584     /**
585      * Creates a DependsOn relationship between the imported VFCs
586      * @param compositionPage Composition Page
587      * @param fromComponentInstanceName VFC - Network Function
588      * @param fromCapability Node Capability
589      * @param toComponentInstanceName  VFC - Network Service
590      * @param toRequirement Node Requirement
591      */
592     private void createRelationship(final CompositionPage compositionPage, final String fromComponentInstanceName,
593                                     final String fromCapability, final String toComponentInstanceName, final String toRequirement) {
594         final RelationshipInformation relationshipInformation =
595             new RelationshipInformation(fromComponentInstanceName, fromCapability, toComponentInstanceName, toRequirement);
596         final CreateRelationshipFlow createRelationshipFlow = new CreateRelationshipFlow(webDriver, relationshipInformation,
597             new InterfaceOperationsData(interfaceName, interfaceOperationName, implementationName, inputName, inputValue));
598         createRelationshipFlow.run(compositionPage).orElseThrow(() -> new UiTestFlowRuntimeException("Expecting a CompositionPage instance"));
599         ExtentTestActions.takeScreenshot(Status.INFO, "relationship",
600             String.format("Relationship from networkFunctionInstance '%s' to networkServiceInstanceResource '%s' was created",
601                 fromComponentInstanceName, toComponentInstanceName));
602     }
603
604     /**
605      * Adds a property to the base service
606      * @param propertyMap map of properties to be added
607      */
608     private void addProperty(final Map<String, String> propertyMap) {
609         componentPage = (ComponentPage) homePage.clickOnComponent(vfResourceCreateData.getName());
610         componentPage.isLoaded();
611         final AddComponentPropertyFlow addComponentPropertyFlow = new AddComponentPropertyFlow(webDriver, propertyMap);
612         addComponentPropertyFlow.run(componentPage.goToPropertiesAssignment());
613     }
614
615     /**
616      * Adds a input to the base service
617      * @param inputMap map of inputs to be added
618      */
619     private void addInput(final Map<String, String> inputMap) {
620         componentPage = (ComponentPage) homePage.clickOnComponent(vfResourceCreateData.getName());
621         componentPage.isLoaded();
622         final AddComponentInputFlow addComponentInputFlow = new AddComponentInputFlow(webDriver, inputMap);
623         addComponentInputFlow.run(componentPage.goToPropertiesAssignment());
624     }
625
626     /**
627      * Edits a property to add a value
628      * @param propertyMap map of properties to be edited
629      */
630     private ComponentPage addValueToProperty(final Map<String, Object> propertyMap) {
631         final EditComponentPropertiesFlow editComponentPropertiesFlow = new EditComponentPropertiesFlow(webDriver, propertyMap);
632         return editComponentPropertiesFlow.run().orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected return ComponentPage"));
633     }
634
635     /**
636      * Downloads and verifies the generated tosca templates.
637      * @param componentPage the component page
638      * @throws UnzipException
639      */
640     private void downloadAndVerifyCsarPackage(final ComponentPage componentPage) throws UnzipException {
641         checkCsarPackage(downloadCsarPackage(componentPage));
642     }
643
644     /**
645      * Downloads and verifies if the generated Tosca template contains the expected properties.
646      * @throws UnzipException
647      * @param componentPage
648      */
649     private void downloadAndVerifyCsarPackageAfterAddProperty(final ComponentPage componentPage) throws UnzipException {
650         verifyPropertiesOnGeneratedTemplate(downloadCsarPackage(componentPage));
651     }
652
653     private String downloadCsarPackage(final ComponentPage componentPage) {
654         final DownloadCsarArtifactFlow downloadCsarArtifactFlow = downloadToscaCsar(componentPage);
655         final ToscaArtifactsPage toscaArtifactsPage = downloadCsarArtifactFlow.getLandedPage()
656             .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected ToscaArtifactsPage"));
657         assertThat("No artifact download was found", toscaArtifactsPage.getDownloadedArtifactList(), not(empty()));
658         return toscaArtifactsPage.getDownloadedArtifactList().get(0);
659     }
660
661     /**
662      * Downloads the generated CSAR package.
663      * @param componentPage the component page
664      * @return the Downloaded Tosca CSAR file
665      */
666     private DownloadCsarArtifactFlow downloadToscaCsar(final ComponentPage componentPage) {
667         final DownloadCsarArtifactFlow downloadCsarArtifactFlow = new DownloadCsarArtifactFlow(webDriver);
668         downloadCsarArtifactFlow.setWaitBeforeGetTheFile(5L);
669         downloadCsarArtifactFlow.run(componentPage);
670         return downloadCsarArtifactFlow;
671     }
672
673     /**
674      * Verifies if the generated Tosca template contains the expected properties.
675      * @param downloadedCsarName the downloaded csar file name
676      * @throws UnzipException
677      */
678     private void verifyPropertiesOnGeneratedTemplate(final String downloadedCsarName) throws UnzipException {
679         final Map<String, byte[]> filesFromZip = extractFilesFromCsar(downloadedCsarName);
680         final String virtualFunctionName = vfResourceCreateData.getName().replace("-", "").toLowerCase();
681         final String vfResourceTemplateFile = "Definitions/resource-" + virtualFunctionName + "-template-interface.yml";
682         final String interfaceTemplateFile = filesFromZip.keySet().stream()
683             .filter(filename -> filename.equalsIgnoreCase(vfResourceTemplateFile)).findFirst()
684             .orElseThrow(() -> new UiTestFlowRuntimeException(String.format("Resource template file not found %s", vfResourceTemplateFile)));
685         final byte[] toscaInterfaceTemplateGenerated = filesFromZip.get(interfaceTemplateFile);
686         assertThat("The Generated Tosca template should not be null", toscaInterfaceTemplateGenerated, is(notNullValue()));
687         final Map<String, Object> interfaceTemplateYamlMap = loadYamlObject(toscaInterfaceTemplateGenerated);
688         final Map<String, Object> nodeTypesYamlMap = getMapEntry(interfaceTemplateYamlMap, "node_types");
689         assertThat(String.format("'%s' should contain a node_types entry", interfaceTemplateYamlMap), nodeTypesYamlMap, is(notNullValue()));
690         final Map<String, Object> properties = (Map) nodeTypesYamlMap.values().stream().filter(stringObjectEntry -> stringObjectEntry != null)
691             .collect(Collectors.toList()).get(0);
692         final Map<String, Object> propertiesFoundMap = (Map<String, Object>) properties.get("properties");
693         assertThat(String.format("The generated template file %s should contain all added properties", vfResourceTemplateFile),
694             propertiesFoundMap.keySet().containsAll(propertiesToBeAddedMap.keySet()), is(true));
695     }
696
697     /**
698      * Checks if the downloaded Tosca csar includes the node templates for the added VFCs,
699      * the generated service template declared “tosca_simple_yaml_1_3” as its Tosca version,
700      * the generated csar contains the node type definitions for the added VFCs in the Definitions directory,
701      * the interface template contains the relationship declaration
702      * @param downloadedCsarName download Tosca CSAR filename
703      * @throws UnzipException
704      */
705     private void checkCsarPackage(final String downloadedCsarName) throws UnzipException {
706         final Map<String, byte[]> filesFromZip = extractFilesFromCsar(downloadedCsarName);
707         final String virtualFunctionName = vfResourceCreateData.getName().replace("-", "").toLowerCase();
708         final List<String> expectedDefinitionFolderFileList = getExpectedDefinitionFolderFileList(virtualFunctionName);
709         final Map<String, byte[]> expectedFilesFromZipMap = filesFromZip.entrySet().parallelStream()
710             .filter(key -> expectedDefinitionFolderFileList.stream()
711                 .anyMatch(filename -> filename.equalsIgnoreCase(key.getKey()))).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
712         final String vfResourceTemplateFile = "Definitions/resource-" + virtualFunctionName + "-template.yml";
713         final String generatedTemplateFile = expectedFilesFromZipMap.keySet().stream()
714             .filter(filename -> filename.equalsIgnoreCase(vfResourceTemplateFile)).findFirst()
715             .orElseThrow(() -> new UiTestFlowRuntimeException(String.format("Resource template file not found %s", vfResourceTemplateFile)));
716         final byte[] toscaTemplateGenerated = filesFromZip.get(generatedTemplateFile);
717         assertThat(toscaTemplateGenerated, is(notNullValue()));
718         verifyGeneratedTemplate(toscaTemplateGenerated, generatedTemplateFile);
719         verifyNodesRelationship(expectedFilesFromZipMap, virtualFunctionName, filesFromZip);
720     }
721
722     private Map<String, byte[]> extractFilesFromCsar(final String downloadedCsarName) throws UnzipException {
723         final String downloadFolderPath = getConfig().getDownloadAutomationFolder();
724         final Map<String, byte[]> filesFromCsar = FileHandling.getFilesFromZip(downloadFolderPath, downloadedCsarName);
725         return filesFromCsar;
726     }
727
728     private void verifyGeneratedTemplate(final byte[] generatedTemplateData, final String generatedTemplateFile) {
729         final Map<String, Object> templateYamlMap = loadYamlObject(generatedTemplateData);
730         final boolean hasToscaDefinitionVersionEntry = templateYamlMap.containsKey("tosca_definitions_version");
731         assertThat(String.format("'%s' should contain tosca_definitions_version entry", generatedTemplateFile), hasToscaDefinitionVersionEntry,
732             is(true));
733         final String toscaVersion = (String) templateYamlMap.get("tosca_definitions_version");
734         assertThat(String.format("'%s' tosca_definitions_version entry should have tosca_simple_yaml_1_3 value", generatedTemplateFile),
735             toscaVersion.equalsIgnoreCase("tosca_simple_yaml_1_3"));
736         final Map<String, Object> topologyTemplateTosca = getMapEntry(templateYamlMap, "topology_template");
737         assertThat(String.format("'%s' should contain a topology_template entry", generatedTemplateFile), topologyTemplateTosca, is(notNullValue()));
738         final Map<String, Object> nodeTemplatesTosca = getMapEntry(topologyTemplateTosca, "node_templates");
739         assertThat(String.format("'%s' should contain a node_templates entry", generatedTemplateFile), nodeTemplatesTosca, is(notNullValue()));
740         final List<String> nodeTemplateFound = nodeTemplatesTosca.keySet().parallelStream().filter(s -> vfcs.stream()
741             .anyMatch(vfc -> s.startsWith(vfc.getName()))).collect(Collectors.toList());
742         assertThat(String.format("'%s' should contain the node type definitions for the added VFCs '%s'", nodeTemplatesTosca, vfcs),
743             nodeTemplateFound, hasSize(vfcs.size()));
744         verifyRelationshipTemplate(topologyTemplateTosca, generatedTemplateFile);
745     }
746
747     private void verifyRelationshipTemplate(final Map<String, Object> topologyTemplateToscaMap, final String generatedTemplateFile) {
748         final Map<String, Object> relationshipTemplateMap = getMapEntry(topologyTemplateToscaMap, "relationship_templates");
749         assertThat(String.format("'%s' should contain a topology_template entry", generatedTemplateFile), relationshipTemplateMap,
750             is(notNullValue()));
751         final String result = Arrays.asList(relationshipTemplateMap.values()).toString();
752         assertThat(String.format("'%s' should contain a DependsOn relationship", relationshipTemplateMap),
753             result.contains("tosca.relationships.DependsOn"), is(true));
754         assertThat(String.format("'%s' should contain interfaces entry", relationshipTemplateMap), result.contains("interfaces"), is(true));
755         assertThat(String.format("'%s' should contain a Interface Name entry '%s'", relationshipTemplateMap, interfaceName),
756             result.contains(interfaceName), is(true));
757         assertThat(String.format("'%s' should contain a Interface Operation Name '%s'", relationshipTemplateMap, interfaceOperationName),
758             result.contains(interfaceOperationName), is(true));
759         assertThat(String.format("'%s' should contain Implementation Name '%s'", relationshipTemplateMap, implementationName),
760             result.contains(implementationName), is(true));
761         assertThat(String.format("'%s' should contain inputs entry", relationshipTemplateMap), result.contains("inputs"), is(true));
762         assertThat(String.format("'%s' should contain Input Name '%s'", relationshipTemplateMap, inputName), result.contains(inputName),
763             is(true));
764         assertThat(String.format("'%s' should contain Input Value '%s'", relationshipTemplateMap, inputValue), result.contains(inputValue),
765             is(true));
766     }
767
768     private void verifyNodesRelationship(final Map<String, byte[]> expectedFilesFromZipMap, final String virtualFunctionName,
769                                          final Map<String, byte[]> filesFromZip) {
770         final String vfResourceTemplateFile = "Definitions/resource-" + virtualFunctionName + "-template-interface.yml";
771         final String interfaceTemplateFile = expectedFilesFromZipMap.keySet().stream()
772             .filter(filename -> filename.equalsIgnoreCase(vfResourceTemplateFile)).findFirst()
773             .orElseThrow(() -> new UiTestFlowRuntimeException(String.format("Resource template file not found %s", vfResourceTemplateFile)));
774         final byte[] toscaInterfaceTemplateGenerated = filesFromZip.get(interfaceTemplateFile);
775         assertThat(toscaInterfaceTemplateGenerated, is(notNullValue()));
776         final Map<String, Object> interfaceTemplateYamlMap = loadYamlObject(toscaInterfaceTemplateGenerated);
777         final Map<String, Object> nodeTypesYamlMap = getMapEntry(interfaceTemplateYamlMap, "node_types");
778         assertThat(String.format("'%s' should contain a node_types entry", interfaceTemplateYamlMap), nodeTypesYamlMap, is(notNullValue()));
779         final String result = Arrays.asList(nodeTypesYamlMap.values()).toString();
780         assertThat(String.format("'%s' should contain a capabilities entry", nodeTypesYamlMap), result.contains("capabilities"), is(true));
781         assertThat(String.format("'%s' should contain a requirements entry", nodeTypesYamlMap), result.contains("requirements"), is(true));
782         assertThat(String.format("'%s' should contain a relationship entry", nodeTypesYamlMap), result.contains("relationship"), is(true));
783         assertThat(String.format("'%s' should contain a DependsOn relationship value", nodeTypesYamlMap),
784             result.contains("tosca.relationships.DependsOn"), is(true));
785     }
786
787     private List<String> getExpectedDefinitionFolderFileList(final String vfResourceName) {
788         final List<String> expectedDefinitionFolderFileList = new ArrayList<>();
789         vfcs.forEach(vfc -> expectedDefinitionFolderFileList.add("Definitions/resource-" + vfc.getName() + "-template.yml"));
790         expectedDefinitionFolderFileList.add("Definitions/resource-" + vfResourceName + "-template.yml");
791         expectedDefinitionFolderFileList.add("Definitions/resource-" + vfResourceName + "-template-interface.yml");
792         return expectedDefinitionFolderFileList;
793     }
794
795     private void verifyToscaTemplateHasDeclareInput(Map<?, ?> yaml) {
796         assertNotNull(yaml, "No contents in TOSCA Template");
797         final Map<String, Object> toscaYaml = (Map<String, Object>) yaml;
798         final Map<String, Object> topologyTemplateTosca = getMapEntry(toscaYaml, "topology_template");
799         assertThat(String.format("'%s' should contain a topology_template entry", toscaYaml), topologyTemplateTosca,
800             notNullValue());
801         final Map<String, Object> inputsTosca = getMapEntry(topologyTemplateTosca, "inputs");
802         assertThat(String.format("'%s' should contain a inputs entry", toscaYaml), inputsTosca, notNullValue());
803         assertEquals(2, inputsTosca.keySet().stream()
804             .filter(s -> (s.contains("resourceSubtype") || s.contains("property1"))).count());
805         final Map<String, Object> substitutionMapping = getMapEntry(topologyTemplateTosca, "substitution_mappings");
806         assertThat(String.format("'%s' should contain a substitution_mappings entry", toscaYaml), substitutionMapping,
807             notNullValue());
808         final Map<String, Object> substitutionMappingProperties = getMapEntry(substitutionMapping, "properties");
809         assertThat(String.format("'%s' should contain a properties entry", toscaYaml), substitutionMappingProperties,
810             notNullValue());
811         assertEquals(2, substitutionMappingProperties.keySet().stream()
812             .filter(s -> (s.contains("resourceSubtype") || s.contains("property1"))).count());
813     }
814
815     private void verifyToscaTemplateAddInput(Map<?, ?> yaml) {
816         final Map<String, String> inputMap = loadInputsToAdd();
817         assertNotNull(yaml, "No contents in TOSCA Template");
818         final Map<String, Object> toscaYaml = (Map<String, Object>) yaml;
819         final Map<String, Object> topologyTemplateTosca = getMapEntry(toscaYaml, "topology_template");
820         assertThat(String.format("'%s' should contain a topology_template entry", toscaYaml), topologyTemplateTosca,
821             notNullValue());
822         final Map<String, Object> inputsTosca = getMapEntry(topologyTemplateTosca, "inputs");
823         assertThat(String.format("'%s' should contain a inputs entry", toscaYaml), inputsTosca, notNullValue());
824         assertEquals(3, inputsTosca.keySet().stream()
825             .filter(s -> inputMap.containsKey(s)).count());
826     }
827
828     private Map<String, Object> getMapEntry(final Map<?, ?> yamlObj, final String entryName) {
829         try {
830             return (Map<String, Object>) yamlObj.get(entryName);
831         } catch (final Exception e) {
832             final String errorMsg = String.format("Could not get the '%s' entry.", entryName);
833             LOGGER.error(errorMsg, e);
834             fail(errorMsg + "Error message: " + e.getMessage());
835         }
836         return null;
837     }
838
839     private Map<String, Object> loadYamlObject(final byte[] definitionYamlFile) {
840         return new Yaml().load(new String(definitionYamlFile));
841     }
842
843     private Map<String, String> loadPropertiesToAdd() {
844         final Map<String, String> propertyMap = new HashMap<>();
845         propertyMap.put("property1", "string");
846         propertyMap.put("property2", "integer");
847         propertyMap.put("property3", "boolean");
848         propertyMap.put("property4", "list");
849         propertyMap.put("property5", "map");
850         propertyMap.put("property6", "scalar-unit.size");
851         return propertyMap;
852     }
853
854     private Map<String, Object> loadPropertiesToEdit() {
855         final Map<String, Object> propertyMap = new HashMap<>();
856         propertyMap.put("property1", "Integration Test");
857         propertyMap.put("property2", 100);
858         propertyMap.put("property3", Boolean.TRUE);
859         propertyMap.put("property4", Arrays.asList("PropListV1", "PropListV2", "PropListV3"));
860         final Map<String, String> stringMap = new HashMap<>();
861         stringMap.put("PropMapKey1", "PropMapValue1");
862         stringMap.put("PropMapKey2", "PropMapValue2");
863         stringMap.put("PropMapKey3", "PropMapValue3");
864         propertyMap.put("property5", stringMap);
865         propertyMap.put("property6", 500);
866         return propertyMap;
867     }
868
869     private Map<String, String> loadInputsToAdd() {
870         final Map<String, String> inputMap = new HashMap<>();
871         inputMap.put("input1", "string");
872         inputMap.put("input2", "integer");
873         inputMap.put("input3", "boolean");
874         return inputMap;
875     }
876
877     private void loadSubstitutionFilterProperties() {
878         final ResourcePropertiesAssignmentPage propertiesPage = componentPage.goToPropertiesAssignment();
879         propertiesPage.isLoaded();
880         ExtentTestActions.takeScreenshot(Status.INFO, "propertiesAssigment",
881             String.format("The %s Properties Assignment Page is loaded", vfResourceCreateData.getName()));
882         Map<String, String> propertyNamesAndTypes = propertiesPage.getPropertyNamesAndTypes();
883         assertThat(String.format("The Component '%s' should have properties", vfResourceCreateData.getName()), propertyNamesAndTypes,
884             not(anEmptyMap()));
885         propertyNamesAndTypes.forEach((name, type)
886             -> substitutionFilterProperties.add(new ServiceDependencyProperty(name, type, getPropertyValueByType(type), LogicalOperator.EQUALS)));
887     }
888
889     private String getPropertyValueByType(final String type) {
890         switch (type) {
891             case "string":
892                 return "IntegrationTest";
893             case "integer":
894                 return "202";
895             case "size":
896                 return "500";
897             case "boolean":
898                 return "TRUE";
899             case "list":
900                 return "[\"value1\", \"value2\"]";
901             case "map":
902                 return "{\"MyKey\": \"MyValue\"}";
903             default:
904                 throw new UnsupportedOperationException("Not yet implemented for " + type);
905         }
906     }
907
908     /**
909      * Downloads Tosca Template file
910      * @return the tosca template yaml file
911      * @throws Exception
912      */
913     private Map<?, ?> downloadToscaTemplate() throws Exception {
914         final DownloadToscaTemplateFlow downloadToscaTemplateFlow = new DownloadToscaTemplateFlow(webDriver);
915         final ToscaArtifactsPage toscaArtifactsPage = (ToscaArtifactsPage) downloadToscaTemplateFlow.run(componentPage).get();
916         return FileHandling.parseYamlFile(getConfig().getDownloadAutomationFolder()
917             .concat(java.io.File.separator).concat(toscaArtifactsPage.getDownloadedArtifactList().get(0)));
918     }
919
920     private void verifyToscaTemplateHasSubstitutionFilter(final Map<?, ?> yaml) {
921         assertNotNull(yaml, "No contents in TOSCA Template");
922         final List<?> substitutionFilters = (List<?>) getSubstitutionFilterFromYaml(yaml).get("properties");
923         substitutionFilterProperties.forEach(substitutionFilterProperty -> {
924             final Map<?, ?> substitutionFilterMap = (Map<?, ?>) substitutionFilters.stream()
925                 .filter(subFilter -> ((Map<?, ?>) subFilter).containsKey(substitutionFilterProperty.getName())).findAny().get();
926             assertThat("Added substitution filter not found in TOSCA Template",
927                 substitutionFilterMap.containsKey(substitutionFilterProperty.getName()));
928             final Map<?, ?> substitutionFilterValue = (Map<?, ?>) ((List<?>) substitutionFilterMap.get(substitutionFilterProperty.getName())).get(0);
929             assertThat("Substitution Filter Value should not be empty", substitutionFilterMap, not(anEmptyMap()));
930             final String expectedSubstitutionPropertyValue = substitutionFilterProperty.getValue().replaceAll("[\"{}]", "");
931             final String actualSubstitutionPropertyValue = substitutionFilterValue.values().stream().findFirst().get() instanceof Map
932                 ? substitutionFilterValue.values().stream().findFirst().get().toString().replace("=", ": ")
933                 .replaceAll("\\{(.*?)\\}", "$1").trim()
934                 : substitutionFilterValue.values().stream().findFirst().get().toString();
935             assertThat("Invalid value for added substitution filters found in TOSCA Template",
936                 expectedSubstitutionPropertyValue.equalsIgnoreCase(actualSubstitutionPropertyValue));
937             assertThat("Invalid logical operator for added substitution filters found in TOSCA Template",
938                 substitutionFilterValue.containsKey(substitutionFilterProperty.getLogicalOperator().getName()));
939         });
940     }
941
942     private Map<?, ?> getSubstitutionFilterFromYaml(final Map<?, ?> yaml) {
943         final Map<?, ?> topology = (Map<?, ?>) yaml.get("topology_template");
944         final Map<?, ?> substitutionMappings = (Map<?, ?>) topology.get("substitution_mappings");
945         return (Map<?, ?>) substitutionMappings.get("substitution_filter");
946     }
947
948     private void verifyAvailableDirectiveTypes(final List<String> availableDirectiveTypes) {
949         assertNotNull(availableDirectiveTypes, "Expected list of available Directive Types, but recieved null");
950         Arrays.asList(DirectiveType.values()).forEach(directiveType -> {
951             assertTrue(availableDirectiveTypes.contains(directiveType.getName())
952                     , String.format("Expected directive %s to be availabe in UI options %s"
953                             , directiveType.getName(), availableDirectiveTypes.toString()));
954         });
955         ExtentTestActions.log(Status.PASS, "All expected directive types are available for selection");
956     }
957
958     private void verifyAvailablePropertyNames(List<String> propertyNames, List<String> propertyNameOptions) {
959         assertEquals(propertyNameOptions.size(), propertyNames.size(), "Mismatch in the number of properties available for selection");
960         propertyNames.forEach(name -> {
961             assertNotEquals(false, propertyNameOptions.remove(name)
962                     , String.format("Expected property %s not found in UI Select element", name));
963         });
964         ExtentTestActions.log(Status.PASS, "All expected properties are available for selection");
965     }
966
967     private void verifyToscaTemplateHasDirectiveNodeFilter(final Map<?, ?> yaml, ServiceDependencyProperty nodeFilterProperty, String nodeTemplateName) {
968         assertNotNull(yaml, "Tosca Template Yaml is not expected to be empty");
969         final List<?> nodeFilters = (List<?>) getDirectiveNodeFilterFromYaml(yaml, nodeTemplateName).get("properties");
970         final Map<?, ?> nodeFilter = (Map<?, ?>) nodeFilters.stream()
971                     .filter(yamlNodeFilter -> ((Map<?, ?>) yamlNodeFilter).containsKey(nodeFilterProperty.getName())).findAny().get();
972         assertNotNull(nodeFilter, "Added directive node filter not found in TOSCA Template");
973
974         final Map<?, ?> nodeFilterValue = (Map<?, ?>) ((List<?>) nodeFilter.get(nodeFilterProperty.getName())).get(0);
975         assertTrue(nodeFilterValue.containsValue(nodeFilterProperty.getValue())
976                 , "Invalid value for added directive node filter found in TOSCA Template");
977         assertTrue(nodeFilterValue.containsKey(nodeFilterProperty.getLogicalOperator().getName())
978                 , "Invalid logical operator for added directive node filter found in TOSCA Template");
979     }
980
981     private Map<?,?> getDirectiveNodeFilterFromYaml(final Map<?,?> yaml, String nodeTemplateName) {
982         final Map<?, ?> topology = (Map<?, ?>) yaml.get("topology_template");
983         final Map<?, ?> nodeTemplates = (Map<?, ?>) topology.get("node_templates");
984         final Map<?, ?> resourceNode = (Map<?, ?>) nodeTemplates.get(nodeTemplateName);
985         return (Map<?, ?>) resourceNode.get("node_filter");
986     }
987 }