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 java.io.IOException;
38 import java.util.ArrayList;
39 import java.util.Arrays;
40 import java.util.HashMap;
41 import java.util.List;
43 import java.util.Map.Entry;
44 import java.util.Optional;
45 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.DownloadToscaTemplateFlow;
69 import org.onap.sdc.frontend.ci.tests.flow.DownloadCsarArtifactFlow;
70 import org.onap.sdc.frontend.ci.tests.flow.EditComponentPropertiesFlow;
71 import org.onap.sdc.frontend.ci.tests.flow.composition.CreateRelationshipFlow;
72 import org.onap.sdc.frontend.ci.tests.flow.exception.UiTestFlowRuntimeException;
73 import org.onap.sdc.frontend.ci.tests.pages.AttributesOutputsPage;
74 import org.onap.sdc.frontend.ci.tests.pages.ComponentPage;
75 import org.onap.sdc.frontend.ci.tests.pages.ResourceCreatePage;
76 import org.onap.sdc.frontend.ci.tests.pages.ResourcePropertiesAssignmentPage;
77 import org.onap.sdc.frontend.ci.tests.pages.ResourcePropertiesPage;
78 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionDetailSideBarComponent;
79 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionDetailSideBarComponent.CompositionDetailTabName;
80 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionInformationTab;
81 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.InterfaceDefinitionOperationsModal;
82 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionInterfaceOperationsTab;
83 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionPage;
84 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.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.Ignore;
95 import org.testng.annotations.Test;
96 import org.yaml.snakeyaml.Yaml;
98 import com.aventstack.extentreports.Status;
100 public class ServiceTemplateDesignUiTests extends SetupCDTest {
102 private static final Logger LOGGER = LoggerFactory.getLogger(ServiceTemplateDesignUiTests.class);
104 private WebDriver webDriver;
105 private HomePage homePage;
106 private List<ResourceCreateData> vfcs = new ArrayList<>();
107 private ResourceCreateData vfResourceCreateData;
108 private ComponentInstance networkFunctionInstance;
109 private ComponentInstance networkServiceInstance;
110 private AddNodeToCompositionFlow addNodeToCompositionFlow;
111 private ComponentPage componentPage;
112 private Map<String, String> propertiesToBeAddedMap;
113 private ResourceCreatePage resourceCreatePage;
114 private Map<String, String> inputsToBeAddedMap;
115 private final List<ServiceDependencyProperty> substitutionFilterProperties = new ArrayList<>();
116 private final String interfaceName = "Standard";
117 private final String interfaceOperationName = "create";
118 private final String implementationName = "IntegrationTest";
119 private final String inputName = "InputName1";
120 private final String inputValue = "InputValue1";
124 webDriver = DriverFactory.getDriver();
125 homePage = new HomePage(webDriver);
128 @Test(dataProviderClass = OnboardingDataProviders.class, dataProvider = "vfcList")
129 public void importAndCertifyVfc(final String rootFolder, final String vfcFilename) {
131 final String resourceName = ElementFactory.addRandomSuffixToName(ElementFactory.getResourcePrefix());
132 final CreateVfcFlow createVfcFlow = createVFC(rootFolder + vfcFilename, resourceName);
133 vfcs.stream().filter(vfc -> vfc.getName().startsWith(resourceName)).findFirst().orElseThrow(
134 () -> new UiTestFlowRuntimeException(String.format("VFCs List should contain a VFC with the expected name %s", resourceName)));
135 final ResourceCreatePage vfcResourceCreatePage = createVfcFlow.getLandedPage()
136 .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected ResourceCreatePage"));
137 vfcResourceCreatePage.isLoaded();
138 vfcResourceCreatePage.certifyComponent();
139 ExtentTestActions.takeScreenshot(Status.INFO, "vfc-certified",
140 String.format("VFC '%s' was certified", resourceName));
143 @Test(dependsOnMethods = "importAndCertifyVfc")
144 public void createBaseService() {
145 final CreateVfFlow createVfFlow = createVF();
146 resourceCreatePage = createVfFlow.getLandedPage()
147 .orElseThrow(() -> new UiTestFlowRuntimeException("Expecting a ResourceCreatePage"));
148 resourceCreatePage.isLoaded();
151 @Test(dependsOnMethods = "createBaseService")
152 public void addComponentProperty() throws UnzipException {
153 propertiesToBeAddedMap = loadPropertiesToAdd();
154 addProperty(propertiesToBeAddedMap);
155 componentPage = addValueToProperty(loadPropertiesToEdit());
156 componentPage.isLoaded();
157 downloadAndVerifyCsarPackageAfterAddProperty(componentPage);
160 @Test(dependsOnMethods = "createBaseService")
161 public void addRelationshipTemplate() throws UnzipException {
163 resourceCreatePage = (ResourceCreatePage) homePage.clickOnComponent(vfResourceCreateData.getName());
164 resourceCreatePage.isLoaded();
165 addNodeToCompositionFlow = addNodeToCompositionAndCreateRelationship();
166 final CompositionPage compositionPage = addNodeToCompositionFlow.getLandedPage()
167 .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected return CompositionPage"));
168 compositionPage.isLoaded();
169 componentPage = compositionPage.goToGeneral();
170 componentPage.isLoaded();
171 downloadAndVerifyCsarPackage(componentPage);
174 @Test(dependsOnMethods = "addRelationshipTemplate")
175 public void createMetadataForServiceProperty() throws Exception {
177 componentPage = (ComponentPage) homePage.clickOnComponent(vfResourceCreateData.getName());
178 componentPage.isLoaded();
179 final ResourcePropertiesAssignmentPage propertiesAssignmentPage = componentPage.goToPropertiesAssignment();
181 propertiesAssignmentPage.isLoaded();
182 propertiesAssignmentPage.selectInputTab();
183 final var propertyName = propertiesAssignmentPage.getInputPropertyNames().get(0);
184 final var key = "Key";
185 final var value = "Test";
186 propertiesAssignmentPage.setInputPropertyMetadata(propertyName, key, value);
188 final var topologyTemplate = getMapEntry(downloadToscaTemplate(), "topology_template");
189 final var inputs = getMapEntry(topologyTemplate, "inputs");
190 final var serviceProperty = getMapEntry(inputs, propertyName);
191 final var servicePropertyMetadata = getMapEntry(serviceProperty, "metadata");
192 assertNotNull(servicePropertyMetadata, String.format("Metadata not found for property %s", propertyName));
193 assertEquals(servicePropertyMetadata.get(key), value, "Created service property metadata has invalid value");
196 @Test(dependsOnMethods = "addRelationshipTemplate")
197 public void addOutputsToVF_test() throws UnzipException, IOException {
199 final ComponentPage resourceCreatePage = (ComponentPage) homePage.clickOnComponent(vfResourceCreateData.getName());
200 resourceCreatePage.isLoaded();
202 final AttributesOutputsPage attributesOutputsPage = resourceCreatePage.goToAttributesOutputs();
203 attributesOutputsPage.isLoaded();
205 final ComponentInstance createdComponentInstance = addNodeToCompositionFlow.getCreatedComponentInstance()
206 .orElseThrow(() -> new UiTestFlowRuntimeException("Expecting a ComponentInstance"));
208 attributesOutputsPage.clickOnAttributeNavigation(createdComponentInstance.getName());
209 assertTrue(attributesOutputsPage.isAttributePresent("attr_1"));
210 attributesOutputsPage.declareOutput("attr_1");
211 attributesOutputsPage.clickOnOutputsTab();
212 assertTrue(attributesOutputsPage.isOutputPresent("attr_1"));
214 attributesOutputsPage.clickOnAttributesTab();
215 assertTrue(attributesOutputsPage.isAttributePresent("attr_2"));
216 attributesOutputsPage.declareOutput("attr_2");
217 attributesOutputsPage.clickOnOutputsTab();
218 assertTrue(attributesOutputsPage.isOutputPresent("attr_2"));
220 attributesOutputsPage.clickOnAttributesTab();
221 assertTrue(attributesOutputsPage.isAttributePresent("attr_3"));
222 attributesOutputsPage.declareOutput("attr_3");
223 attributesOutputsPage.clickOnOutputsTab();
224 assertTrue(attributesOutputsPage.isOutputPresent("attr_3"));
226 attributesOutputsPage.deleteOutput(createdComponentInstance.getName() + "_attr_2");
227 attributesOutputsPage.clickOnAttributesTab();
228 assertTrue(attributesOutputsPage.isAttributePresent("attr_2"));
229 attributesOutputsPage.clickOnOutputsTab();
230 assertTrue(attributesOutputsPage.isOutputDeleted("attr_2"));
232 attributesOutputsPage.clickOnAttributesTab();
233 ExtentTestActions.addScreenshot(Status.INFO, "AttributesTab", "The Attribute's list : ");
235 attributesOutputsPage.clickOnOutputsTab();
236 ExtentTestActions.addScreenshot(Status.INFO, "OutputsTab", "The Output's list : ");
238 Map<String, Object> yamlObject = downloadToscaArtifact(attributesOutputsPage);
239 checkMetadata(yamlObject, vfResourceCreateData);
240 checkTopologyTemplate(yamlObject);
243 @Test(dependsOnMethods = "addRelationshipTemplate")
244 @Ignore // solved in https://gerrit.onap.org/r/c/sdc/+/127976
245 public void updateInterfaceOperation() throws Exception {
247 componentPage = (ComponentPage) homePage.clickOnComponent(vfResourceCreateData.getName());
248 componentPage.isLoaded();
249 final CompositionPage compositionPage = componentPage.goToComposition();
250 compositionPage.isLoaded();
251 ExtentTestActions.addScreenshot(Status.INFO, "select-VFC-node", "Selecting Node on composition");
252 compositionPage.selectNode(vfcs.get(1).getName());
253 final List<InputData> inputList = List.of(
254 new InputData("My_IT_InputName", "string", "My_IT_InputValue")
256 final InterfaceDefinitionOperationsModal.InterfaceOperationsData interfaceOperationsData =
257 new InterfaceDefinitionOperationsModal.InterfaceOperationsData("IT for updating an Interface Operation",
258 "MyIntegrationTestImplementationName", inputList);
259 updateInterfaceOperation(compositionPage, interfaceOperationsData);
260 componentPage = compositionPage.goToGeneral();
261 componentPage.isLoaded();
262 verifyToscaTemplateHasUpdatedInterfaceOperation(downloadToscaTemplate(), interfaceOperationsData);
265 @Test(dependsOnMethods = "addComponentProperty")
266 public void createSubstitutionFilter() throws Exception {
267 componentPage = (ComponentPage) homePage.clickOnComponent(vfResourceCreateData.getName());
268 componentPage.isLoaded();
269 loadSubstitutionFilterProperties();
270 final CompositionPage compositionPage = componentPage.goToComposition();
271 compositionPage.isLoaded();
272 substitutionFilterProperties.forEach(substitutionFilterProperty -> {
273 final CreateSubstitutionFilterFlow createSubstitutionFilterFlow = new CreateSubstitutionFilterFlow(webDriver, substitutionFilterProperty);
274 createSubstitutionFilterFlow.run(compositionPage);
276 componentPage = compositionPage.goToGeneral();
277 componentPage.isLoaded();
278 verifyToscaTemplateHasSubstitutionFilter(downloadToscaTemplate());
281 @Test(dependsOnMethods = "createBaseService")
282 public void createDirectiveNodeFilterTest() throws Exception {
283 final ResourceCreateData vfcResourceCreateData = vfcs.get(1);
284 final String vfcNameInComposition = vfcResourceCreateData.getName().concat(" 0");
285 final String value = "Test";
286 final LogicalOperator operator = LogicalOperator.EQUALS;
288 componentPage = (ComponentPage) homePage.clickOnComponent(vfcResourceCreateData.getName());
290 componentPage.isLoaded();
291 final ResourcePropertiesPage vfcPropertiesPage = componentPage.goToProperties();
292 vfcPropertiesPage.isLoaded();
293 final Map<String, String> propertyNamesAndTypes = vfcPropertiesPage.getPropertyNamesAndTypes();
294 final List<String> propertyNames = propertyNamesAndTypes.keySet().stream().collect(Collectors.toList());
295 final ServiceDependencyProperty serviceDependencyProperty =
296 new ServiceDependencyProperty(propertyNames.get(0), propertyNamesAndTypes.get(propertyNames.get(0)), value, operator);
298 homePage.getTopNavComponent().clickOnHome();
300 homePage.clickOnComponent(vfResourceCreateData.getName());
302 componentPage.isLoaded();
303 final CompositionPage compositionPage = componentPage.goToComposition();
304 compositionPage.isLoaded();
305 compositionPage.selectNode(vfcNameInComposition);
307 final CreateDirectiveNodeFilterFlow createDirectiveNodeFilterFlow =
308 new CreateDirectiveNodeFilterFlow(webDriver, 2, serviceDependencyProperty);
309 createDirectiveNodeFilterFlow.run(componentPage);
311 verifyAvailableDirectiveTypes(createDirectiveNodeFilterFlow.getDirectiveOptions());
313 verifyAvailablePropertyNames(propertyNames, createDirectiveNodeFilterFlow.getPropertyOptions());
315 componentPage = compositionPage.goToGeneral();
316 componentPage.isLoaded();
317 final Map<?, ?> yaml = downloadToscaTemplate();
318 verifyToscaTemplateHasDirectiveNodeFilter(yaml, serviceDependencyProperty, vfcNameInComposition);
321 @Test(dependsOnMethods = "addComponentProperty")
322 public void declareInputFromProperties() throws Exception {
323 componentPage = (ComponentPage) homePage.clickOnComponent(vfResourceCreateData.getName());
324 componentPage.isLoaded();
326 ResourcePropertiesAssignmentPage propertiesAssignmentPage = componentPage.goToPropertiesAssignment();
327 propertiesAssignmentPage.isLoaded();
329 declareInputToBaseService(propertiesAssignmentPage, "property1");
330 declareInputToInstanceProperties(propertiesAssignmentPage, "resourceSubtype");
331 verifyToscaTemplateHasDeclareInput(downloadToscaTemplate());
334 @Test(dependsOnMethods = "createBaseService")
335 public void addComponentInputs() throws Exception {
336 inputsToBeAddedMap = loadInputsToAdd();
337 addInput(inputsToBeAddedMap);
338 verifyToscaTemplateAddInput(downloadToscaTemplate());
341 private void checkMetadata(final Map<String, Object> map, final ResourceCreateData createdData) {
342 final Map<String, Object> metadata = getMapEntry(map, "metadata");
344 assertEquals(createdData.getName(), metadata.get("name"));
345 assertEquals(createdData.getDescription(), metadata.get("description"));
346 assertEquals("Generic", metadata.get("category"));
347 assertThat((String) metadata.get("type"), not(emptyString()));
348 assertEquals(createdData.getCategory(), metadata.get("subcategory"));
349 assertEquals(createdData.getVendorName(), metadata.get("resourceVendor"));
350 assertEquals(createdData.getVendorRelease(), metadata.get("resourceVendorRelease"));
351 assertEquals(createdData.getVendorModelNumber(), metadata.get("reourceVendorModelNumber"));
354 private void checkTopologyTemplate(final Map<String, Object> map) {
355 final Map<String, Object> mapEntry = getMapEntry(map, "topology_template");
356 assertNotNull(mapEntry);
358 final Map<String, Object> inputs = getMapEntry(mapEntry, "inputs");
359 assertThat(inputs, not(anEmptyMap()));
361 final Map<String, Object> outputs = getMapEntry(mapEntry, "outputs");
362 assertThat(outputs, not(anEmptyMap()));
363 assertEquals(2, outputs.keySet().stream().filter(s -> (s.contains("_attr_1") || s.contains("_attr_3")) && !s.contains("_attr_2")).count());
365 final Map<String, Object> nodeTemplates = getMapEntry(mapEntry, "node_templates");
366 assertThat(nodeTemplates, not(anEmptyMap()));
368 final Map<String, Object> substitutionMappings = getMapEntry(mapEntry, "substitution_mappings");
369 assertThat(substitutionMappings, not(anEmptyMap()));
371 final Map<String, Object> attributes = getMapEntry(substitutionMappings, "attributes");
372 assertThat(attributes, not(anEmptyMap()));
373 assertEquals(2, attributes.keySet().stream().filter(s -> (s.contains("_attr_1") || s.contains("_attr_3")) && !s.contains("_attr_2")).count());
377 * Updates an Interface operation from a selected Node (VFC)
378 * @param compositionPage the composition page
379 * @param interfaceOperationsData the interface definition
380 * @throws IOException
382 private void updateInterfaceOperation(final CompositionPage compositionPage,
383 final InterfaceDefinitionOperationsModal.InterfaceOperationsData interfaceOperationsData) throws IOException {
384 final CompositionDetailSideBarComponent detailSideBar = compositionPage.getDetailSideBar();
385 detailSideBar.isLoaded();
386 final CompositionInterfaceOperationsTab compositionInterfaceOperationsTab =
387 (CompositionInterfaceOperationsTab) detailSideBar.selectTab(CompositionDetailTabName.INTERFACE_OPERATIONS);
388 compositionInterfaceOperationsTab.isLoaded();
389 ExtentTestActions.takeScreenshot(Status.INFO, "compositionInterfaceOperationsTab",
390 "Composition Interface Operations Tab loaded");
391 assertTrue(compositionInterfaceOperationsTab.isOperationPresent(interfaceOperationName));
392 final InterfaceDefinitionOperationsModal compositionInterfaceOperationsModal = compositionInterfaceOperationsTab
393 .clickOnOperation(interfaceOperationName);
394 compositionInterfaceOperationsModal.isLoaded();
395 ExtentTestActions.takeScreenshot(Status.INFO, "update-interface-operation-modal", "Loading Interface Operations Modal");
396 compositionInterfaceOperationsModal.updateInterfaceOperation(interfaceOperationsData);
397 compositionInterfaceOperationsTab.isLoaded();
398 ExtentTestActions.addScreenshot(Status.INFO, "updated-interface-operation",
399 "The Interface operation from the selected Node was successfully updated");
400 // Gives time for UI to load the Updated Interface Operation
401 final CompositionInformationTab compositionInformationTab =
402 (CompositionInformationTab) detailSideBar.selectTab(CompositionDetailTabName.INFORMATION);
403 compositionInformationTab.isLoaded();
404 validateUpdatedInterfaceOperation(detailSideBar, interfaceOperationsData);
408 * Validates if the Updated Interface Operation has the expected values
409 * @param detailSideBar The composition Page
410 * @param interfaceOperationsData The Updated Interface Definition
412 private void validateUpdatedInterfaceOperation(final CompositionDetailSideBarComponent detailSideBar,
413 final InterfaceDefinitionOperationsModal.InterfaceOperationsData interfaceOperationsData) {
414 final CompositionInterfaceOperationsTab compositionInterfaceOperationsTab = (CompositionInterfaceOperationsTab) detailSideBar
415 .selectTab(CompositionDetailTabName.INTERFACE_OPERATIONS);
416 compositionInterfaceOperationsTab.isLoaded();
417 assertTrue(compositionInterfaceOperationsTab.isOperationPresent(interfaceOperationName));
418 assertTrue(compositionInterfaceOperationsTab.isDescriptionPresent());
419 final InterfaceDefinitionOperationsModal compositionInterfaceOperationsModal = compositionInterfaceOperationsTab
420 .clickOnOperation(interfaceOperationName);
421 compositionInterfaceOperationsModal.isLoaded();
422 ExtentTestActions.takeScreenshot(Status.INFO, "validate-updated-interface-operation",
423 "Loading the Interface Operations Modal for validating");
424 assertThat("The Interface Operation Description should match", interfaceOperationsData.getDescription(),
425 equalToIgnoringCase(compositionInterfaceOperationsModal.getDescription()));
426 assertThat("The Interface Operation Implementation Name should match", interfaceOperationsData.getImplementationName(),
427 equalToIgnoringCase(compositionInterfaceOperationsModal.getImplementationName()));
428 // assertThat("The Interface Operation Input key should match", interfaceOperationsData.getInputName(),
429 // equalToIgnoringCase(compositionInterfaceOperationsModal.getInputName()));
430 // assertThat("The Interface Operation Input Value should match", interfaceOperationsData.getInputValue(),
431 // equalToIgnoringCase(compositionInterfaceOperationsModal.getInputValue()));
432 compositionInterfaceOperationsModal.clickOnCancel();
435 private void verifyToscaTemplateHasUpdatedInterfaceOperation(final Map<?, ?> toscaTemplateYaml,
436 final InterfaceDefinitionOperationsModal.InterfaceOperationsData interfaceOperationsData) {
438 assertNotNull(toscaTemplateYaml, "No contents in TOSCA Template");
439 final Map<String, Object> topologyTemplateTosca = getMapEntry((Map<String, Object>) toscaTemplateYaml, "topology_template");
440 assertThat("Should contain a topology_template entry", toscaTemplateYaml, is(notNullValue()));
441 final Map<String, Object> nodeTemplatesTosca = getMapEntry(topologyTemplateTosca, "node_templates");
442 assertThat("Should contain a node_templates entry", nodeTemplatesTosca, is(notNullValue()));
443 final Optional<Entry<String, Object>> nodeWithInterfaceOperation = nodeTemplatesTosca.entrySet().stream()
444 .filter(s -> s.getKey().startsWith(vfcs.get(1).getName())).findFirst();
445 assertThat("Should contain a node (VFC)", nodeWithInterfaceOperation.isPresent(), is(true));
446 final Map<String, Object> interfacesEntry = (Map<String, Object>) nodeWithInterfaceOperation.get().getValue();
447 assertThat("The Interfaces Entry should not be empty", interfacesEntry, not(anEmptyMap()));
448 final Map<String, Object> interfaceOperations = (Map<String, Object>) interfacesEntry.get("interfaces");
449 assertThat("The Interface Entry should have operations", interfaceOperations, not(anEmptyMap()));
450 final Map<String, Object> interfaceNameMap = (Map<String, Object>) interfaceOperations.get(interfaceName);
451 assertThat(String.format("'%s' should contain a Interface Name entry '%s'", interfaceNameMap, interfaceName),
452 interfaceOperations, not(anEmptyMap()));
453 final Map<String, Object> updatedInterfaceOperation = (Map<String, Object>) interfaceNameMap.get(interfaceOperationName);
454 assertThat(String.format("'%s' should contain a Interface Operation Name '%s'", updatedInterfaceOperation, interfaceOperationName),
455 updatedInterfaceOperation, not(anEmptyMap()));
456 assertThat("The Interface Operation Description should match",
457 updatedInterfaceOperation.get("description").equals(interfaceOperationsData.getDescription()));
458 assertThat("The Interface Operation Implementation Name should match",
459 updatedInterfaceOperation.get("implementation").equals(interfaceOperationsData.getImplementationName()));
460 final Map<String, Object> updatedInterfaceOperationInput = (Map<String, Object>) updatedInterfaceOperation.get("inputs");
461 interfaceOperationsData.getInputList().forEach(inputData -> {
462 assertThat("The Interface Operation Input Key should match",
463 updatedInterfaceOperationInput.containsKey(inputData.getName()));
464 assertThat("The Interface Operation Input Value should match",
465 updatedInterfaceOperationInput.containsValue(inputData.getValue()));
469 private Map<String, Object> downloadToscaArtifact(final ComponentPage resourceCreatePage) throws UnzipException {
470 final DownloadCsarArtifactFlow downloadCsarArtifactFlow = downloadToscaCsar(resourceCreatePage);
471 final ToscaArtifactsPage toscaArtifactsPage = downloadCsarArtifactFlow.getLandedPage()
472 .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected ToscaArtifactsPage"));
474 assertThat("No artifact download was found", toscaArtifactsPage.getDownloadedArtifactList(), not(empty()));
475 final String downloadedCsarName = toscaArtifactsPage.getDownloadedArtifactList().get(0);
476 final String downloadFolderPath = getConfig().getDownloadAutomationFolder();
477 final Map<String, byte[]> filesFromZip = FileHandling.getFilesFromZip(downloadFolderPath, downloadedCsarName);
478 final Optional<String> resourceEntryOpt = filesFromZip.keySet().stream()
479 .filter(s -> s.equals("Definitions/" + downloadedCsarName.replace("-csar.csar", "-template.yml")))
481 if (resourceEntryOpt.isEmpty()) {
482 fail("Could not find the resource package in Definitions");
484 return loadYamlObject(filesFromZip.get(resourceEntryOpt.get()));
487 private void declareInputToBaseService(ResourcePropertiesAssignmentPage propertiesAssignmentPage, String propertyName){
488 propertiesAssignmentPage.selectProperty(propertyName);
489 propertiesAssignmentPage.clickOnDeclareInput();
490 propertiesAssignmentPage.clickInputTab(propertyName);
491 propertiesAssignmentPage.isInputPresent(vfResourceCreateData.getName() + "_" + propertyName);
494 private void declareInputToInstanceProperties(ResourcePropertiesAssignmentPage propertiesAssignmentPage, String propertyName){
495 propertiesAssignmentPage.selectPropertiesTab();
496 propertiesAssignmentPage.loadCompositionTab();
497 propertiesAssignmentPage.loadComponentInstanceProperties(vfcs.get(0).getName().concat(" 0"));
498 propertiesAssignmentPage.selectProperty(propertyName);
499 propertiesAssignmentPage.clickOnDeclareInput();
500 propertiesAssignmentPage.clickInputTab(propertyName);
501 propertiesAssignmentPage.isInputPresent(vfResourceCreateData.getName() + "_" + vfcs.get(0).getName());
504 private CreateVfFlow createVF() {
505 final ResourceCreateData vfCreateData = createVfFormData();
506 final CreateVfFlow createVfFlow = new CreateVfFlow(webDriver, vfCreateData);
507 createVfFlow.run(homePage);
511 private ResourceCreateData createVfFormData() {
512 vfResourceCreateData = new ResourceCreateData();
513 vfResourceCreateData.setRandomName(ElementFactory.getResourcePrefix() + "-VF");
514 vfResourceCreateData.setCategory(ResourceCategoryEnum.GENERIC_ABSTRACT.getSubCategory());
515 vfResourceCreateData.setTagList(Arrays.asList(vfResourceCreateData.getName(), "createVF"));
516 vfResourceCreateData.setDescription("aDescription");
517 vfResourceCreateData.setVendorName("EST");
518 vfResourceCreateData.setVendorRelease("4.1.1");
519 vfResourceCreateData.setVendorModelNumber("0001");
520 return vfResourceCreateData;
523 private CreateVfcFlow createVFC(final String vfcFullFilename, final String resourceName) {
524 final ResourceCreateData vfcCreateData = createVfcFormData(resourceName);
525 final CreateVfcFlow createVfcFlow = new CreateVfcFlow(webDriver, vfcCreateData, vfcFullFilename);
526 createVfcFlow.run(homePage);
527 ExtentTestActions.takeScreenshot(Status.INFO, "vfc-created", String.format("VFC '%s' was created", resourceName));
528 assertThat(vfcs, notNullValue());
529 vfcs.add(vfcCreateData);
530 return createVfcFlow;
533 private ResourceCreateData createVfcFormData(final String resourceName) {
534 final ResourceCreateData vfcCreateData = new ResourceCreateData();
535 vfcCreateData.setRandomName(resourceName);
536 vfcCreateData.setCategory(ResourceCategoryEnum.GENERIC_NETWORK_ELEMENTS.getSubCategory());
537 vfcCreateData.setTagList(Arrays.asList(vfcCreateData.getName(), "importVFC"));
538 vfcCreateData.setDescription("aDescription");
539 vfcCreateData.setVendorName("EST");
540 vfcCreateData.setVendorRelease("4.1.1");
541 vfcCreateData.setVendorModelNumber("0001");
542 return vfcCreateData;
545 private AddNodeToCompositionFlow addNodeToCompositionAndCreateRelationship() {
546 assertThat(vfcs, hasSize(2));
547 final ComponentData parentComponent = new ComponentData();
548 parentComponent.setName(vfResourceCreateData.getName());
549 parentComponent.setVersion("0.1");
550 parentComponent.setComponentType(ComponentType.RESOURCE);
552 // Adds networkFunction to VF composition
553 final ComponentData networkFunction = new ComponentData();
554 networkFunction.setName(vfcs.get(0).getName());
555 networkFunction.setVersion("1.0");
556 networkFunction.setComponentType(ComponentType.RESOURCE);
557 final CompositionPage compositionPage = resourceCreatePage.goToComposition();
558 compositionPage.isLoaded();
559 AddNodeToCompositionFlow addNodeToCompositionFlow = addNodeToComposition(parentComponent, networkFunction, compositionPage);
560 networkFunctionInstance = addNodeToCompositionFlow.getCreatedComponentInstance()
561 .orElseThrow(() -> new UiTestFlowRuntimeException("Could not get the created component instance"));
563 // Adds networkService to VF composition
564 final ComponentData networkService = new ComponentData();
565 networkService.setName(vfcs.get(1).getName());
566 networkService.setVersion("1.0");
567 networkService.setComponentType(ComponentType.RESOURCE);
568 addNodeToCompositionFlow = addNodeToComposition(parentComponent, networkService, compositionPage);
569 networkServiceInstance = addNodeToCompositionFlow.getCreatedComponentInstance()
570 .orElseThrow(() -> new UiTestFlowRuntimeException("Could not get the created component instance"));
572 // Creates a dependsOn relationship from networkServiceInstance to networkFunctionInstance
573 createRelationship(compositionPage, networkFunctionInstance.getName(), "tosca.capabilities.Node",
574 networkServiceInstance.getName(), "tosca.capabilities.Node");
576 return addNodeToCompositionFlow;
579 public AddNodeToCompositionFlow addNodeToComposition(final ComponentData parentComponent,
580 final ComponentData resourceToAdd,
581 CompositionPage compositionPage) {
582 final AddNodeToCompositionFlow addNodeToCompositionFlow = new AddNodeToCompositionFlow(webDriver, parentComponent, resourceToAdd);
583 compositionPage = (CompositionPage) addNodeToCompositionFlow.run(compositionPage)
584 .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected CompositionPage"));
585 compositionPage.isLoaded();
586 ExtentTestActions.takeScreenshot(Status.INFO, "node-added-to-composition",
587 String.format("Resource '%s' was added to composition", resourceToAdd.getName()));
588 return addNodeToCompositionFlow;
592 * 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
613 * @param propertyMap map of properties to be added
615 private void addProperty(final Map<String, String> propertyMap) {
616 componentPage = (ComponentPage) homePage.clickOnComponent(vfResourceCreateData.getName());
617 componentPage.isLoaded();
618 final AddComponentPropertyFlow addComponentPropertyFlow = new AddComponentPropertyFlow(webDriver, propertyMap);
619 addComponentPropertyFlow.run(componentPage.goToPropertiesAssignment());
623 * Adds a input to the base service
624 * @param inputMap map of inputs to be added
626 private void addInput(final Map<String, String> inputMap) {
627 componentPage = (ComponentPage) homePage.clickOnComponent(vfResourceCreateData.getName());
628 componentPage.isLoaded();
629 final AddComponentInputFlow addComponentInputFlow = new AddComponentInputFlow(webDriver, inputMap);
630 addComponentInputFlow.run(componentPage.goToPropertiesAssignment());
634 * Edits a property to add a value
635 * @param propertyMap map of properties to be edited
637 private ComponentPage addValueToProperty(final Map<String, Object> propertyMap) {
638 final EditComponentPropertiesFlow editComponentPropertiesFlow = new EditComponentPropertiesFlow(webDriver, propertyMap);
639 return editComponentPropertiesFlow.run().orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected return ComponentPage"));
643 * Downloads and verifies the generated tosca templates.
644 * @param componentPage the component page
645 * @throws UnzipException
647 private void downloadAndVerifyCsarPackage(final ComponentPage componentPage) throws UnzipException {
648 checkCsarPackage(downloadCsarPackage(componentPage));
652 * Downloads and verifies if the generated Tosca template contains the expected properties.
653 * @throws UnzipException
654 * @param componentPage
656 private void downloadAndVerifyCsarPackageAfterAddProperty(final ComponentPage componentPage) throws UnzipException {
657 verifyPropertiesOnGeneratedTemplate(downloadCsarPackage(componentPage));
660 private String downloadCsarPackage(final ComponentPage componentPage) {
661 final DownloadCsarArtifactFlow downloadCsarArtifactFlow = downloadToscaCsar(componentPage);
662 final ToscaArtifactsPage toscaArtifactsPage = downloadCsarArtifactFlow.getLandedPage()
663 .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected ToscaArtifactsPage"));
664 assertThat("No artifact download was found", toscaArtifactsPage.getDownloadedArtifactList(), not(empty()));
665 return toscaArtifactsPage.getDownloadedArtifactList().get(0);
669 * Downloads the generated CSAR package.
670 * @param componentPage the component page
671 * @return the Downloaded Tosca CSAR file
673 private DownloadCsarArtifactFlow downloadToscaCsar(final ComponentPage componentPage) {
674 final DownloadCsarArtifactFlow downloadCsarArtifactFlow = new DownloadCsarArtifactFlow(webDriver);
675 downloadCsarArtifactFlow.setWaitBeforeGetTheFile(5L);
676 downloadCsarArtifactFlow.run(componentPage);
677 return downloadCsarArtifactFlow;
681 * Verifies if the generated Tosca template contains the expected properties.
682 * @param downloadedCsarName the downloaded csar file name
683 * @throws UnzipException
685 private void verifyPropertiesOnGeneratedTemplate(final String downloadedCsarName) throws UnzipException {
686 final Map<String, byte[]> filesFromZip = extractFilesFromCsar(downloadedCsarName);
687 final String virtualFunctionName = vfResourceCreateData.getName().replace("-", "").toLowerCase();
688 final String vfResourceTemplateFile = "Definitions/resource-" + virtualFunctionName + "-template-interface.yml";
689 final String interfaceTemplateFile = filesFromZip.keySet().stream()
690 .filter(filename -> filename.equalsIgnoreCase(vfResourceTemplateFile)).findFirst()
691 .orElseThrow(() -> new UiTestFlowRuntimeException(String.format("Resource template file not found %s", vfResourceTemplateFile)));
692 final byte[] toscaInterfaceTemplateGenerated = filesFromZip.get(interfaceTemplateFile);
693 assertThat("The Generated Tosca template should not be null", toscaInterfaceTemplateGenerated, is(notNullValue()));
694 final Map<String, Object> interfaceTemplateYamlMap = loadYamlObject(toscaInterfaceTemplateGenerated);
695 final Map<String, Object> nodeTypesYamlMap = getMapEntry(interfaceTemplateYamlMap, "node_types");
696 assertThat(String.format("'%s' should contain a node_types entry", interfaceTemplateYamlMap), nodeTypesYamlMap, is(notNullValue()));
697 final Map<String, Object> properties = (Map) nodeTypesYamlMap.values().stream().filter(stringObjectEntry -> stringObjectEntry != null)
698 .collect(Collectors.toList()).get(0);
699 final Map<String, Object> propertiesFoundMap = (Map<String, Object>) properties.get("properties");
700 assertThat(String.format("The generated template file %s should contain all added properties", vfResourceTemplateFile),
701 propertiesFoundMap.keySet().containsAll(propertiesToBeAddedMap.keySet()), is(true));
705 * Checks if the downloaded Tosca csar includes the node templates for the added VFCs,
706 * the generated service template declared “tosca_simple_yaml_1_3” as its Tosca version,
707 * the generated csar contains the node type definitions for the added VFCs in the Definitions directory,
708 * the interface template contains the relationship declaration
709 * @param downloadedCsarName download Tosca CSAR filename
710 * @throws UnzipException
712 private void checkCsarPackage(final String downloadedCsarName) throws UnzipException {
713 final Map<String, byte[]> filesFromZip = extractFilesFromCsar(downloadedCsarName);
714 final String virtualFunctionName = vfResourceCreateData.getName().replace("-", "").toLowerCase();
715 final List<String> expectedDefinitionFolderFileList = getExpectedDefinitionFolderFileList(virtualFunctionName);
716 final Map<String, byte[]> expectedFilesFromZipMap = filesFromZip.entrySet().parallelStream()
717 .filter(key -> expectedDefinitionFolderFileList.stream()
718 .anyMatch(filename -> filename.equalsIgnoreCase(key.getKey()))).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
719 final String vfResourceTemplateFile = "Definitions/resource-" + virtualFunctionName + "-template.yml";
720 final String generatedTemplateFile = expectedFilesFromZipMap.keySet().stream()
721 .filter(filename -> filename.equalsIgnoreCase(vfResourceTemplateFile)).findFirst()
722 .orElseThrow(() -> new UiTestFlowRuntimeException(String.format("Resource template file not found %s", vfResourceTemplateFile)));
723 final byte[] toscaTemplateGenerated = filesFromZip.get(generatedTemplateFile);
724 assertThat(toscaTemplateGenerated, is(notNullValue()));
725 verifyGeneratedTemplate(toscaTemplateGenerated, generatedTemplateFile);
726 verifyNodesRelationship(expectedFilesFromZipMap, virtualFunctionName, filesFromZip);
729 private Map<String, byte[]> extractFilesFromCsar(final String downloadedCsarName) throws UnzipException {
730 final String downloadFolderPath = getConfig().getDownloadAutomationFolder();
731 final Map<String, byte[]> filesFromCsar = FileHandling.getFilesFromZip(downloadFolderPath, downloadedCsarName);
732 return filesFromCsar;
735 private void verifyGeneratedTemplate(final byte[] generatedTemplateData, final String generatedTemplateFile) {
736 final Map<String, Object> templateYamlMap = loadYamlObject(generatedTemplateData);
737 final boolean hasToscaDefinitionVersionEntry = templateYamlMap.containsKey("tosca_definitions_version");
738 assertThat(String.format("'%s' should contain tosca_definitions_version entry", generatedTemplateFile), hasToscaDefinitionVersionEntry,
740 final String toscaVersion = (String) templateYamlMap.get("tosca_definitions_version");
741 assertThat(String.format("'%s' tosca_definitions_version entry should have tosca_simple_yaml_1_3 value", generatedTemplateFile),
742 toscaVersion.equalsIgnoreCase("tosca_simple_yaml_1_3"));
743 final Map<String, Object> topologyTemplateTosca = getMapEntry(templateYamlMap, "topology_template");
744 assertThat(String.format("'%s' should contain a topology_template entry", generatedTemplateFile), topologyTemplateTosca, is(notNullValue()));
745 final Map<String, Object> nodeTemplatesTosca = getMapEntry(topologyTemplateTosca, "node_templates");
746 assertThat(String.format("'%s' should contain a node_templates entry", generatedTemplateFile), nodeTemplatesTosca, is(notNullValue()));
747 final List<String> nodeTemplateFound = nodeTemplatesTosca.keySet().parallelStream().filter(s -> vfcs.stream()
748 .anyMatch(vfc -> s.startsWith(vfc.getName()))).collect(Collectors.toList());
749 assertThat(String.format("'%s' should contain the node type definitions for the added VFCs '%s'", nodeTemplatesTosca, vfcs),
750 nodeTemplateFound, hasSize(vfcs.size()));
751 verifyRelationshipTemplate(topologyTemplateTosca, generatedTemplateFile);
754 private void verifyRelationshipTemplate(final Map<String, Object> topologyTemplateToscaMap, final String generatedTemplateFile) {
755 final Map<String, Object> relationshipTemplateMap = getMapEntry(topologyTemplateToscaMap, "relationship_templates");
756 assertThat(String.format("'%s' should contain a topology_template entry", generatedTemplateFile), relationshipTemplateMap,
758 final String result = Arrays.asList(relationshipTemplateMap.values()).toString();
759 assertThat(String.format("'%s' should contain a DependsOn relationship", relationshipTemplateMap),
760 result.contains("tosca.relationships.DependsOn"), is(true));
761 assertThat(String.format("'%s' should contain interfaces entry", relationshipTemplateMap), result.contains("interfaces"), is(true));
762 assertThat(String.format("'%s' should contain a Interface Name entry '%s'", relationshipTemplateMap, interfaceName),
763 result.contains(interfaceName), is(true));
764 assertThat(String.format("'%s' should contain a Interface Operation Name '%s'", relationshipTemplateMap, interfaceOperationName),
765 result.contains(interfaceOperationName), is(true));
766 assertThat(String.format("'%s' should contain Implementation Name '%s'", relationshipTemplateMap, implementationName),
767 result.contains(implementationName), is(true));
768 assertThat(String.format("'%s' should contain inputs entry", relationshipTemplateMap), result.contains("inputs"), is(true));
769 assertThat(String.format("'%s' should contain Input Name '%s'", relationshipTemplateMap, inputName), result.contains(inputName),
771 assertThat(String.format("'%s' should contain Input Value '%s'", relationshipTemplateMap, inputValue), result.contains(inputValue),
775 private void verifyNodesRelationship(final Map<String, byte[]> expectedFilesFromZipMap, final String virtualFunctionName,
776 final Map<String, byte[]> filesFromZip) {
777 final String vfResourceTemplateFile = "Definitions/resource-" + virtualFunctionName + "-template-interface.yml";
778 final String interfaceTemplateFile = expectedFilesFromZipMap.keySet().stream()
779 .filter(filename -> filename.equalsIgnoreCase(vfResourceTemplateFile)).findFirst()
780 .orElseThrow(() -> new UiTestFlowRuntimeException(String.format("Resource template file not found %s", vfResourceTemplateFile)));
781 final byte[] toscaInterfaceTemplateGenerated = filesFromZip.get(interfaceTemplateFile);
782 assertThat(toscaInterfaceTemplateGenerated, is(notNullValue()));
783 final Map<String, Object> interfaceTemplateYamlMap = loadYamlObject(toscaInterfaceTemplateGenerated);
784 final Map<String, Object> nodeTypesYamlMap = getMapEntry(interfaceTemplateYamlMap, "node_types");
785 assertThat(String.format("'%s' should contain a node_types entry", interfaceTemplateYamlMap), nodeTypesYamlMap, is(notNullValue()));
786 final String result = Arrays.asList(nodeTypesYamlMap.values()).toString();
787 assertThat(String.format("'%s' should contain a capabilities entry", nodeTypesYamlMap), result.contains("capabilities"), is(true));
788 assertThat(String.format("'%s' should contain a requirements entry", nodeTypesYamlMap), result.contains("requirements"), is(true));
789 assertThat(String.format("'%s' should contain a relationship entry", nodeTypesYamlMap), result.contains("relationship"), is(true));
790 assertThat(String.format("'%s' should contain a DependsOn relationship value", nodeTypesYamlMap),
791 result.contains("tosca.relationships.DependsOn"), is(true));
794 private List<String> getExpectedDefinitionFolderFileList(final String vfResourceName) {
795 final List<String> expectedDefinitionFolderFileList = new ArrayList<>();
796 vfcs.forEach(vfc -> expectedDefinitionFolderFileList.add("Definitions/resource-" + vfc.getName() + "-template.yml"));
797 expectedDefinitionFolderFileList.add("Definitions/resource-" + vfResourceName + "-template.yml");
798 expectedDefinitionFolderFileList.add("Definitions/resource-" + vfResourceName + "-template-interface.yml");
799 return expectedDefinitionFolderFileList;
802 private void verifyToscaTemplateHasDeclareInput(Map<?, ?> yaml) {
803 assertNotNull(yaml, "No contents in TOSCA Template");
804 final Map<String, Object> toscaYaml = (Map<String, Object>) yaml;
805 final Map<String, Object> topologyTemplateTosca = getMapEntry(toscaYaml, "topology_template");
806 assertThat(String.format("'%s' should contain a topology_template entry", toscaYaml), topologyTemplateTosca,
808 final Map<String, Object> inputsTosca = getMapEntry(topologyTemplateTosca, "inputs");
809 assertThat(String.format("'%s' should contain a inputs entry", toscaYaml), inputsTosca, notNullValue());
810 assertEquals(2, inputsTosca.keySet().stream()
811 .filter(s -> (s.contains("resourceSubtype") || s.contains("property1"))).count());
812 final Map<String, Object> substitutionMapping = getMapEntry(topologyTemplateTosca, "substitution_mappings");
813 assertThat(String.format("'%s' should contain a substitution_mappings entry", toscaYaml), substitutionMapping,
815 final Map<String, Object> substitutionMappingProperties = getMapEntry(substitutionMapping, "properties");
816 assertThat(String.format("'%s' should contain a properties entry", toscaYaml), substitutionMappingProperties,
818 assertEquals(2, substitutionMappingProperties.keySet().stream()
819 .filter(s -> (s.contains("resourceSubtype") || s.contains("property1"))).count());
822 private void verifyToscaTemplateAddInput(Map<?, ?> yaml) {
823 final Map<String, String> inputMap = loadInputsToAdd();
824 assertNotNull(yaml, "No contents in TOSCA Template");
825 final Map<String, Object> toscaYaml = (Map<String, Object>) yaml;
826 final Map<String, Object> topologyTemplateTosca = getMapEntry(toscaYaml, "topology_template");
827 assertThat(String.format("'%s' should contain a topology_template entry", toscaYaml), topologyTemplateTosca,
829 final Map<String, Object> inputsTosca = getMapEntry(topologyTemplateTosca, "inputs");
830 assertThat(String.format("'%s' should contain a inputs entry", toscaYaml), inputsTosca, notNullValue());
831 assertEquals(3, inputsTosca.keySet().stream()
832 .filter(s -> inputMap.containsKey(s)).count());
835 private Map<String, Object> getMapEntry(final Map<?, ?> yamlObj, final String entryName) {
837 return (Map<String, Object>) yamlObj.get(entryName);
838 } catch (final Exception e) {
839 final String errorMsg = String.format("Could not get the '%s' entry.", entryName);
840 LOGGER.error(errorMsg, e);
841 fail(errorMsg + "Error message: " + e.getMessage());
846 private Map<String, Object> loadYamlObject(final byte[] definitionYamlFile) {
847 return new Yaml().load(new String(definitionYamlFile));
850 private Map<String, String> loadPropertiesToAdd() {
851 final Map<String, String> propertyMap = new HashMap<>();
852 propertyMap.put("property1", "string");
853 propertyMap.put("property2", "integer");
854 propertyMap.put("property3", "boolean");
855 propertyMap.put("property4", "list");
856 propertyMap.put("property5", "map");
857 propertyMap.put("property6", "scalar-unit.size");
861 private Map<String, Object> loadPropertiesToEdit() {
862 final Map<String, Object> propertyMap = new HashMap<>();
863 propertyMap.put("property1", "Integration Test");
864 propertyMap.put("property2", 100);
865 propertyMap.put("property3", Boolean.TRUE);
866 propertyMap.put("property4", Arrays.asList("PropListV1", "PropListV2", "PropListV3"));
867 final Map<String, String> stringMap = new HashMap<>();
868 stringMap.put("PropMapKey1", "PropMapValue1");
869 stringMap.put("PropMapKey2", "PropMapValue2");
870 stringMap.put("PropMapKey3", "PropMapValue3");
871 propertyMap.put("property5", stringMap);
872 propertyMap.put("property6", 500);
876 private Map<String, String> loadInputsToAdd() {
877 final Map<String, String> inputMap = new HashMap<>();
878 inputMap.put("input1", "string");
879 inputMap.put("input2", "integer");
880 inputMap.put("input3", "boolean");
884 private void loadSubstitutionFilterProperties() {
885 final ResourcePropertiesAssignmentPage propertiesPage = componentPage.goToPropertiesAssignment();
886 propertiesPage.isLoaded();
887 ExtentTestActions.takeScreenshot(Status.INFO, "propertiesAssigment",
888 String.format("The %s Properties Assignment Page is loaded", vfResourceCreateData.getName()));
889 Map<String, String> propertyNamesAndTypes = propertiesPage.getPropertyNamesAndTypes();
890 assertThat(String.format("The Component '%s' should have properties", vfResourceCreateData.getName()), propertyNamesAndTypes,
892 propertyNamesAndTypes.forEach((name, type)
893 -> substitutionFilterProperties.add(new ServiceDependencyProperty(name, type, getPropertyValueByType(type), LogicalOperator.EQUALS)));
896 private String getPropertyValueByType(final String type) {
899 return "IntegrationTest";
907 return "[\"value1\", \"value2\"]";
909 return "{\"MyKey\": \"MyValue\"}";
911 throw new UnsupportedOperationException("Not yet implemented for " + type);
916 * Downloads Tosca Template file
917 * @return the tosca template yaml file
920 private Map<?, ?> downloadToscaTemplate() throws Exception {
921 final DownloadToscaTemplateFlow downloadToscaTemplateFlow = new DownloadToscaTemplateFlow(webDriver);
922 final ToscaArtifactsPage toscaArtifactsPage = (ToscaArtifactsPage) downloadToscaTemplateFlow.run(componentPage).get();
923 return FileHandling.parseYamlFile(getConfig().getDownloadAutomationFolder()
924 .concat(java.io.File.separator).concat(toscaArtifactsPage.getDownloadedArtifactList().get(0)));
927 private void verifyToscaTemplateHasSubstitutionFilter(final Map<?, ?> yaml) {
928 assertNotNull(yaml, "No contents in TOSCA Template");
929 final List<?> substitutionFilters = (List<?>) getSubstitutionFilterFromYaml(yaml).get("properties");
930 substitutionFilterProperties.forEach(substitutionFilterProperty -> {
931 final Map<?, ?> substitutionFilterMap = (Map<?, ?>) substitutionFilters.stream()
932 .filter(subFilter -> ((Map<?, ?>) subFilter).containsKey(substitutionFilterProperty.getName())).findAny().get();
933 assertThat("Added substitution filter not found in TOSCA Template",
934 substitutionFilterMap.containsKey(substitutionFilterProperty.getName()));
935 final Map<?, ?> substitutionFilterValue = (Map<?, ?>) ((List<?>) substitutionFilterMap.get(substitutionFilterProperty.getName())).get(0);
936 assertThat("Substitution Filter Value should not be empty", substitutionFilterMap, not(anEmptyMap()));
937 final String expectedSubstitutionPropertyValue = substitutionFilterProperty.getValue().replaceAll("[\"{}]", "");
938 final String actualSubstitutionPropertyValue = substitutionFilterValue.values().stream().findFirst().get() instanceof Map
939 ? substitutionFilterValue.values().stream().findFirst().get().toString().replace("=", ": ")
940 .replaceAll("\\{(.*?)\\}", "$1").trim()
941 : substitutionFilterValue.values().stream().findFirst().get().toString();
942 assertThat("Invalid value for added substitution filters found in TOSCA Template",
943 expectedSubstitutionPropertyValue.equalsIgnoreCase(actualSubstitutionPropertyValue));
944 assertThat("Invalid logical operator for added substitution filters found in TOSCA Template",
945 substitutionFilterValue.containsKey(substitutionFilterProperty.getLogicalOperator().getName()));
949 private Map<?, ?> getSubstitutionFilterFromYaml(final Map<?, ?> yaml) {
950 final Map<?, ?> topology = (Map<?, ?>) yaml.get("topology_template");
951 final Map<?, ?> substitutionMappings = (Map<?, ?>) topology.get("substitution_mappings");
952 return (Map<?, ?>) substitutionMappings.get("substitution_filter");
955 private void verifyAvailableDirectiveTypes(final List<String> availableDirectiveTypes) {
956 assertNotNull(availableDirectiveTypes, "Expected list of available Directive Types, but recieved null");
957 Arrays.asList(DirectiveType.values()).forEach(directiveType -> {
958 assertTrue(availableDirectiveTypes.contains(directiveType.getName())
959 , String.format("Expected directive %s to be availabe in UI options %s"
960 , directiveType.getName(), availableDirectiveTypes.toString()));
962 ExtentTestActions.log(Status.PASS, "All expected directive types are available for selection");
965 private void verifyAvailablePropertyNames(List<String> propertyNames, List<String> propertyNameOptions) {
966 assertEquals(propertyNameOptions.size(), propertyNames.size(), "Mismatch in the number of properties available for selection");
967 propertyNames.forEach(name -> {
968 assertNotEquals(false, propertyNameOptions.remove(name)
969 , String.format("Expected property %s not found in UI Select element", name));
971 ExtentTestActions.log(Status.PASS, "All expected properties are available for selection");
974 private void verifyToscaTemplateHasDirectiveNodeFilter(final Map<?, ?> yaml, ServiceDependencyProperty nodeFilterProperty, String nodeTemplateName) {
975 assertNotNull(yaml, "Tosca Template Yaml is not expected to be empty");
976 final List<?> nodeFilters = (List<?>) getDirectiveNodeFilterFromYaml(yaml, nodeTemplateName).get("properties");
977 final Map<?, ?> nodeFilter = (Map<?, ?>) nodeFilters.stream()
978 .filter(yamlNodeFilter -> ((Map<?, ?>) yamlNodeFilter).containsKey(nodeFilterProperty.getName())).findAny().get();
979 assertNotNull(nodeFilter, "Added directive node filter not found in TOSCA Template");
981 final Map<?, ?> nodeFilterValue = (Map<?, ?>) ((List<?>) nodeFilter.get(nodeFilterProperty.getName())).get(0);
982 assertTrue(nodeFilterValue.containsValue(nodeFilterProperty.getValue())
983 , "Invalid value for added directive node filter found in TOSCA Template");
984 assertTrue(nodeFilterValue.containsKey(nodeFilterProperty.getLogicalOperator().getName())
985 , "Invalid logical operator for added directive node filter found in TOSCA Template");
988 private Map<?,?> getDirectiveNodeFilterFromYaml(final Map<?,?> yaml, String nodeTemplateName) {
989 final Map<?, ?> topology = (Map<?, ?>) yaml.get("topology_template");
990 final Map<?, ?> nodeTemplates = (Map<?, ?>) topology.get("node_templates");
991 final Map<?, ?> resourceNode = (Map<?, ?>) nodeTemplates.get(nodeTemplateName);
992 return (Map<?, ?>) resourceNode.get("node_filter");