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.DataTestIdEnum;
26 import org.openecomp.sdc.ci.tests.datatypes.HeatMetaFirstLevelDefinition;
27 import org.openecomp.sdc.ci.tests.datatypes.LifeCycleStateEnum;
28 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
29 import org.openecomp.sdc.ci.tests.datatypes.VendorLicenseModel;
30 import org.openecomp.sdc.ci.tests.datatypes.VendorSoftwareProductObject;
31 import org.openecomp.sdc.ci.tests.execute.devCI.ArtifactFromCsar;
32 import org.openecomp.sdc.ci.tests.execute.setup.ArtifactsCorrelationManager;
33 import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
34 import org.openecomp.sdc.ci.tests.pages.DeploymentArtifactPage;
35 import org.openecomp.sdc.ci.tests.pages.GeneralPageElements;
36 import org.openecomp.sdc.ci.tests.pages.HomePage;
37 import org.openecomp.sdc.ci.tests.pages.ResourceGeneralPage;
38 import org.openecomp.sdc.ci.tests.utils.general.OnboardingUtils;
39 import org.openecomp.sdc.ci.tests.utils.general.VendorLicenseModelRestUtils;
40 import org.openecomp.sdc.ci.tests.utils.general.VendorSoftwareProductRestUtils;
41 import org.openecomp.sdc.ci.tests.verificator.VfVerificator;
42 import org.openqa.selenium.WebElement;
43 import org.testng.Assert;
46 import java.util.LinkedList;
47 import java.util.List;
49 import java.util.stream.Collectors;
52 public class OnboardingUiUtils {
54 private static final int WAITING_FOR_LOADER_TIME_OUT = 60 * 10;
56 private static void importUpdateVSP(VendorSoftwareProductObject vsp, boolean isUpdate, boolean restore) throws Exception {
57 String vspName = vsp.getName();
58 boolean vspFound = HomePage.searchForVSP(vspName);
61 List<WebElement> elementsFromTable = GeneralPageElements.getElementsFromTable();
62 elementsFromTable.get(0).click();
63 elementsFromTable.get(0).click();
64 GeneralUIUtils.waitForLoader();
67 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ImportVfRepository.UPDATE_VSP.getValue());
69 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ImportVfRepository.IMPORT_VSP.getValue());
72 GeneralPageElements.restoreComponentFromElementPage(vspName);
75 //Metadata verification
76 onboardedVnfMetadataVerification(vsp, isUpdate);
77 String duration = GeneralUIUtils.getActionDuration(OnboardingUiUtils::waitUntilVnfCreated);
78 ExtentTestActions.log(Status.INFO, "Succeeded in importing/updating " + vspName, duration);
80 Assert.fail("Did not find VSP named " + vspName);
84 private static void onboardedVnfMetadataVerification(VendorSoftwareProductObject vsp, boolean isUpdate) {
86 VfVerificator.verifyOnboardedVnfMetadataAfterUpdateVNF(vsp.getName(), vsp);
88 VfVerificator.verifyOnboardedVnfMetadata(vsp.getName(), vsp);
92 public static boolean getVspValidationCongiguration() throws Exception {
93 return Boolean.parseBoolean(OnboardingUtils.getVspValidationConfiguration());
96 public static boolean putVspValidationCongiguration(boolean value) throws Exception {
97 return Boolean.parseBoolean(OnboardingUtils.putVspValidationConfiguration(value));
100 public static void doCheckOut() {
101 String lifeCycleState = ResourceGeneralPage.getLifeCycleState();
102 boolean needCheckout = lifeCycleState.equals(LifeCycleStateEnum.CHECKIN.getValue()) || lifeCycleState.equals(LifeCycleStateEnum.CERTIFIED.getValue());
105 ResourceGeneralPage.clickCheckoutButton();
106 Assert.assertTrue(ResourceGeneralPage.getLifeCycleState().equals(LifeCycleStateEnum.CHECKOUT.getValue()), "Did not succeed to checkout");
107 } catch (Exception e) {
108 ExtentTestActions.log(Status.ERROR, "Did not succeed to checkout");
111 GeneralUIUtils.waitForLoader();
115 private static void waitUntilVnfCreated() {
116 ExtentTestActions.log(Status.INFO, "Clicking create/update VNF");
117 GeneralUIUtils.ultimateWait();
118 GeneralUIUtils.clickOnAreaJS(DataTestIdEnum.GeneralElementsEnum.CREATE_BUTTON.getValue());
119 GeneralUIUtils.waitForLoader(WAITING_FOR_LOADER_TIME_OUT);
120 GeneralUIUtils.ultimateWait();
121 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.CHECKIN_BUTTON.getValue());
124 public static void updateVSP(VendorSoftwareProductObject vsp, boolean restore) throws Exception {
125 ExtentTestActions.log(Status.INFO, "Updating VSP " + vsp.getName());
126 importUpdateVSP(vsp, true, restore);
129 public static void updateVSP(VendorSoftwareProductObject vsp) throws Exception {
130 ExtentTestActions.log(Status.INFO, "Updating VSP " + vsp.getName());
131 importUpdateVSP(vsp, true, false);
134 public static void importVSP(VendorSoftwareProductObject vsp) throws Exception {
135 ExtentTestActions.log(Status.INFO, "Importing VSP " + vsp.getName());
136 importUpdateVSP(vsp, false, false);
139 public static void updateVnfAndValidate(String filePath, VendorSoftwareProductObject vsp, String updatedVnfFile, User user) throws Exception {
140 ExtentTestActions.log(Status.INFO, String.format("Going to update the VNF with %s......", updatedVnfFile));
141 System.out.println(String.format("Going to update the VNF with %s......", updatedVnfFile));
143 VendorSoftwareProductRestUtils.updateVendorSoftwareProductToNextVersion(vsp, user, filePath, updatedVnfFile);
144 HomePage.showVspRepository();
146 ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
147 DeploymentArtifactPage.verifyArtifactsExistInTable(filePath, updatedVnfFile);
150 public static VendorSoftwareProductObject createVSP(ResourceReqDetails resourceReqDetails, String vnfFile, String filepath, User user) throws Exception {
151 ExtentTestActions.log(Status.INFO, String.format("Creating VSP from package '%s'", vnfFile));
152 final VendorLicenseModel vendorLicenseModel = VendorLicenseModelRestUtils.createVendorLicense(user);
153 return VendorSoftwareProductRestUtils.createVSP(resourceReqDetails, vnfFile, filepath, user, vendorLicenseModel);
157 public static VendorSoftwareProductObject onboardAndValidate(ResourceReqDetails resourceReqDetails, String filepath, String vnfFile, User user) throws Exception {
158 ExtentTestActions.log(Status.INFO, String.format("Going to onboard the VNF %s", vnfFile));
159 System.out.println(String.format("Going to onboard the VNF %s", vnfFile));
161 VendorLicenseModel vendorLicenseModel = VendorLicenseModelRestUtils.createVendorLicense(user);
162 VendorSoftwareProductObject createVendorSoftwareProduct = VendorSoftwareProductRestUtils.createVendorSoftwareProduct(resourceReqDetails, vnfFile, filepath, user,
164 String vspName = createVendorSoftwareProduct.getName();
166 DownloadManager.downloadCsarByNameFromVSPRepository(vspName, createVendorSoftwareProduct.getVspId());
167 File latestFilefromDir = FileHandling.getLastModifiedFileNameFromDir();
169 ExtentTestActions.log(Status.INFO, String.format("Going to import %s", vnfFile.substring(0, vnfFile.indexOf("."))));
170 importVSP(createVendorSoftwareProduct);
172 ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
174 // Verify deployment artifacts
175 Map<String, Object> combinedMap = ArtifactFromCsar.combineHeatArtifacstWithFolderArtifacsToMap(latestFilefromDir.getAbsolutePath());
177 LinkedList<HeatMetaFirstLevelDefinition> deploymentArtifacts = ((LinkedList<HeatMetaFirstLevelDefinition>) combinedMap.get("Deployment"));
178 ArtifactsCorrelationManager.addVNFartifactDetails(vspName, deploymentArtifacts);
180 List<String> heatEnvFilesFromCSAR = deploymentArtifacts.stream().filter(e -> e.getType().equals("HEAT_ENV")).
181 map(e -> e.getFileName()).
182 collect(Collectors.toList());
184 validateDeploymentArtifactsVersion(deploymentArtifacts, heatEnvFilesFromCSAR);
186 // DeploymentArtifactPage.verifyArtifactsExistInTable(filepath, vnfFile);
187 return createVendorSoftwareProduct;
190 public static void validateDeploymentArtifactsVersion(LinkedList<HeatMetaFirstLevelDefinition> deploymentArtifacts,
191 List<String> heatEnvFilesFromCSAR) {
192 String artifactVersion;
195 for (HeatMetaFirstLevelDefinition deploymentArtifact : deploymentArtifacts) {
196 artifactVersion = "1";
198 if (deploymentArtifact.getType().equals("HEAT_ENV")) {
200 } else if (deploymentArtifact.getFileName().contains(".")) {
201 artifactName = deploymentArtifact.getFileName().trim().substring(0, deploymentArtifact.getFileName().lastIndexOf("."));
203 artifactName = deploymentArtifact.getFileName().trim();
206 ArtifactUIUtils.validateArtifactNameVersionType(artifactName, artifactVersion, deploymentArtifact.getType());