2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.ci.tests.utilities;
23 import com.aventstack.extentreports.Status;
24 import org.openecomp.sdc.be.model.User;
25 import org.openecomp.sdc.ci.tests.datatypes.*;
26 import org.openecomp.sdc.ci.tests.execute.devCI.ArtifactFromCsar;
27 import org.openecomp.sdc.ci.tests.execute.setup.ArtifactsCorrelationManager;
28 import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
29 import org.openecomp.sdc.ci.tests.pages.DeploymentArtifactPage;
30 import org.openecomp.sdc.ci.tests.pages.GeneralPageElements;
31 import org.openecomp.sdc.ci.tests.pages.HomePage;
32 import org.openecomp.sdc.ci.tests.pages.ResourceGeneralPage;
33 import org.openecomp.sdc.ci.tests.utils.general.VendorLicenseModelRestUtils;
34 import org.openecomp.sdc.ci.tests.utils.general.VendorSoftwareProductRestUtils;
35 import org.openecomp.sdc.ci.tests.verificator.VfVerificator;
36 import org.openqa.selenium.WebElement;
37 import org.testng.Assert;
40 import java.util.LinkedList;
41 import java.util.List;
43 import java.util.stream.Collectors;
46 public class OnboardingUiUtils {
48 private static void importUpdateVSP(VendorSoftwareProductObject vsp, boolean isUpdate, boolean restore) throws Exception {
49 String vspName = vsp.getName();
50 boolean vspFound = HomePage.searchForVSP(vspName);
53 List<WebElement> elementsFromTable = HomePage.getElemenetsFromTable();
54 elementsFromTable.get(1).click();
55 GeneralUIUtils.waitForLoader();
58 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ImportVfRepository.UPDATE_VSP.getValue());
60 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ImportVfRepository.IMPORT_VSP.getValue());
63 GeneralPageElements.restoreComponentFromElementPage(vspName);
66 //Metadata verification
67 onboardedVnfMetadataVerification(vsp, isUpdate);
68 String duration = GeneralUIUtils.getActionDuration(() -> waitUntilVnfCreated());
69 ExtentTestActions.log(Status.INFO, "Succeeded in importing/updating " + vspName, duration);
71 Assert.fail("Did not find VSP named " + vspName);
75 private static void onboardedVnfMetadataVerification(VendorSoftwareProductObject vsp, boolean isUpdate) {
77 VfVerificator.verifyOnboardedVnfMetadataAfterUpdateVNF(vsp.getName(), vsp);
79 VfVerificator.verifyOnboardedVnfMetadata(vsp.getName(), vsp);
83 public static void doCheckOut() {
84 String lifeCycleState = ResourceGeneralPage.getLifeCycleState();
85 boolean needCheckout = lifeCycleState.equals(LifeCycleStateEnum.CHECKIN.getValue()) || lifeCycleState.equals(LifeCycleStateEnum.CERTIFIED.getValue());
88 ResourceGeneralPage.clickCheckoutButton();
89 Assert.assertTrue(ResourceGeneralPage.getLifeCycleState().equals(LifeCycleStateEnum.CHECKOUT.getValue()), "Did not succeed to checkout");
90 } catch (Exception e) {
91 ExtentTestActions.log(Status.ERROR, "Did not succeed to checkout");
94 GeneralUIUtils.waitForLoader();
98 private static void waitUntilVnfCreated() {
99 ExtentTestActions.log(Status.INFO, "Clicking create/update VNF");
100 GeneralUIUtils.ultimateWait();
101 GeneralUIUtils.clickOnAreaJS(DataTestIdEnum.GeneralElementsEnum.CREATE_BUTTON.getValue());
102 GeneralUIUtils.waitForLoader(60 * 10);
103 GeneralUIUtils.ultimateWait();
104 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.CHECKIN_BUTTON.getValue());
107 public static void updateVSP(VendorSoftwareProductObject vsp, boolean restore) throws Exception {
108 ExtentTestActions.log(Status.INFO, "Updating VSP " + vsp.getName());
109 importUpdateVSP(vsp, true, restore);
112 public static void updateVSP(VendorSoftwareProductObject vsp) throws Exception {
113 ExtentTestActions.log(Status.INFO, "Updating VSP " + vsp.getName());
114 importUpdateVSP(vsp, true, false);
117 public static void importVSP(VendorSoftwareProductObject vsp) throws Exception {
118 ExtentTestActions.log(Status.INFO, "Importing VSP " + vsp.getName());
119 importUpdateVSP(vsp, false, false);
122 public static void updateVnfAndValidate(String filePath, VendorSoftwareProductObject vsp, String updatedVnfFile, User user) throws Throwable {
123 ExtentTestActions.log(Status.INFO, String.format("Going to update the VNF with %s......", updatedVnfFile));
124 System.out.println(String.format("Going to update the VNF with %s......", updatedVnfFile));
126 VendorSoftwareProductRestUtils.updateVendorSoftwareProductToNextVersion(vsp, user, filePath, updatedVnfFile);
127 HomePage.showVspRepository();
129 ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
130 DeploymentArtifactPage.verifyArtifactsExistInTable(filePath, updatedVnfFile);
134 public static VendorSoftwareProductObject onboardAndValidate(ResourceReqDetails resourceReqDetails, String filepath, String vnfFile, User user) throws Exception {
135 ExtentTestActions.log(Status.INFO, String.format("Going to onboard the VNF %s", vnfFile));
136 System.out.println(String.format("Going to onboard the VNF %s", vnfFile));
138 AmdocsLicenseMembers amdocsLicenseMembers = VendorLicenseModelRestUtils.createVendorLicense(user);
139 VendorSoftwareProductObject createVendorSoftwareProduct = VendorSoftwareProductRestUtils.createVendorSoftwareProduct(resourceReqDetails, vnfFile, filepath, user, amdocsLicenseMembers);
140 String vspName = createVendorSoftwareProduct.getName();
142 DownloadManager.downloadCsarByNameFromVSPRepository(vspName, createVendorSoftwareProduct.getVspId());
143 File latestFilefromDir = FileHandling.getLastModifiedFileNameFromDir();
145 ExtentTestActions.log(Status.INFO, String.format("Searching for onboarded %s", vnfFile));
146 HomePage.showVspRepository();
147 ExtentTestActions.log(Status.INFO, String.format("Going to import %s", vnfFile.substring(0, vnfFile.indexOf("."))));
148 importVSP(createVendorSoftwareProduct);
150 ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
152 // Verify deployment artifacts
153 Map<String, Object> combinedMap = ArtifactFromCsar.combineHeatArtifacstWithFolderArtifacsToMap(latestFilefromDir.getAbsolutePath());
155 LinkedList<HeatMetaFirstLevelDefinition> deploymentArtifacts = ((LinkedList<HeatMetaFirstLevelDefinition>) combinedMap.get("Deployment"));
156 ArtifactsCorrelationManager.addVNFartifactDetails(vspName, deploymentArtifacts);
158 List<String> heatEnvFilesFromCSAR = deploymentArtifacts.stream().filter(e -> e.getType().equals("HEAT_ENV")).
159 map(e -> e.getFileName()).
160 collect(Collectors.toList());
162 validateDeploymentArtifactsVersion(deploymentArtifacts, heatEnvFilesFromCSAR);
164 DeploymentArtifactPage.verifyArtifactsExistInTable(filepath, vnfFile);
165 return createVendorSoftwareProduct;
168 public static void validateDeploymentArtifactsVersion(LinkedList<HeatMetaFirstLevelDefinition> deploymentArtifacts,
169 List<String> heatEnvFilesFromCSAR) {
170 String artifactVersion;
173 for (HeatMetaFirstLevelDefinition deploymentArtifact : deploymentArtifacts) {
174 artifactVersion = "1";
176 if (deploymentArtifact.getType().equals("HEAT_ENV")) {
178 } else if (deploymentArtifact.getFileName().contains(".")) {
179 artifactName = deploymentArtifact.getFileName().trim().substring(0, deploymentArtifact.getFileName().lastIndexOf("."));
181 artifactName = deploymentArtifact.getFileName().trim();
184 if (heatEnvFilesFromCSAR.contains(artifactName + ".env")) {
185 artifactVersion = "2";
187 ArtifactUIUtils.validateArtifactNameVersionType(artifactName, artifactVersion, deploymentArtifact.getType());