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