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