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=========================================================
19 package org.onap.sdc.frontend.ci.tests.execute.sanity;
21 import static org.hamcrest.MatcherAssert.assertThat;
22 import static org.hamcrest.Matchers.empty;
23 import static org.hamcrest.Matchers.emptyString;
24 import static org.hamcrest.Matchers.not;
25 import static org.junit.jupiter.api.Assertions.assertEquals;
26 import static org.junit.jupiter.api.Assertions.assertFalse;
27 import static org.junit.jupiter.api.Assertions.assertNotNull;
28 import static org.junit.jupiter.api.Assertions.assertTrue;
29 import static org.junit.jupiter.api.Assertions.fail;
31 import com.aventstack.extentreports.Status;
32 import java.util.Arrays;
34 import java.util.Optional;
35 import org.apache.commons.collections.MapUtils;
36 import org.onap.sdc.backend.ci.tests.datatypes.enums.ComponentType;
37 import org.onap.sdc.backend.ci.tests.datatypes.enums.ResourceCategoryEnum;
38 import org.onap.sdc.backend.ci.tests.utils.general.ElementFactory;
39 import org.onap.sdc.frontend.ci.tests.datatypes.ComponentData;
40 import org.onap.sdc.frontend.ci.tests.datatypes.ModelName;
41 import org.onap.sdc.frontend.ci.tests.datatypes.ResourceCreateData;
42 import org.onap.sdc.frontend.ci.tests.exception.UnzipException;
43 import org.onap.sdc.frontend.ci.tests.execute.setup.DriverFactory;
44 import org.onap.sdc.frontend.ci.tests.execute.setup.ExtentTestActions;
45 import org.onap.sdc.frontend.ci.tests.execute.setup.SetupCDTest;
46 import org.onap.sdc.frontend.ci.tests.flow.AddNodeToCompositionFlow;
47 import org.onap.sdc.frontend.ci.tests.flow.CreateVfFlow;
48 import org.onap.sdc.frontend.ci.tests.flow.CreateVfcFlow;
49 import org.onap.sdc.frontend.ci.tests.flow.DownloadCsarArtifactFlow;
50 import org.onap.sdc.frontend.ci.tests.flow.exception.UiTestFlowRuntimeException;
51 import org.onap.sdc.frontend.ci.tests.pages.AttributeModal;
52 import org.onap.sdc.frontend.ci.tests.pages.AttributesPage;
53 import org.onap.sdc.frontend.ci.tests.pages.ComponentPage;
54 import org.onap.sdc.frontend.ci.tests.pages.ResourceCreatePage;
55 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionDetailSideBarComponent;
56 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionDetailSideBarComponent.CompositionDetailTabName;
57 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionInformationTab;
58 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionInterfaceOperationsModal;
59 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionInterfaceOperationsTab;
60 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionPage;
61 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.ToscaArtifactsPage;
62 import org.onap.sdc.frontend.ci.tests.pages.home.HomePage;
63 import org.onap.sdc.frontend.ci.tests.utilities.FileHandling;
64 import org.openecomp.sdc.be.model.ComponentInstance;
65 import org.openqa.selenium.WebDriver;
66 import org.testng.annotations.BeforeClass;
67 import org.testng.annotations.Test;
68 import org.yaml.snakeyaml.Yaml;
70 public class ImportVfcUiTest extends SetupCDTest {
72 private String filePath;
73 private WebDriver webDriver;
74 private HomePage homePage;
75 private ResourceCreateData vfcCreateData;
76 private ResourceCreateData vfCreateData;
77 private ComponentInstance createdComponentInstance;
78 private final String vfcCategory = ResourceCategoryEnum.NETWORK_L4.getSubCategory();
81 public void beforeClass() {
82 filePath = FileHandling.getFilePath("VFCs/");
86 public void importVFC_createVF_addVFC2VF_test() throws UnzipException {
87 ComponentPage componentPage;
88 webDriver = DriverFactory.getDriver();
89 homePage = new HomePage(webDriver);
90 // TC - Import VFC with root namespace
91 String fileName = "org.openecomp.resource.VFC-root.yml";
92 CreateVfcFlow createVfcFlow = createVFC(fileName, ModelName.DEFAULT_MODEL_NAME.getName(), vfcCategory);
94 componentPage = createVfcFlow.getLandedPage().orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected return ResourceCreatePage"));
95 componentPage.isLoaded();
96 componentPage.certifyComponent();
97 componentPage.isLoaded();
99 Map<String, Object> yamlObject = downloadToscaArtifact(componentPage);
100 checkMetadata(yamlObject, vfcCreateData);
101 checkNodeTypes(yamlObject);
102 homePage.getTopNavComponent().clickOnHome();
104 // TC - Import hierarchy of VFCs
105 fileName = "org.openecomp.resource.VFC-child.yml";
106 createVfcFlow = createVFC(fileName, ModelName.DEFAULT_MODEL_NAME.getName(), vfcCategory);
107 componentPage = createVfcFlow.getLandedPage().orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected return ResourceCreatePage"));
108 componentPage.isLoaded();
110 componentPage = manageAttributes(componentPage);
111 componentPage.isLoaded();
112 componentPage.certifyComponent();
113 componentPage.isLoaded();
115 yamlObject = downloadToscaArtifact(componentPage);
116 checkMetadata(yamlObject, vfcCreateData);
117 checkNodeTypes(yamlObject);
118 homePage.getTopNavComponent().clickOnHome();
120 // TC - Import VFC with interface inputs
121 // TC - Import VFC with attributes
122 final CreateVfFlow createVfFlow = createVF();
123 componentPage = createVfFlow.getLandedPage().orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected return ResourceCreatePage"));
124 componentPage.isLoaded();
126 final CompositionPage compositionPage = addInterfaceOperations(componentPage);
127 componentPage = compositionPage.goToGeneral();
128 componentPage.isLoaded();
129 componentPage.certifyComponent();
130 componentPage.isLoaded();
132 yamlObject = downloadToscaArtifact(componentPage);
133 checkMetadata(yamlObject, vfCreateData);
134 checkTopologyTemplate(yamlObject);
139 public void importVfcWithModel() {
140 final String fileName = "VFC-For-Model.yaml";
141 final CreateVfcFlow createVfcFlow = createVFC(fileName, ModelName.ETSI_SOL001_v2_5_1.getName(), vfcCategory);
142 final ComponentPage componentPage = createVfcFlow.getLandedPage()
143 .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected return ResourceCreatePage"));
144 componentPage.isLoaded();
145 componentPage.certifyComponent();
146 componentPage.isLoaded();
149 private ComponentPage manageAttributes(final ComponentPage componentPage) {
150 final AttributesPage attributesPage = componentPage.goToAttributes();
151 attributesPage.isLoaded();
153 assertTrue(attributesPage.isAttributePresent("test_1"));
154 assertTrue(attributesPage.isAttributePresent("test_2"));
155 assertTrue(attributesPage.isAttributePresent("test_3"));
156 assertTrue(attributesPage.isAttributePresent("test_4"));
158 attributesPage.deleteAttribute("test_2");
159 assertFalse(attributesPage.isAttributePresent("test_2"));
160 ExtentTestActions.takeScreenshot(Status.INFO, "attributesPage.deleteAttribute", "Attribute 'test_2' successfully deleted");
161 attributesPage.addAttribute(new AttributeModal.AttributeData("test_9", "Additional attribute added from UI", "string", "one More Attribute"));
162 attributesPage.isLoaded();
163 assertTrue(attributesPage.isAttributePresent("test_9"));
164 ExtentTestActions.takeScreenshot(Status.INFO, "attributesPage.addAttribute", "Additional Attribute 'test_9' successfully added");
166 attributesPage.editAttribute(new AttributeModal.AttributeData("test_9", "Additional attribute added from UI".toUpperCase(), "string",
167 "one More Attribute".toUpperCase()));
168 attributesPage.isLoaded();
169 assertTrue(attributesPage.isAttributePresent("test_9"));
170 ExtentTestActions.takeScreenshot(Status.INFO, "attributesPage.editAttribute", "Additional Attribute 'test_9' successfully altered");
172 return attributesPage.clickOnGeneralMenuItem(ResourceCreatePage.class);
175 private CompositionPage addInterfaceOperations(final ComponentPage componentPage) {
176 final AddNodeToCompositionFlow addNodeToCompositionFlow = addNodeToCompositionFlow(componentPage);
177 final CompositionPage compositionPage = addNodeToCompositionFlow.getLandedPage()
178 .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected return CompositionPage"));
179 final CompositionDetailSideBarComponent detailSideBar = compositionPage.getDetailSideBar();
180 detailSideBar.isLoaded();
182 createdComponentInstance = addNodeToCompositionFlow.getCreatedComponentInstance()
183 .orElseThrow(() -> new UiTestFlowRuntimeException("Expecting a ComponentInstance"));
185 compositionPage.selectNode(createdComponentInstance.getName());
187 CompositionInterfaceOperationsTab compositionInterfaceOperationsTab =
188 (CompositionInterfaceOperationsTab) detailSideBar.selectTab(CompositionDetailTabName.INTERFACE_OPERATIONS);
189 compositionInterfaceOperationsTab.isLoaded();
190 ExtentTestActions.takeScreenshot(Status.INFO, "compositionInterfaceOperationsTab", "Composition Interface Operations Tab opened");
191 assertTrue(compositionInterfaceOperationsTab.isOperationPresent("create"));
192 CompositionInterfaceOperationsModal compositionInterfaceOperationsModal = compositionInterfaceOperationsTab.clickOnOperation("create");
193 compositionInterfaceOperationsModal.isLoaded();
195 .takeScreenshot(Status.INFO, "compositionInterfaceOperationsTab.clickOnOperation", "Composition Interface Operations Modal opened");
196 compositionInterfaceOperationsModal.clickOnDelete();
197 ExtentTestActions.takeScreenshot(Status.INFO, "compositionInterfaceOperationsModal.clickOnDelete", "Input deleted");
198 compositionInterfaceOperationsModal.addInput();
199 ExtentTestActions.takeScreenshot(Status.INFO, "compositionInterfaceOperationsModal.addInput", "Adding Input");
201 final CompositionInterfaceOperationsModal.InterfaceOperationsData interfaceOperationsData = new CompositionInterfaceOperationsModal.InterfaceOperationsData
202 ("This is CREATE operation", "fullPath/to/my/newImplementation.sh", "second", "9876");
203 compositionInterfaceOperationsModal.updateInterfaceOperation(interfaceOperationsData);
204 compositionInterfaceOperationsTab.isLoaded();
206 final CompositionInformationTab compositionInformationTab =
207 (CompositionInformationTab) detailSideBar.selectTab(CompositionDetailTabName.INFORMATION);
208 compositionInformationTab.isLoaded();
210 compositionInterfaceOperationsTab =
211 (CompositionInterfaceOperationsTab) detailSideBar.selectTab(CompositionDetailTabName.INTERFACE_OPERATIONS);
212 compositionInterfaceOperationsTab.isLoaded();
214 assertTrue(compositionInterfaceOperationsTab.isOperationPresent("create"));
215 assertTrue(compositionInterfaceOperationsTab.isDescriptionPresent());
216 ExtentTestActions.takeScreenshot(Status.INFO, "isDescriptionPresent", "Description is present");
217 compositionInterfaceOperationsModal = compositionInterfaceOperationsTab.clickOnOperation("create");
218 compositionInterfaceOperationsModal.isLoaded();
220 .takeScreenshot(Status.INFO, "compositionInterfaceOperationsTab.clickOnOperation", "Composition Interface Operations Modal opened");
222 checkCompositionInterfaceOperations(compositionInterfaceOperationsModal, interfaceOperationsData);
223 compositionInterfaceOperationsModal.clickOnCancel();
224 compositionInterfaceOperationsTab.isLoaded();
225 return compositionPage;
228 private AddNodeToCompositionFlow addNodeToCompositionFlow(final ComponentPage componentPage) {
229 componentPage.isLoaded();
230 final ComponentData parentComponent = new ComponentData();
231 parentComponent.setName(vfCreateData.getName());
232 parentComponent.setVersion("0.1");
233 parentComponent.setComponentType(ComponentType.RESOURCE);
234 final ComponentData componentToAdd = new ComponentData();
235 componentToAdd.setName(vfcCreateData.getName());
236 componentToAdd.setVersion("1.0");
237 componentToAdd.setComponentType(ComponentType.RESOURCE);
238 final AddNodeToCompositionFlow addNodeToCompositionFlow = new AddNodeToCompositionFlow(webDriver, parentComponent, componentToAdd);
239 addNodeToCompositionFlow.run(componentPage.goToComposition());
240 return addNodeToCompositionFlow;
243 private Map<String, Object> downloadToscaArtifact(final ComponentPage componentPage) throws UnzipException {
244 final DownloadCsarArtifactFlow downloadCsarArtifactFlow = downloadCsarArtifact(componentPage);
245 final ToscaArtifactsPage toscaArtifactsPage = downloadCsarArtifactFlow.getLandedPage()
246 .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected ToscaArtifactsPage"));
248 assertThat("No artifact download was found", toscaArtifactsPage.getDownloadedArtifactList(), not(empty()));
249 final String downloadedCsarName = toscaArtifactsPage.getDownloadedArtifactList().get(0);
250 final String downloadFolderPath = getConfig().getDownloadAutomationFolder();
251 final Map<String, byte[]> filesFromZip = FileHandling.getFilesFromZip(downloadFolderPath, downloadedCsarName);
252 final Optional<String> resourceEntryOpt = filesFromZip.keySet().stream()
253 .filter(s -> s.equals("Definitions/" + downloadedCsarName.replace("-csar.csar", "-template.yml")))
255 if (resourceEntryOpt.isEmpty()) {
256 fail("Could not find the resource package in Definitions");
258 return loadYamlObject(filesFromZip.get(resourceEntryOpt.get()));
261 private Map<String, Object> getMapEntry(final Map<String, Object> yamlObj, final String entryName) {
263 return (Map<String, Object>) yamlObj.get(entryName);
264 } catch (final Exception e) {
265 final String errorMsg = String.format("Could not get the '%s' entry.", entryName);
266 fail(errorMsg + "Error message: " + e.getMessage());
271 private Map<String, Object> loadYamlObject(final byte[] mainDefinitionFileBytes) {
272 return new Yaml().load(new String(mainDefinitionFileBytes));
275 private DownloadCsarArtifactFlow downloadCsarArtifact(final ComponentPage componentPage) {
276 final DownloadCsarArtifactFlow downloadCsarArtifactFlow = new DownloadCsarArtifactFlow(webDriver);
277 downloadCsarArtifactFlow.setWaitBeforeGetTheFile(5L);
278 downloadCsarArtifactFlow.run(componentPage);
279 return downloadCsarArtifactFlow;
282 private CreateVfcFlow createVFC(final String fileName, final String model, final String category) {
283 vfcCreateData = createVfcFormData(model, category);
284 final CreateVfcFlow createVfcFlow = new CreateVfcFlow(webDriver, vfcCreateData, filePath + fileName);
285 createVfcFlow.run(homePage);
286 return createVfcFlow;
289 private CreateVfFlow createVF() {
290 vfCreateData = createVfFormData();
291 final CreateVfFlow createVfFlow = new CreateVfFlow(webDriver, vfCreateData);
292 createVfFlow.run(homePage);
296 private ResourceCreateData createVfcFormData(final String model, final String category) {
297 final ResourceCreateData vfcCreateData = new ResourceCreateData();
298 vfcCreateData.setRandomName(ElementFactory.getResourcePrefix() + "-VFC");
299 vfcCreateData.setModel(model);
300 vfcCreateData.setCategory(category);
301 vfcCreateData.setTagList(Arrays.asList(vfcCreateData.getName(), "importVFC"));
302 vfcCreateData.setDescription("aDescription");
303 vfcCreateData.setVendorName("Ericsson");
304 vfcCreateData.setVendorRelease("1.2.3");
305 vfcCreateData.setVendorModelNumber("4.5.6");
306 return vfcCreateData;
309 private ResourceCreateData createVfFormData() {
310 final ResourceCreateData vfCreateData = new ResourceCreateData();
311 vfCreateData.setRandomName(ElementFactory.getResourcePrefix() + "-VF");
312 vfCreateData.setCategory(ResourceCategoryEnum.NETWORK_L4.getSubCategory());
313 vfCreateData.setTagList(Arrays.asList(vfCreateData.getName(), "createVF"));
314 vfCreateData.setDescription("aDescription");
315 vfCreateData.setVendorName("Ericsson");
316 vfCreateData.setVendorRelease("6.5.4");
317 vfCreateData.setVendorModelNumber("3.2.1");
321 private void checkMetadata(final Map<String, Object> map, final ResourceCreateData createdData) {
322 final Map<String, Object> metadata = getMapEntry(map, "metadata");
324 assertEquals(createdData.getName(), metadata.get("name"));
325 assertEquals(createdData.getDescription(), metadata.get("description"));
326 assertEquals("Network L4+", metadata.get("category"));
327 assertThat((String) metadata.get("type"), not(emptyString()));
328 assertEquals(createdData.getCategory(), metadata.get("subcategory"));
329 assertEquals(createdData.getVendorName(), metadata.get("resourceVendor"));
330 assertEquals(createdData.getVendorRelease(), metadata.get("resourceVendorRelease"));
331 assertEquals(createdData.getVendorModelNumber(), metadata.get("reourceVendorModelNumber"));
334 private void checkNodeTypes(final Map<String, Object> map) {
335 final Map<String, Object> mapEntry = getMapEntry(map, "node_types");
336 final Map<String, Object> nodeTypes = getMapEntry(mapEntry, mapEntry.keySet().iterator().next());
338 assertFalse(MapUtils.isEmpty(nodeTypes));
339 assertEquals("aDescription", nodeTypes.get("description"));
341 final Map<String, Object> properties = getMapEntry(nodeTypes, "properties");
342 assertFalse(MapUtils.isEmpty(properties));
344 final Map<String, Object> attributes = getMapEntry(nodeTypes, "attributes");
345 assertFalse(MapUtils.isEmpty(attributes));
347 final Map<String, Object> interfaces = getMapEntry(nodeTypes, "interfaces");
348 assertFalse(MapUtils.isEmpty(interfaces));
352 private void checkTopologyTemplate(final Map<String, Object> map) {
353 final Map<String, Object> topologyTemplate = getMapEntry(map, "topology_template");
354 assertNotNull(topologyTemplate);
356 final Map<String, Object> inputs = getMapEntry(topologyTemplate, "inputs");
357 assertFalse(MapUtils.isEmpty(inputs));
359 final Map<String, Object> nodeTemplates = getMapEntry(topologyTemplate, "node_templates");
360 assertFalse(MapUtils.isEmpty(nodeTemplates));
362 final Map<String, Object> attributes = getMapEntry((Map<String, Object>) nodeTemplates.get(createdComponentInstance.getName()), "attributes");
363 assertFalse(MapUtils.isEmpty(attributes));
364 assertEquals(4, attributes.keySet().stream()
365 .filter(s -> (s.contains("test_1") || s.contains("test_3") || s.contains("test_4") || s.contains("test_9")) && !s.contains("test_2"))
368 final Map<String, Object> substitutionMappings = getMapEntry(topologyTemplate, "substitution_mappings");
369 assertFalse(MapUtils.isEmpty(substitutionMappings));
373 private void checkCompositionInterfaceOperations(final CompositionInterfaceOperationsModal compositionInterfaceOperationsModal,
374 final CompositionInterfaceOperationsModal.InterfaceOperationsData interfaceOperationsData) {
375 assertEquals(interfaceOperationsData.getDescription(), compositionInterfaceOperationsModal.getDescription());
376 assertEquals(interfaceOperationsData.getImplementationName(), compositionInterfaceOperationsModal.getImplementationName());
377 assertEquals(interfaceOperationsData.getInputName(), compositionInterfaceOperationsModal.getInputName());
378 assertEquals(interfaceOperationsData.getInputValue(), compositionInterfaceOperationsModal.getInputValue());