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