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.empty;
24 import static org.hamcrest.Matchers.not;
25 import static org.junit.Assert.fail;
27 import com.aventstack.extentreports.ExtentTest;
28 import com.aventstack.extentreports.Status;
30 import java.util.Optional;
31 import org.junit.jupiter.api.Assertions;
32 import org.onap.sdc.backend.ci.tests.data.providers.OnboardingDataProviders;
33 import org.onap.sdc.backend.ci.tests.datatypes.enums.UserRoleEnum;
34 import org.onap.sdc.backend.ci.tests.utils.general.ElementFactory;
35 import org.onap.sdc.frontend.ci.tests.exception.UnzipException;
36 import org.onap.sdc.frontend.ci.tests.execute.setup.DriverFactory;
37 import org.onap.sdc.frontend.ci.tests.execute.setup.SetupCDTest;
38 import org.onap.sdc.frontend.ci.tests.flow.CreateResourceFromVspFlow;
39 import org.onap.sdc.frontend.ci.tests.flow.CreateVlmFlow;
40 import org.onap.sdc.frontend.ci.tests.flow.CreateVspFlow;
41 import org.onap.sdc.frontend.ci.tests.flow.DownloadToscaCsarFlow;
42 import org.onap.sdc.frontend.ci.tests.flow.ImportVspFlow;
43 import org.onap.sdc.frontend.ci.tests.flow.exception.UiTestFlowRuntimeException;
44 import org.onap.sdc.frontend.ci.tests.pages.ComponentPage;
45 import org.onap.sdc.frontend.ci.tests.pages.ResourceCreatePage;
46 import org.onap.sdc.frontend.ci.tests.pages.ResourceLeftSideMenu;
47 import org.onap.sdc.frontend.ci.tests.pages.ResourceWorkspaceTopBarComponent;
48 import org.onap.sdc.frontend.ci.tests.pages.TopNavComponent;
49 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.ToscaArtifactsPage;
50 import org.onap.sdc.frontend.ci.tests.utilities.FileHandling;
51 import org.openqa.selenium.WebDriver;
52 import org.slf4j.Logger;
53 import org.slf4j.LoggerFactory;
54 import org.testng.annotations.BeforeMethod;
55 import org.testng.annotations.Test;
57 public class EtsiOnboardVnfCnfUiTests extends SetupCDTest {
59 private static final Logger LOGGER = LoggerFactory.getLogger(EtsiOnboardVnfCnfUiTests.class);
61 private WebDriver webDriver;
62 private TopNavComponent topNavComponent;
66 webDriver = DriverFactory.getDriver();
67 topNavComponent = new TopNavComponent(webDriver);
71 public void createVlm() {
72 final ExtentTest extendTest = getExtendTest();
73 extendTest.log(Status.INFO, String.format("Starting flow to create a VLM"));
74 final CreateVlmFlow createVlmFlow = new CreateVlmFlow(webDriver);
78 @Test(dataProviderClass = OnboardingDataProviders.class, dataProvider = "etsiVnfCnfOnboardPackages")
79 public void onboardEtsiVnfCnfFlow(final String rootFolder, final String vnfFile) {
81 final String resourceName = ElementFactory.addRandomSuffixToName(ElementFactory.getResourcePrefix());
82 runOnboardEtsiVnfCnf(resourceName, rootFolder, vnfFile);
86 * Runs ETSI onboarding VNF/CNF UI flow
88 * @param resourceName VSP name
89 * @param rootFolder VNF/CNF package location
90 * @param vnfCnfFile file to be onboarded
92 public void runOnboardEtsiVnfCnf(final String resourceName, final String rootFolder, final String vnfCnfFile) {
93 final ExtentTest extendTest = getExtendTest();
94 extendTest.log(Status.INFO,
95 String.format("Creating VSP '%s' by onboarding ETSI VNF/CNF package '%s'", resourceName, vnfCnfFile));
96 final CreateVspFlow createVspFlow = new CreateVspFlow(webDriver, resourceName, vnfCnfFile, rootFolder);
97 createVspFlow.run(topNavComponent);
99 extendTest.log(Status.INFO, String.format("Importing VSP '%s'", resourceName));
100 final ImportVspFlow importVspFlow = new ImportVspFlow(webDriver, resourceName);
102 extendTest.log(Status.INFO, "Creating ResourceCreatePage");
103 final ResourceCreatePage resourceCreatePage = importVspFlow.run()
104 .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected return ResourceCreatePage"));
106 extendTest.log(Status.INFO, String.format("Onboarding '%s' package", vnfCnfFile));
107 final CreateResourceFromVspFlow createResourceFlow = new CreateResourceFromVspFlow(webDriver, resourceName);
108 createResourceFlow.run(resourceCreatePage);
109 extendTest.log(Status.INFO, String.format("Successfully onboarded the package '%s'", vnfCnfFile));
111 extendTest.log(Status.INFO, "Loading Component Page");
112 final ComponentPage componentPage = loadComponentPage();
113 extendTest.log(Status.INFO, "Downloading Tosca CSAR generated");
114 final DownloadToscaCsarFlow downloadToscaCsarFlow = downloadToscaCsar(componentPage);
115 final ToscaArtifactsPage toscaArtifactsPage = downloadToscaCsarFlow.getLandedPage()
116 .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected ToscaArtifactsPage"));
117 assertThat("No artifact download was found", toscaArtifactsPage.getDownloadedArtifactList(), not(empty()));
118 extendTest.log(Status.INFO, "Tosca CSAR was successfully downloaded");
120 final String downloadedCsarName = toscaArtifactsPage.getDownloadedArtifactList().get(0);
121 extendTest.log(Status.INFO, String
122 .format("Verifying if the onboarded package is included in the downloaded csar '%s'", downloadedCsarName));
123 verifyOnboardedPackage(downloadedCsarName);
127 * Loads Component Page
129 * @return ComponentPage
131 private ComponentPage loadComponentPage() {
132 final ResourceLeftSideMenu resourceLeftSideMenu = new ResourceLeftSideMenu(webDriver);
133 resourceLeftSideMenu.isLoaded();
134 final ResourceWorkspaceTopBarComponent workspaceTopBarComponent = new ResourceWorkspaceTopBarComponent(
136 workspaceTopBarComponent.isLoaded();
137 final ComponentPage componentPage = Optional
138 .of(new ComponentPage(webDriver, topNavComponent, resourceLeftSideMenu, workspaceTopBarComponent))
139 .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected ComponentPage"));
140 componentPage.isLoaded();
141 return componentPage;
145 * Download the generated packag
147 * @return DownloadToscaCsarFlow
149 private DownloadToscaCsarFlow downloadToscaCsar(final ComponentPage componentPage) {
150 final DownloadToscaCsarFlow downloadToscaCsarFlow = new DownloadToscaCsarFlow(webDriver);
151 downloadToscaCsarFlow.run(componentPage);
152 return downloadToscaCsarFlow;
156 * Verifies if the onboarded package is included in the downloaded csar
158 * @param downloadedCsarName downloaded csar package name
160 private void verifyOnboardedPackage(final String downloadedCsarName) {
161 final String downloadFolderPath = getConfig().getDownloadAutomationFolder();
162 final Map<String, byte[]> filesFromZip;
164 filesFromZip = FileHandling.getFilesFromZip(downloadFolderPath, downloadedCsarName);
165 final java.util.Optional<String> etsiPackageEntryOpt =
166 filesFromZip.keySet().stream().filter(s -> s.startsWith("Artifacts/Deployment/ETSI_PACKAGE"))
168 if (etsiPackageEntryOpt.isEmpty()) {
169 Assertions.fail("Could not find the Onboarded Package in Artifacts/Deployment/ETSI_PACKAGE");
171 } catch (final UnzipException e) {
172 final String errorMsg = "Could not unzip the downloaded csar package";
173 LOGGER.info(errorMsg, e);
174 fail(String.format("%s Error: %s", errorMsg, e.getMessage()));
179 protected UserRoleEnum getRole() {
180 return UserRoleEnum.DESIGNER;