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