e944ab329a0c42efb992809ad4528330f6853376
[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.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.CompositionInterfaceOperationsModal;
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 CompositionInterfaceOperationsModal.InterfaceOperationsData interfaceOperationsData =
251             new CompositionInterfaceOperationsModal.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 List<String> propertyNames = vfcPropertiesPage.getPropertyNames();
288         final ServiceDependencyProperty serviceDependencyProperty = new ServiceDependencyProperty(propertyNames.get(0), value, operator);
289
290         homePage.getTopNavComponent().clickOnHome();
291         homePage.isLoaded();
292         homePage.clickOnComponent(vfResourceCreateData.getName());
293
294         componentPage.isLoaded();
295         final CompositionPage compositionPage = componentPage.goToComposition();
296         compositionPage.isLoaded();
297         compositionPage.selectNode(vfcNameInComposition);
298
299         final CreateDirectiveNodeFilterFlow createDirectiveNodeFilterFlow =
300                 new CreateDirectiveNodeFilterFlow(webDriver, 2, DirectiveType.SELECT, serviceDependencyProperty);
301         createDirectiveNodeFilterFlow.run(componentPage);
302
303         verifyAvailableDirectiveTypes(createDirectiveNodeFilterFlow.getDirectiveOptions());
304
305         verifyAvailablePropertyNames(propertyNames, createDirectiveNodeFilterFlow.getPropertyOptions());
306
307         componentPage = compositionPage.goToGeneral();
308         componentPage.isLoaded();
309         final Map<?, ?> yaml = downloadToscaTemplate();
310         verifyToscaTemplateHasDirectiveNodeFilter(yaml, serviceDependencyProperty, vfcNameInComposition);
311     }
312
313     @Test(dependsOnMethods = "addComponentProperty")
314     public void declareInputFromProperties() throws Exception {
315         componentPage = (ComponentPage) homePage.clickOnComponent(vfResourceCreateData.getName());
316         componentPage.isLoaded();
317
318         ResourcePropertiesAssignmentPage propertiesAssignmentPage = componentPage.goToPropertiesAssignment();
319         propertiesAssignmentPage.isLoaded();
320
321         declareInputToBaseService(propertiesAssignmentPage, "property1");
322         declareInputToInstanceProperties(propertiesAssignmentPage, "resourceSubtype");
323         verifyToscaTemplateHasDeclareInput(downloadToscaTemplate());
324     }
325
326     @Test(dependsOnMethods = "createBaseService")
327     public void addComponentInputs() throws Exception {
328         inputsToBeAddedMap = loadInputsToAdd();
329         addInput(inputsToBeAddedMap);
330         verifyToscaTemplateAddInput(downloadToscaTemplate());
331     }
332
333     private void checkMetadata(final Map<String, Object> map, final ResourceCreateData createdData) {
334         final Map<String, Object> metadata = getMapEntry(map, "metadata");
335
336         assertEquals(createdData.getName(), metadata.get("name"));
337         assertEquals(createdData.getDescription(), metadata.get("description"));
338         assertEquals("Generic", metadata.get("category"));
339         assertThat((String) metadata.get("type"), not(emptyString()));
340         assertEquals(createdData.getCategory(), metadata.get("subcategory"));
341         assertEquals(createdData.getVendorName(), metadata.get("resourceVendor"));
342         assertEquals(createdData.getVendorRelease(), metadata.get("resourceVendorRelease"));
343         assertEquals(createdData.getVendorModelNumber(), metadata.get("reourceVendorModelNumber"));
344     }
345
346     private void checkTopologyTemplate(final Map<String, Object> map) {
347         final Map<String, Object> mapEntry = getMapEntry(map, "topology_template");
348         assertNotNull(mapEntry);
349
350         final Map<String, Object> inputs = getMapEntry(mapEntry, "inputs");
351         assertThat(inputs, not(anEmptyMap()));
352
353         final Map<String, Object> outputs = getMapEntry(mapEntry, "outputs");
354         assertThat(outputs, not(anEmptyMap()));
355         assertEquals(2, outputs.keySet().stream().filter(s -> (s.contains("_attr_1") || s.contains("_attr_3")) && !s.contains("_attr_2")).count());
356
357         final Map<String, Object> nodeTemplates = getMapEntry(mapEntry, "node_templates");
358         assertThat(nodeTemplates, not(anEmptyMap()));
359
360         final Map<String, Object> substitutionMappings = getMapEntry(mapEntry, "substitution_mappings");
361         assertThat(substitutionMappings, not(anEmptyMap()));
362
363         final Map<String, Object> attributes = getMapEntry(substitutionMappings, "attributes");
364         assertThat(attributes, not(anEmptyMap()));
365         assertEquals(2, attributes.keySet().stream().filter(s -> (s.contains("_attr_1") || s.contains("_attr_3")) && !s.contains("_attr_2")).count());
366     }
367
368     /**
369      * Updates an Interface operation from a selected Node (VFC)
370      * @param compositionPage the composition page
371      * @param interfaceOperationsData the interface definition
372      * @throws IOException
373      */
374     private void updateInterfaceOperation(final CompositionPage compositionPage,
375         final CompositionInterfaceOperationsModal.InterfaceOperationsData interfaceOperationsData) throws IOException {
376         final CompositionDetailSideBarComponent detailSideBar = compositionPage.getDetailSideBar();
377         detailSideBar.isLoaded();
378         final CompositionInterfaceOperationsTab compositionInterfaceOperationsTab =
379             (CompositionInterfaceOperationsTab) detailSideBar.selectTab(CompositionDetailTabName.INTERFACE_OPERATIONS);
380         compositionInterfaceOperationsTab.isLoaded();
381         ExtentTestActions.takeScreenshot(Status.INFO, "compositionInterfaceOperationsTab",
382             "Composition Interface Operations Tab loaded");
383         assertTrue(compositionInterfaceOperationsTab.isOperationPresent(interfaceOperationName));
384         final CompositionInterfaceOperationsModal compositionInterfaceOperationsModal = compositionInterfaceOperationsTab
385             .clickOnOperation(interfaceOperationName);
386         compositionInterfaceOperationsModal.isLoaded();
387         ExtentTestActions.takeScreenshot(Status.INFO, "update-interface-operation-modal", "Loading Interface Operations Modal");
388         compositionInterfaceOperationsModal.addInput();
389         compositionInterfaceOperationsModal.updateInterfaceOperation(interfaceOperationsData);
390         compositionInterfaceOperationsTab.isLoaded();
391         ExtentTestActions.addScreenshot(Status.INFO, "updated-interface-operation",
392             "The Interface operation from the selected Node was successfully updated");
393         // Gives time for UI to load the Updated Interface Operation
394         final CompositionInformationTab compositionInformationTab =
395             (CompositionInformationTab) detailSideBar.selectTab(CompositionDetailTabName.INFORMATION);
396         compositionInformationTab.isLoaded();
397         validateUpdatedInterfaceOperation(detailSideBar, interfaceOperationsData);
398     }
399
400     /**
401      * Validates if the Updated Interface Operation has the expected values
402      * @param detailSideBar The composition Page
403      * @param interfaceOperationsData The Updated Interface Definition
404      */
405     private void validateUpdatedInterfaceOperation(final CompositionDetailSideBarComponent detailSideBar,
406                                                    final CompositionInterfaceOperationsModal.InterfaceOperationsData interfaceOperationsData) {
407         final CompositionInterfaceOperationsTab compositionInterfaceOperationsTab = (CompositionInterfaceOperationsTab) detailSideBar
408             .selectTab(CompositionDetailTabName.INTERFACE_OPERATIONS);
409         compositionInterfaceOperationsTab.isLoaded();
410         assertTrue(compositionInterfaceOperationsTab.isOperationPresent(interfaceOperationName));
411         assertTrue(compositionInterfaceOperationsTab.isDescriptionPresent());
412         final CompositionInterfaceOperationsModal compositionInterfaceOperationsModal = compositionInterfaceOperationsTab
413             .clickOnOperation(interfaceOperationName);
414         compositionInterfaceOperationsModal.isLoaded();
415         ExtentTestActions.takeScreenshot(Status.INFO, "validate-updated-interface-operation",
416             "Loading the Interface Operations Modal for validating");
417         assertThat("The Interface Operation Description should match", interfaceOperationsData.getDescription(),
418             equalToIgnoringCase(compositionInterfaceOperationsModal.getDescription()));
419         assertThat("The Interface Operation Implementation Name should match", interfaceOperationsData.getImplementationName(),
420             equalToIgnoringCase(compositionInterfaceOperationsModal.getImplementationName()));
421         assertThat("The Interface Operation Input key should match", interfaceOperationsData.getInputName(),
422             equalToIgnoringCase(compositionInterfaceOperationsModal.getInputName()));
423         assertThat("The Interface Operation Input Value should match", interfaceOperationsData.getInputValue(),
424             equalToIgnoringCase(compositionInterfaceOperationsModal.getInputValue()));
425         compositionInterfaceOperationsModal.clickOnCancel();
426     }
427
428     private void verifyToscaTemplateHasUpdatedInterfaceOperation(final Map<?, ?> toscaTemplateYaml,
429         final CompositionInterfaceOperationsModal.InterfaceOperationsData interfaceOperationsData) {
430
431         assertNotNull(toscaTemplateYaml, "No contents in TOSCA Template");
432         final Map<String, Object> topologyTemplateTosca = getMapEntry((Map<String, Object>) toscaTemplateYaml, "topology_template");
433         assertThat("Should contain a topology_template entry", toscaTemplateYaml, is(notNullValue()));
434         final Map<String, Object> nodeTemplatesTosca = getMapEntry(topologyTemplateTosca, "node_templates");
435         assertThat("Should contain a node_templates entry", nodeTemplatesTosca, is(notNullValue()));
436         final Optional<Entry<String, Object>> nodeWithInterfaceOperation = nodeTemplatesTosca.entrySet().stream()
437             .filter(s -> s.getKey().startsWith(vfcs.get(1).getName())).findFirst();
438         assertThat("Should contain a node (VFC)", nodeWithInterfaceOperation.isPresent(), is(true));
439         final Map<String, Object> interfacesEntry = (Map<String, Object>) nodeWithInterfaceOperation.get().getValue();
440         assertThat("The Interfaces Entry should not be empty", interfacesEntry, not(anEmptyMap()));
441         final Map<String, Object> interfaceOperations = (Map<String, Object>) interfacesEntry.get("interfaces");
442         assertThat("The Interface Entry should have operations", interfaceOperations, not(anEmptyMap()));
443         final Map<String, Object> interfaceNameMap = (Map<String, Object>) interfaceOperations.get(interfaceName);
444         assertThat(String.format("'%s' should contain a Interface Name entry '%s'", interfaceNameMap, interfaceName),
445             interfaceOperations, not(anEmptyMap()));
446         final Map<String, Object> updatedInterfaceOperation = (Map<String, Object>) interfaceNameMap.get(interfaceOperationName);
447         assertThat(String.format("'%s' should contain a Interface Operation Name '%s'", updatedInterfaceOperation, interfaceOperationName),
448             updatedInterfaceOperation, not(anEmptyMap()));
449         assertThat("The Interface Operation Description should match",
450             updatedInterfaceOperation.get("description").equals(interfaceOperationsData.getDescription()));
451         assertThat("The Interface Operation Implementation Name should match",
452             updatedInterfaceOperation.get("implementation").equals(interfaceOperationsData.getImplementationName()));
453         final Map<String, Object> updatedInterfaceOperationInput = (Map<String, Object>) updatedInterfaceOperation.get("inputs");
454         assertThat("The Interface Operation Input Key should match",
455             updatedInterfaceOperationInput.containsKey(interfaceOperationsData.getInputName()));
456         assertThat("The Interface Operation Input Value should match",
457             updatedInterfaceOperationInput.containsValue(interfaceOperationsData.getInputValue()));
458     }
459
460     private Map<String, Object> downloadToscaArtifact(final ComponentPage resourceCreatePage) throws UnzipException {
461         final DownloadCsarArtifactFlow downloadCsarArtifactFlow = downloadToscaCsar(resourceCreatePage);
462         final ToscaArtifactsPage toscaArtifactsPage = downloadCsarArtifactFlow.getLandedPage()
463             .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected ToscaArtifactsPage"));
464
465         assertThat("No artifact download was found", toscaArtifactsPage.getDownloadedArtifactList(), not(empty()));
466         final String downloadedCsarName = toscaArtifactsPage.getDownloadedArtifactList().get(0);
467         final String downloadFolderPath = getConfig().getDownloadAutomationFolder();
468         final Map<String, byte[]> filesFromZip = FileHandling.getFilesFromZip(downloadFolderPath, downloadedCsarName);
469         final Optional<String> resourceEntryOpt = filesFromZip.keySet().stream()
470             .filter(s -> s.equals("Definitions/" + downloadedCsarName.replace("-csar.csar", "-template.yml")))
471             .findFirst();
472         if (resourceEntryOpt.isEmpty()) {
473             fail("Could not find the resource package in Definitions");
474         }
475         return loadYamlObject(filesFromZip.get(resourceEntryOpt.get()));
476     }
477
478     private void declareInputToBaseService(ResourcePropertiesAssignmentPage propertiesAssignmentPage, String propertyName){
479         propertiesAssignmentPage.selectProperty(propertyName);
480         propertiesAssignmentPage.clickOnDeclareInput();
481         propertiesAssignmentPage.clickInputTab(propertyName);
482         propertiesAssignmentPage.isInputPresent(vfResourceCreateData.getName() + "_" + propertyName);
483     }
484
485     private void declareInputToInstanceProperties(ResourcePropertiesAssignmentPage propertiesAssignmentPage, String propertyName){
486         propertiesAssignmentPage.selectPropertiesTab();
487         propertiesAssignmentPage.loadCompositionTab();
488         propertiesAssignmentPage.loadComponentInstanceProperties(vfcs.get(0).getName().concat(" 0"));
489         propertiesAssignmentPage.selectProperty(propertyName);
490         propertiesAssignmentPage.clickOnDeclareInput();
491         propertiesAssignmentPage.clickInputTab(propertyName);
492         propertiesAssignmentPage.isInputPresent(vfResourceCreateData.getName() + "_" + vfcs.get(0).getName());
493     }
494
495     private CreateVfFlow createVF() {
496         final ResourceCreateData vfCreateData = createVfFormData();
497         final CreateVfFlow createVfFlow = new CreateVfFlow(webDriver, vfCreateData);
498         createVfFlow.run(homePage);
499         return createVfFlow;
500     }
501
502     private ResourceCreateData createVfFormData() {
503         vfResourceCreateData = new ResourceCreateData();
504         vfResourceCreateData.setRandomName(ElementFactory.getResourcePrefix() + "-VF");
505         vfResourceCreateData.setCategory(ResourceCategoryEnum.GENERIC_ABSTRACT.getSubCategory());
506         vfResourceCreateData.setTagList(Arrays.asList(vfResourceCreateData.getName(), "createVF"));
507         vfResourceCreateData.setDescription("aDescription");
508         vfResourceCreateData.setVendorName("EST");
509         vfResourceCreateData.setVendorRelease("4.1.1");
510         vfResourceCreateData.setVendorModelNumber("0001");
511         return vfResourceCreateData;
512     }
513
514     private CreateVfcFlow createVFC(final String vfcFullFilename, final String resourceName) {
515         final ResourceCreateData vfcCreateData = createVfcFormData(resourceName);
516         final CreateVfcFlow createVfcFlow = new CreateVfcFlow(webDriver, vfcCreateData, vfcFullFilename);
517         createVfcFlow.run(homePage);
518         ExtentTestActions.takeScreenshot(Status.INFO, "vfc-created", String.format("VFC '%s' was created", resourceName));
519         assertThat(vfcs, notNullValue());
520         vfcs.add(vfcCreateData);
521         return createVfcFlow;
522     }
523
524     private ResourceCreateData createVfcFormData(final String resourceName) {
525         final ResourceCreateData vfcCreateData = new ResourceCreateData();
526         vfcCreateData.setRandomName(resourceName);
527         vfcCreateData.setCategory(ResourceCategoryEnum.GENERIC_NETWORK_ELEMENTS.getSubCategory());
528         vfcCreateData.setTagList(Arrays.asList(vfcCreateData.getName(), "importVFC"));
529         vfcCreateData.setDescription("aDescription");
530         vfcCreateData.setVendorName("EST");
531         vfcCreateData.setVendorRelease("4.1.1");
532         vfcCreateData.setVendorModelNumber("0001");
533         return vfcCreateData;
534     }
535
536     private AddNodeToCompositionFlow addNodeToCompositionAndCreateRelationship() {
537         assertThat(vfcs, hasSize(2));
538         final ComponentData parentComponent = new ComponentData();
539         parentComponent.setName(vfResourceCreateData.getName());
540         parentComponent.setVersion("0.1");
541         parentComponent.setComponentType(ComponentType.RESOURCE);
542
543         // Adds networkFunction to VF composition
544         final ComponentData networkFunction = new ComponentData();
545         networkFunction.setName(vfcs.get(0).getName());
546         networkFunction.setVersion("1.0");
547         networkFunction.setComponentType(ComponentType.RESOURCE);
548         final CompositionPage compositionPage = resourceCreatePage.goToComposition();
549         compositionPage.isLoaded();
550         AddNodeToCompositionFlow addNodeToCompositionFlow = addNodeToComposition(parentComponent, networkFunction, compositionPage);
551         networkFunctionInstance = addNodeToCompositionFlow.getCreatedComponentInstance()
552             .orElseThrow(() -> new UiTestFlowRuntimeException("Could not get the created component instance"));
553
554         // Adds networkService to VF composition
555         final ComponentData networkService = new ComponentData();
556         networkService.setName(vfcs.get(1).getName());
557         networkService.setVersion("1.0");
558         networkService.setComponentType(ComponentType.RESOURCE);
559         addNodeToCompositionFlow = addNodeToComposition(parentComponent, networkService, compositionPage);
560         networkServiceInstance = addNodeToCompositionFlow.getCreatedComponentInstance()
561             .orElseThrow(() -> new UiTestFlowRuntimeException("Could not get the created component instance"));
562
563         // Creates a dependsOn relationship from networkServiceInstance to networkFunctionInstance
564         createRelationship(compositionPage, networkFunctionInstance.getName(), "tosca.capabilities.Node",
565             networkServiceInstance.getName(), "tosca.capabilities.Node");
566
567         return addNodeToCompositionFlow;
568     }
569
570     public AddNodeToCompositionFlow addNodeToComposition(final ComponentData parentComponent,
571                                                          final ComponentData resourceToAdd,
572                                                          CompositionPage compositionPage) {
573         final AddNodeToCompositionFlow addNodeToCompositionFlow = new AddNodeToCompositionFlow(webDriver, parentComponent, resourceToAdd);
574         compositionPage = (CompositionPage) addNodeToCompositionFlow.run(compositionPage)
575             .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected CompositionPage"));
576         compositionPage.isLoaded();
577         ExtentTestActions.takeScreenshot(Status.INFO, "node-added-to-composition",
578             String.format("Resource '%s' was added to composition", resourceToAdd.getName()));
579         return addNodeToCompositionFlow;
580     }
581
582     /**
583      * Creates a DependsOn relationship between the imported VFCs
584      * @param compositionPage Composition Page
585      * @param fromComponentInstanceName VFC - Network Function
586      * @param fromCapability Node Capability
587      * @param toComponentInstanceName  VFC - Network Service
588      * @param toRequirement Node Requirement
589      */
590     private void createRelationship(final CompositionPage compositionPage, final String fromComponentInstanceName,
591                                     final String fromCapability, final String toComponentInstanceName, final String toRequirement) {
592         final RelationshipInformation relationshipInformation =
593             new RelationshipInformation(fromComponentInstanceName, fromCapability, toComponentInstanceName, toRequirement);
594         final CreateRelationshipFlow createRelationshipFlow = new CreateRelationshipFlow(webDriver, relationshipInformation,
595             new InterfaceOperationsData(interfaceName, interfaceOperationName, implementationName, inputName, inputValue));
596         createRelationshipFlow.run(compositionPage).orElseThrow(() -> new UiTestFlowRuntimeException("Expecting a CompositionPage instance"));
597         ExtentTestActions.takeScreenshot(Status.INFO, "relationship",
598             String.format("Relationship from networkFunctionInstance '%s' to networkServiceInstanceResource '%s' was created",
599                 fromComponentInstanceName, toComponentInstanceName));
600     }
601
602     /**
603      * Adds a property to the base service
604      * @param propertyMap map of properties to be added
605      */
606     private void addProperty(final Map<String, String> propertyMap) {
607         componentPage = (ComponentPage) homePage.clickOnComponent(vfResourceCreateData.getName());
608         componentPage.isLoaded();
609         final AddComponentPropertyFlow addComponentPropertyFlow = new AddComponentPropertyFlow(webDriver, propertyMap);
610         addComponentPropertyFlow.run(componentPage.goToPropertiesAssignment());
611     }
612
613     /**
614      * Adds a input to the base service
615      * @param inputMap map of inputs to be added
616      */
617     private void addInput(final Map<String, String> inputMap) {
618         componentPage = (ComponentPage) homePage.clickOnComponent(vfResourceCreateData.getName());
619         componentPage.isLoaded();
620         final AddComponentInputFlow addComponentInputFlow = new AddComponentInputFlow(webDriver, inputMap);
621         addComponentInputFlow.run(componentPage.goToPropertiesAssignment());
622     }
623
624     /**
625      * Edits a property to add a value
626      * @param propertyMap map of properties to be edited
627      */
628     private ComponentPage addValueToProperty(final Map<String, Object> propertyMap) {
629         final EditComponentPropertiesFlow editComponentPropertiesFlow = new EditComponentPropertiesFlow(webDriver, propertyMap);
630         return editComponentPropertiesFlow.run().orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected return ComponentPage"));
631     }
632
633     /**
634      * Downloads and verifies the generated tosca templates.
635      * @param componentPage the component page
636      * @throws UnzipException
637      */
638     private void downloadAndVerifyCsarPackage(final ComponentPage componentPage) throws UnzipException {
639         checkCsarPackage(downloadCsarPackage(componentPage));
640     }
641
642     /**
643      * Downloads and verifies if the generated Tosca template contains the expected properties.
644      * @throws UnzipException
645      * @param componentPage
646      */
647     private void downloadAndVerifyCsarPackageAfterAddProperty(final ComponentPage componentPage) throws UnzipException {
648         verifyPropertiesOnGeneratedTemplate(downloadCsarPackage(componentPage));
649     }
650
651     private String downloadCsarPackage(final ComponentPage componentPage) {
652         final DownloadCsarArtifactFlow downloadCsarArtifactFlow = downloadToscaCsar(componentPage);
653         final ToscaArtifactsPage toscaArtifactsPage = downloadCsarArtifactFlow.getLandedPage()
654             .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected ToscaArtifactsPage"));
655         assertThat("No artifact download was found", toscaArtifactsPage.getDownloadedArtifactList(), not(empty()));
656         return toscaArtifactsPage.getDownloadedArtifactList().get(0);
657     }
658
659     /**
660      * Downloads the generated CSAR package.
661      * @param componentPage the component page
662      * @return the Downloaded Tosca CSAR file
663      */
664     private DownloadCsarArtifactFlow downloadToscaCsar(final ComponentPage componentPage) {
665         final DownloadCsarArtifactFlow downloadCsarArtifactFlow = new DownloadCsarArtifactFlow(webDriver);
666         downloadCsarArtifactFlow.setWaitBeforeGetTheFile(5L);
667         downloadCsarArtifactFlow.run(componentPage);
668         return downloadCsarArtifactFlow;
669     }
670
671     /**
672      * Verifies if the generated Tosca template contains the expected properties.
673      * @param downloadedCsarName the downloaded csar file name
674      * @throws UnzipException
675      */
676     private void verifyPropertiesOnGeneratedTemplate(final String downloadedCsarName) throws UnzipException {
677         final Map<String, byte[]> filesFromZip = extractFilesFromCsar(downloadedCsarName);
678         final String virtualFunctionName = vfResourceCreateData.getName().replace("-", "").toLowerCase();
679         final String vfResourceTemplateFile = "Definitions/resource-" + virtualFunctionName + "-template-interface.yml";
680         final String interfaceTemplateFile = filesFromZip.keySet().stream()
681             .filter(filename -> filename.equalsIgnoreCase(vfResourceTemplateFile)).findFirst()
682             .orElseThrow(() -> new UiTestFlowRuntimeException(String.format("Resource template file not found %s", vfResourceTemplateFile)));
683         final byte[] toscaInterfaceTemplateGenerated = filesFromZip.get(interfaceTemplateFile);
684         assertThat("The Generated Tosca template should not be null", toscaInterfaceTemplateGenerated, is(notNullValue()));
685         final Map<String, Object> interfaceTemplateYamlMap = loadYamlObject(toscaInterfaceTemplateGenerated);
686         final Map<String, Object> nodeTypesYamlMap = getMapEntry(interfaceTemplateYamlMap, "node_types");
687         assertThat(String.format("'%s' should contain a node_types entry", interfaceTemplateYamlMap), nodeTypesYamlMap, is(notNullValue()));
688         final Map<String, Object> properties = (Map) nodeTypesYamlMap.values().stream().filter(stringObjectEntry -> stringObjectEntry != null)
689             .collect(Collectors.toList()).get(0);
690         final Map<String, Object> propertiesFoundMap = (Map<String, Object>) properties.get("properties");
691         assertThat(String.format("The generated template file %s should contain all added properties", vfResourceTemplateFile),
692             propertiesFoundMap.keySet().containsAll(propertiesToBeAddedMap.keySet()), is(true));
693     }
694
695     /**
696      * Checks if the downloaded Tosca csar includes the node templates for the added VFCs,
697      * the generated service template declared “tosca_simple_yaml_1_3” as its Tosca version,
698      * the generated csar contains the node type definitions for the added VFCs in the Definitions directory,
699      * the interface template contains the relationship declaration
700      * @param downloadedCsarName download Tosca CSAR filename
701      * @throws UnzipException
702      */
703     private void checkCsarPackage(final String downloadedCsarName) throws UnzipException {
704         final Map<String, byte[]> filesFromZip = extractFilesFromCsar(downloadedCsarName);
705         final String virtualFunctionName = vfResourceCreateData.getName().replace("-", "").toLowerCase();
706         final List<String> expectedDefinitionFolderFileList = getExpectedDefinitionFolderFileList(virtualFunctionName);
707         final Map<String, byte[]> expectedFilesFromZipMap = filesFromZip.entrySet().parallelStream()
708             .filter(key -> expectedDefinitionFolderFileList.stream()
709                 .anyMatch(filename -> filename.equalsIgnoreCase(key.getKey()))).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
710         final String vfResourceTemplateFile = "Definitions/resource-" + virtualFunctionName + "-template.yml";
711         final String generatedTemplateFile = expectedFilesFromZipMap.keySet().stream()
712             .filter(filename -> filename.equalsIgnoreCase(vfResourceTemplateFile)).findFirst()
713             .orElseThrow(() -> new UiTestFlowRuntimeException(String.format("Resource template file not found %s", vfResourceTemplateFile)));
714         final byte[] toscaTemplateGenerated = filesFromZip.get(generatedTemplateFile);
715         assertThat(toscaTemplateGenerated, is(notNullValue()));
716         verifyGeneratedTemplate(toscaTemplateGenerated, generatedTemplateFile);
717         verifyNodesRelationship(expectedFilesFromZipMap, virtualFunctionName, filesFromZip);
718     }
719
720     private Map<String, byte[]> extractFilesFromCsar(final String downloadedCsarName) throws UnzipException {
721         final String downloadFolderPath = getConfig().getDownloadAutomationFolder();
722         final Map<String, byte[]> filesFromCsar = FileHandling.getFilesFromZip(downloadFolderPath, downloadedCsarName);
723         return filesFromCsar;
724     }
725
726     private void verifyGeneratedTemplate(final byte[] generatedTemplateData, final String generatedTemplateFile) {
727         final Map<String, Object> templateYamlMap = loadYamlObject(generatedTemplateData);
728         final boolean hasToscaDefinitionVersionEntry = templateYamlMap.containsKey("tosca_definitions_version");
729         assertThat(String.format("'%s' should contain tosca_definitions_version entry", generatedTemplateFile), hasToscaDefinitionVersionEntry,
730             is(true));
731         final String toscaVersion = (String) templateYamlMap.get("tosca_definitions_version");
732         assertThat(String.format("'%s' tosca_definitions_version entry should have tosca_simple_yaml_1_3 value", generatedTemplateFile),
733             toscaVersion.equalsIgnoreCase("tosca_simple_yaml_1_3"));
734         final Map<String, Object> topologyTemplateTosca = getMapEntry(templateYamlMap, "topology_template");
735         assertThat(String.format("'%s' should contain a topology_template entry", generatedTemplateFile), topologyTemplateTosca, is(notNullValue()));
736         final Map<String, Object> nodeTemplatesTosca = getMapEntry(topologyTemplateTosca, "node_templates");
737         assertThat(String.format("'%s' should contain a node_templates entry", generatedTemplateFile), nodeTemplatesTosca, is(notNullValue()));
738         final List<String> nodeTemplateFound = nodeTemplatesTosca.keySet().parallelStream().filter(s -> vfcs.stream()
739             .anyMatch(vfc -> s.startsWith(vfc.getName()))).collect(Collectors.toList());
740         assertThat(String.format("'%s' should contain the node type definitions for the added VFCs '%s'", nodeTemplatesTosca, vfcs),
741             nodeTemplateFound, hasSize(vfcs.size()));
742         verifyRelationshipTemplate(topologyTemplateTosca, generatedTemplateFile);
743     }
744
745     private void verifyRelationshipTemplate(final Map<String, Object> topologyTemplateToscaMap, final String generatedTemplateFile) {
746         final Map<String, Object> relationshipTemplateMap = getMapEntry(topologyTemplateToscaMap, "relationship_templates");
747         assertThat(String.format("'%s' should contain a topology_template entry", generatedTemplateFile), relationshipTemplateMap,
748             is(notNullValue()));
749         final String result = Arrays.asList(relationshipTemplateMap.values()).toString();
750         assertThat(String.format("'%s' should contain a DependsOn relationship", relationshipTemplateMap),
751             result.contains("tosca.relationships.DependsOn"), is(true));
752         assertThat(String.format("'%s' should contain interfaces entry", relationshipTemplateMap), result.contains("interfaces"), is(true));
753         assertThat(String.format("'%s' should contain a Interface Name entry '%s'", relationshipTemplateMap, interfaceName),
754             result.contains(interfaceName), is(true));
755         assertThat(String.format("'%s' should contain a Interface Operation Name '%s'", relationshipTemplateMap, interfaceOperationName),
756             result.contains(interfaceOperationName), is(true));
757         assertThat(String.format("'%s' should contain Implementation Name '%s'", relationshipTemplateMap, implementationName),
758             result.contains(implementationName), is(true));
759         assertThat(String.format("'%s' should contain inputs entry", relationshipTemplateMap), result.contains("inputs"), is(true));
760         assertThat(String.format("'%s' should contain Input Name '%s'", relationshipTemplateMap, inputName), result.contains(inputName),
761             is(true));
762         assertThat(String.format("'%s' should contain Input Value '%s'", relationshipTemplateMap, inputValue), result.contains(inputValue),
763             is(true));
764     }
765
766     private void verifyNodesRelationship(final Map<String, byte[]> expectedFilesFromZipMap, final String virtualFunctionName,
767                                          final Map<String, byte[]> filesFromZip) {
768         final String vfResourceTemplateFile = "Definitions/resource-" + virtualFunctionName + "-template-interface.yml";
769         final String interfaceTemplateFile = expectedFilesFromZipMap.keySet().stream()
770             .filter(filename -> filename.equalsIgnoreCase(vfResourceTemplateFile)).findFirst()
771             .orElseThrow(() -> new UiTestFlowRuntimeException(String.format("Resource template file not found %s", vfResourceTemplateFile)));
772         final byte[] toscaInterfaceTemplateGenerated = filesFromZip.get(interfaceTemplateFile);
773         assertThat(toscaInterfaceTemplateGenerated, is(notNullValue()));
774         final Map<String, Object> interfaceTemplateYamlMap = loadYamlObject(toscaInterfaceTemplateGenerated);
775         final Map<String, Object> nodeTypesYamlMap = getMapEntry(interfaceTemplateYamlMap, "node_types");
776         assertThat(String.format("'%s' should contain a node_types entry", interfaceTemplateYamlMap), nodeTypesYamlMap, is(notNullValue()));
777         final String result = Arrays.asList(nodeTypesYamlMap.values()).toString();
778         assertThat(String.format("'%s' should contain a capabilities entry", nodeTypesYamlMap), result.contains("capabilities"), is(true));
779         assertThat(String.format("'%s' should contain a requirements entry", nodeTypesYamlMap), result.contains("requirements"), is(true));
780         assertThat(String.format("'%s' should contain a relationship entry", nodeTypesYamlMap), result.contains("relationship"), is(true));
781         assertThat(String.format("'%s' should contain a DependsOn relationship value", nodeTypesYamlMap),
782             result.contains("tosca.relationships.DependsOn"), is(true));
783     }
784
785     private List<String> getExpectedDefinitionFolderFileList(final String vfResourceName) {
786         final List<String> expectedDefinitionFolderFileList = new ArrayList<>();
787         vfcs.forEach(vfc -> expectedDefinitionFolderFileList.add("Definitions/resource-" + vfc.getName() + "-template.yml"));
788         expectedDefinitionFolderFileList.add("Definitions/resource-" + vfResourceName + "-template.yml");
789         expectedDefinitionFolderFileList.add("Definitions/resource-" + vfResourceName + "-template-interface.yml");
790         return expectedDefinitionFolderFileList;
791     }
792
793     private void verifyToscaTemplateHasDeclareInput(Map<?, ?> yaml) {
794         assertNotNull(yaml, "No contents in TOSCA Template");
795         final Map<String, Object> toscaYaml = (Map<String, Object>) yaml;
796         final Map<String, Object> topologyTemplateTosca = getMapEntry(toscaYaml, "topology_template");
797         assertThat(String.format("'%s' should contain a topology_template entry", toscaYaml), topologyTemplateTosca,
798             notNullValue());
799         final Map<String, Object> inputsTosca = getMapEntry(topologyTemplateTosca, "inputs");
800         assertThat(String.format("'%s' should contain a inputs entry", toscaYaml), inputsTosca, notNullValue());
801         assertEquals(2, inputsTosca.keySet().stream()
802             .filter(s -> (s.contains("resourceSubtype") || s.contains("property1"))).count());
803         final Map<String, Object> substitutionMapping = getMapEntry(topologyTemplateTosca, "substitution_mappings");
804         assertThat(String.format("'%s' should contain a substitution_mappings entry", toscaYaml), substitutionMapping,
805             notNullValue());
806         final Map<String, Object> substitutionMappingProperties = getMapEntry(substitutionMapping, "properties");
807         assertThat(String.format("'%s' should contain a properties entry", toscaYaml), substitutionMappingProperties,
808             notNullValue());
809         assertEquals(2, substitutionMappingProperties.keySet().stream()
810             .filter(s -> (s.contains("resourceSubtype") || s.contains("property1"))).count());
811     }
812
813     private void verifyToscaTemplateAddInput(Map<?, ?> yaml) {
814         final Map<String, String> inputMap = loadInputsToAdd();
815         assertNotNull(yaml, "No contents in TOSCA Template");
816         final Map<String, Object> toscaYaml = (Map<String, Object>) yaml;
817         final Map<String, Object> topologyTemplateTosca = getMapEntry(toscaYaml, "topology_template");
818         assertThat(String.format("'%s' should contain a topology_template entry", toscaYaml), topologyTemplateTosca,
819             notNullValue());
820         final Map<String, Object> inputsTosca = getMapEntry(topologyTemplateTosca, "inputs");
821         assertThat(String.format("'%s' should contain a inputs entry", toscaYaml), inputsTosca, notNullValue());
822         assertEquals(3, inputsTosca.keySet().stream()
823             .filter(s -> inputMap.containsKey(s)).count());
824     }
825
826     private Map<String, Object> getMapEntry(final Map<?, ?> yamlObj, final String entryName) {
827         try {
828             return (Map<String, Object>) yamlObj.get(entryName);
829         } catch (final Exception e) {
830             final String errorMsg = String.format("Could not get the '%s' entry.", entryName);
831             LOGGER.error(errorMsg, e);
832             fail(errorMsg + "Error message: " + e.getMessage());
833         }
834         return null;
835     }
836
837     private Map<String, Object> loadYamlObject(final byte[] definitionYamlFile) {
838         return new Yaml().load(new String(definitionYamlFile));
839     }
840
841     private Map<String, String> loadPropertiesToAdd() {
842         final Map<String, String> propertyMap = new HashMap<>();
843         propertyMap.put("property1", "string");
844         propertyMap.put("property2", "integer");
845         propertyMap.put("property3", "boolean");
846         propertyMap.put("property4", "list");
847         propertyMap.put("property5", "map");
848         propertyMap.put("property6", "scalar-unit.size");
849         return propertyMap;
850     }
851
852     private Map<String, Object> loadPropertiesToEdit() {
853         final Map<String, Object> propertyMap = new HashMap<>();
854         propertyMap.put("property1", "Integration Test");
855         propertyMap.put("property2", 100);
856         propertyMap.put("property3", Boolean.TRUE);
857         propertyMap.put("property4", Arrays.asList("PropListV1", "PropListV2", "PropListV3"));
858         final Map<String, String> stringMap = new HashMap<>();
859         stringMap.put("PropMapKey1", "PropMapValue1");
860         stringMap.put("PropMapKey2", "PropMapValue2");
861         stringMap.put("PropMapKey3", "PropMapValue3");
862         propertyMap.put("property5", stringMap);
863         propertyMap.put("property6", 500);
864         return propertyMap;
865     }
866
867     private Map<String, String> loadInputsToAdd() {
868         final Map<String, String> inputMap = new HashMap<>();
869         inputMap.put("input1", "string");
870         inputMap.put("input2", "integer");
871         inputMap.put("input3", "boolean");
872         return inputMap;
873     }
874
875     private void loadSubstitutionFilterProperties() {
876         final ResourcePropertiesAssignmentPage propertiesPage = componentPage.goToPropertiesAssignment();
877         propertiesPage.isLoaded();
878         ExtentTestActions.takeScreenshot(Status.INFO, "propertiesAssigment",
879             String.format("The %s Properties Assignment Page is loaded", vfResourceCreateData.getName()));
880         Map<String, String> propertyNamesAndTypes = propertiesPage.getPropertyNamesAndTypes();
881         assertThat(String.format("The Component '%s' should have properties", vfResourceCreateData.getName()), propertyNamesAndTypes,
882             not(anEmptyMap()));
883         propertyNamesAndTypes.forEach((name, type)
884             -> substitutionFilterProperties.add(new ServiceDependencyProperty(name, getPropertyValueByType(type), LogicalOperator.EQUALS)));
885     }
886
887     private String getPropertyValueByType(final String type) {
888         switch (type) {
889             case "string":
890                 return "IntegrationTest";
891             case "integer":
892                 return "202";
893             case "size":
894                 return "500";
895             case "boolean":
896                 return "TRUE";
897             case "list":
898                 return "[value1, value2]";
899             case "map":
900                 return "MyKey: MyValue";
901             default:
902                 throw new UnsupportedOperationException("Not yet implemented for " + type);
903         }
904     }
905
906     /**
907      * Downloads Tosca Template file
908      * @return the tosca template yaml file
909      * @throws Exception
910      */
911     private Map<?, ?> downloadToscaTemplate() throws Exception {
912         final DownloadToscaTemplateFlow downloadToscaTemplateFlow = new DownloadToscaTemplateFlow(webDriver);
913         final ToscaArtifactsPage toscaArtifactsPage = (ToscaArtifactsPage) downloadToscaTemplateFlow.run(componentPage).get();
914         return FileHandling.parseYamlFile(getConfig().getDownloadAutomationFolder()
915             .concat(java.io.File.separator).concat(toscaArtifactsPage.getDownloadedArtifactList().get(0)));
916     }
917
918     private void verifyToscaTemplateHasSubstitutionFilter(final Map<?, ?> yaml) {
919         assertNotNull(yaml, "No contents in TOSCA Template");
920         final List<?> substitutionFilters = (List<?>) getSubstitutionFilterFromYaml(yaml).get("properties");
921         substitutionFilterProperties.forEach(substitutionFilterProperty -> {
922             final Map<?, ?> substitutionFilterMap = (Map<?, ?>) substitutionFilters.stream()
923                 .filter(subFilter -> ((Map<?, ?>) subFilter).containsKey(substitutionFilterProperty.getName())).findAny().get();
924             assertThat("Added substitution filter not found in TOSCA Template",
925                 substitutionFilterMap.containsKey(substitutionFilterProperty.getName()));
926             final Map<?, ?> substitutionFilterValue = (Map<?, ?>) ((List<?>) substitutionFilterMap.get(substitutionFilterProperty.getName())).get(0);
927             assertThat("Substitution Filter Value should not be empty", substitutionFilterMap, not(anEmptyMap()));
928             final String expectedSubstitutionPropertyValue = substitutionFilterProperty.getValue();
929             final String actualSubstitutionPropertyValue = substitutionFilterValue.values().stream().findFirst().get() instanceof Map
930                 ? substitutionFilterValue.values().stream().findFirst().get().toString().replace("=", ": ")
931                 .replaceAll("\\{(.*?)\\}", "$1").trim()
932                 : substitutionFilterValue.values().stream().findFirst().get().toString();
933             assertThat("Invalid value for added substitution filters found in TOSCA Template",
934                 expectedSubstitutionPropertyValue.equalsIgnoreCase(actualSubstitutionPropertyValue));
935             assertThat("Invalid logical operator for added substitution filters found in TOSCA Template",
936                 substitutionFilterValue.containsKey(substitutionFilterProperty.getLogicalOperator().getName()));
937         });
938     }
939
940     private Map<?, ?> getSubstitutionFilterFromYaml(final Map<?, ?> yaml) {
941         final Map<?, ?> topology = (Map<?, ?>) yaml.get("topology_template");
942         final Map<?, ?> substitutionMappings = (Map<?, ?>) topology.get("substitution_mappings");
943         return (Map<?, ?>) substitutionMappings.get("substitution_filter");
944     }
945
946     private void verifyAvailableDirectiveTypes(final List<String> availableDirectiveTypes) {
947         assertNotNull(availableDirectiveTypes, "Expected list of available Directive Types, but recieved null");
948         Arrays.asList(DirectiveType.values()).forEach(directiveType -> {
949             assertTrue(availableDirectiveTypes.contains(directiveType.getName())
950                     , String.format("Expected directive %s to be availabe in UI options %s"
951                             , directiveType.getName(), availableDirectiveTypes.toString()));
952         });
953         ExtentTestActions.log(Status.PASS, "All expected directive types are available for selection");
954     }
955
956     private void verifyAvailablePropertyNames(List<String> propertyNames, List<String> propertyNameOptions) {
957         assertEquals(propertyNameOptions.size(), propertyNames.size(), "Mismatch in the number of properties available for selection");
958         propertyNames.forEach(name -> {
959             assertNotEquals(false, propertyNameOptions.remove(name)
960                     , String.format("Expected property %s not found in UI Select element", name));
961         });
962         ExtentTestActions.log(Status.PASS, "All expected properties are available for selection");
963     }
964
965     private void verifyToscaTemplateHasDirectiveNodeFilter(final Map<?, ?> yaml, ServiceDependencyProperty nodeFilterProperty, String nodeTemplateName) {
966         assertNotNull(yaml, "Tosca Template Yaml is not expected to be empty");
967         final List<?> nodeFilters = (List<?>) getDirectiveNodeFilterFromYaml(yaml, nodeTemplateName).get("properties");
968         final Map<?, ?> nodeFilter = (Map<?, ?>) nodeFilters.stream()
969                     .filter(yamlNodeFilter -> ((Map<?, ?>) yamlNodeFilter).containsKey(nodeFilterProperty.getName())).findAny().get();
970         assertNotNull(nodeFilter, "Added directive node filter not found in TOSCA Template");
971
972         final Map<?, ?> nodeFilterValue = (Map<?, ?>) ((List<?>) nodeFilter.get(nodeFilterProperty.getName())).get(0);
973         assertTrue(nodeFilterValue.containsValue(nodeFilterProperty.getValue())
974                 , "Invalid value for added directive node filter found in TOSCA Template");
975         assertTrue(nodeFilterValue.containsKey(nodeFilterProperty.getLogicalOperator().getName())
976                 , "Invalid logical operator for added directive node filter found in TOSCA Template");
977     }
978
979     private Map<?,?> getDirectiveNodeFilterFromYaml(final Map<?,?> yaml, String nodeTemplateName) {
980         final Map<?, ?> topology = (Map<?, ?>) yaml.get("topology_template");
981         final Map<?, ?> nodeTemplates = (Map<?, ?>) topology.get("node_templates");
982         final Map<?, ?> resourceNode = (Map<?, ?>) nodeTemplates.get(nodeTemplateName);
983         return (Map<?, ?>) resourceNode.get("node_filter");
984     }
985 }