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.VendorLicenseModel;
26 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
27 import org.openecomp.sdc.ci.tests.datatypes.HeatMetaFirstLevelDefinition;
28 import org.openecomp.sdc.ci.tests.datatypes.LifeCycleStateEnum;
29 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
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(1).click();
63 GeneralUIUtils.waitForLoader();
66 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ImportVfRepository.UPDATE_VSP.getValue());
68 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ImportVfRepository.IMPORT_VSP.getValue());
71 GeneralPageElements.restoreComponentFromElementPage(vspName);
74 //Metadata verification
75 onboardedVnfMetadataVerification(vsp, isUpdate);
76 String duration = GeneralUIUtils.getActionDuration(OnboardingUiUtils::waitUntilVnfCreated);
77 ExtentTestActions.log(Status.INFO, "Succeeded in importing/updating " + vspName, duration);
79 Assert.fail("Did not find VSP named " + vspName);
83 private static void onboardedVnfMetadataVerification(VendorSoftwareProductObject vsp, boolean isUpdate) {
85 VfVerificator.verifyOnboardedVnfMetadataAfterUpdateVNF(vsp.getName(), vsp);
87 VfVerificator.verifyOnboardedVnfMetadata(vsp.getName(), vsp);
91 public static boolean getVspValidationCongiguration() throws Exception {
92 return Boolean.parseBoolean(OnboardingUtils.getVspValidationConfiguration());
95 public static boolean putVspValidationCongiguration(boolean value) throws Exception {
96 return Boolean.parseBoolean(OnboardingUtils.putVspValidationConfiguration(value));
99 public static void doCheckOut() {
100 String lifeCycleState = ResourceGeneralPage.getLifeCycleState();
101 boolean needCheckout = lifeCycleState.equals(LifeCycleStateEnum.CHECKIN.getValue()) || lifeCycleState.equals(LifeCycleStateEnum.CERTIFIED.getValue());
104 ResourceGeneralPage.clickCheckoutButton();
105 Assert.assertTrue(ResourceGeneralPage.getLifeCycleState().equals(LifeCycleStateEnum.CHECKOUT.getValue()), "Did not succeed to checkout");
106 } catch (Exception e) {
107 ExtentTestActions.log(Status.ERROR, "Did not succeed to checkout");
110 GeneralUIUtils.waitForLoader();
114 private static void waitUntilVnfCreated() {
115 ExtentTestActions.log(Status.INFO, "Clicking create/update VNF");
116 GeneralUIUtils.ultimateWait();
117 GeneralUIUtils.clickOnAreaJS(DataTestIdEnum.GeneralElementsEnum.CREATE_BUTTON.getValue());
118 GeneralUIUtils.waitForLoader(WAITING_FOR_LOADER_TIME_OUT);
119 GeneralUIUtils.ultimateWait();
120 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.CHECKIN_BUTTON.getValue());
123 public static void updateVSP(VendorSoftwareProductObject vsp, boolean restore) throws Exception {
124 ExtentTestActions.log(Status.INFO, "Updating VSP " + vsp.getName());
125 importUpdateVSP(vsp, true, restore);
128 public static void updateVSP(VendorSoftwareProductObject vsp) throws Exception {
129 ExtentTestActions.log(Status.INFO, "Updating VSP " + vsp.getName());
130 importUpdateVSP(vsp, true, false);
133 public static void importVSP(VendorSoftwareProductObject vsp) throws Exception {
134 ExtentTestActions.log(Status.INFO, "Importing VSP " + vsp.getName());
135 importUpdateVSP(vsp, false, false);
138 public static void updateVnfAndValidate(String filePath, VendorSoftwareProductObject vsp, String updatedVnfFile, User user) throws Exception {
139 ExtentTestActions.log(Status.INFO, String.format("Going to update the VNF with %s......", updatedVnfFile));
140 System.out.println(String.format("Going to update the VNF with %s......", updatedVnfFile));
142 VendorSoftwareProductRestUtils.updateVendorSoftwareProductToNextVersion(vsp, user, filePath, updatedVnfFile);
143 HomePage.showVspRepository();
145 ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
146 DeploymentArtifactPage.verifyArtifactsExistInTable(filePath, updatedVnfFile);
149 public static VendorSoftwareProductObject createVSP(ResourceReqDetails resourceReqDetails, String vnfFile, String filepath, User user) throws Exception {
150 ExtentTestActions.log(Status.INFO, String.format("Creating VSP from package '%s'", vnfFile));
151 final VendorLicenseModel vendorLicenseModel = VendorLicenseModelRestUtils.createVendorLicense(user);
152 return VendorSoftwareProductRestUtils.createVSP(resourceReqDetails, vnfFile, filepath, user, vendorLicenseModel);
156 public static VendorSoftwareProductObject onboardAndValidate(ResourceReqDetails resourceReqDetails, String filepath, String vnfFile, User user) throws Exception {
157 ExtentTestActions.log(Status.INFO, String.format("Going to onboard the VNF %s", vnfFile));
158 System.out.println(String.format("Going to onboard the VNF %s", vnfFile));
160 VendorLicenseModel vendorLicenseModel = VendorLicenseModelRestUtils.createVendorLicense(user);
161 VendorSoftwareProductObject createVendorSoftwareProduct = VendorSoftwareProductRestUtils.createVendorSoftwareProduct(resourceReqDetails, vnfFile, filepath, user,
163 String vspName = createVendorSoftwareProduct.getName();
165 DownloadManager.downloadCsarByNameFromVSPRepository(vspName, createVendorSoftwareProduct.getVspId());
166 File latestFilefromDir = FileHandling.getLastModifiedFileNameFromDir();
168 ExtentTestActions.log(Status.INFO, String.format("Searching for onboarded %s", vnfFile));
169 HomePage.showVspRepository();
170 ExtentTestActions.log(Status.INFO, String.format("Going to import %s", vnfFile.substring(0, vnfFile.indexOf("."))));
171 importVSP(createVendorSoftwareProduct);
173 ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
175 // Verify deployment artifacts
176 Map<String, Object> combinedMap = ArtifactFromCsar.combineHeatArtifacstWithFolderArtifacsToMap(latestFilefromDir.getAbsolutePath());
178 LinkedList<HeatMetaFirstLevelDefinition> deploymentArtifacts = ((LinkedList<HeatMetaFirstLevelDefinition>) combinedMap.get("Deployment"));
179 ArtifactsCorrelationManager.addVNFartifactDetails(vspName, deploymentArtifacts);
181 List<String> heatEnvFilesFromCSAR = deploymentArtifacts.stream().filter(e -> e.getType().equals("HEAT_ENV")).
182 map(e -> e.getFileName()).
183 collect(Collectors.toList());
185 validateDeploymentArtifactsVersion(deploymentArtifacts, heatEnvFilesFromCSAR);
187 DeploymentArtifactPage.verifyArtifactsExistInTable(filepath, vnfFile);
188 return createVendorSoftwareProduct;
191 public static void validateDeploymentArtifactsVersion(LinkedList<HeatMetaFirstLevelDefinition> deploymentArtifacts,
192 List<String> heatEnvFilesFromCSAR) {
193 String artifactVersion;
196 for (HeatMetaFirstLevelDefinition deploymentArtifact : deploymentArtifacts) {
197 artifactVersion = "1";
199 if (deploymentArtifact.getType().equals("HEAT_ENV")) {
201 } else if (deploymentArtifact.getFileName().contains(".")) {
202 artifactName = deploymentArtifact.getFileName().trim().substring(0, deploymentArtifact.getFileName().lastIndexOf("."));
204 artifactName = deploymentArtifact.getFileName().trim();
207 if (heatEnvFilesFromCSAR.contains(artifactName + ".env")) {
208 artifactVersion = "2";
210 ArtifactUIUtils.validateArtifactNameVersionType(artifactName, artifactVersion, deploymentArtifact.getType());