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 com.clearspring.analytics.util.Pair;
25 import org.openecomp.sdc.be.model.User;
26 import org.openecomp.sdc.ci.tests.datatypes.*;
27 import org.openecomp.sdc.ci.tests.execute.devCI.ArtifactFromCsar;
28 import org.openecomp.sdc.ci.tests.execute.setup.ArtifactsCorrelationManager;
29 import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
30 import org.openecomp.sdc.ci.tests.pages.DeploymentArtifactPage;
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(Pair<String, VendorSoftwareProductObject> vsp, boolean isUpdate) throws Exception{
49 String vspName = vsp.left;
50 VendorSoftwareProductObject vspMetadata = vsp.right;
51 boolean vspFound = HomePage.searchForVSP(vspName);
55 List<WebElement> elemenetsFromTable = HomePage.getElemenetsFromTable();
56 // WebDriverWait wait = new WebDriverWait(GeneralUIUtils.getDriver(), 30);
57 // WebElement findElement = wait.until(ExpectedConditions.visibilityOf(elemenetsFromTable.get(1)));
58 // findElement.click();
59 elemenetsFromTable.get(1).click();
60 GeneralUIUtils.waitForLoader();
63 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ImportVfRepository.UPDATE_VSP.getValue());
66 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ImportVfRepository.IMPORT_VSP.getValue());
69 String lifeCycleState = ResourceGeneralPage.getLifeCycleState();
70 boolean needCheckout = lifeCycleState.equals(LifeCycleStateEnum.CHECKIN.getValue()) || lifeCycleState.equals(LifeCycleStateEnum.CERTIFIED.getValue());
74 ResourceGeneralPage.clickCheckoutButton();
75 Assert.assertTrue(ResourceGeneralPage.getLifeCycleState().equals(LifeCycleStateEnum.CHECKOUT.getValue()), "Did not succeed to checkout");
76 } catch (Exception e) {
77 ExtentTestActions.log(Status.ERROR, "Did not succeed to checkout");
80 GeneralUIUtils.waitForLoader();
83 //Metadata verification
84 VfVerificator.verifyOnboardedVnfMetadata(vspName, vspMetadata);
86 ExtentTestActions.log(Status.INFO, "Clicking create/update VNF");
87 String duration = GeneralUIUtils.getActionDuration(() -> waitUntilVnfCreated());
88 ExtentTestActions.log(Status.INFO, "Succeeded in importing/updating " + vspName, duration);
91 Assert.fail("Did not find VSP named " + vspName);
95 private static void waitUntilVnfCreated() {
96 GeneralUIUtils.clickOnElementByTestIdWithoutWait(DataTestIdEnum.GeneralElementsEnum.CREATE_BUTTON.getValue());
97 GeneralUIUtils.waitForLoader(60*10);
98 GeneralUIUtils.waitForAngular();
99 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.CHECKIN_BUTTON.getValue());
102 public static void updateVSP(Pair<String, VendorSoftwareProductObject> vsp) throws Exception{
103 ExtentTestActions.log(Status.INFO, "Updating VSP " + vsp.left);
104 importUpdateVSP(vsp, true);
107 public static void importVSP(Pair<String, VendorSoftwareProductObject> vsp) throws Exception{
108 ExtentTestActions.log(Status.INFO, "Importing VSP " + vsp.left);
109 importUpdateVSP(vsp, false);
112 public static void updateVnfAndValidate(String filePath, Pair<String, VendorSoftwareProductObject> vsp, String updatedVnfFile, User user) throws Exception, Throwable {
113 ExtentTestActions.log(Status.INFO, String.format("Going to update the VNF with %s......", updatedVnfFile));
114 System.out.println(String.format("Going to update the VNF with %s......", updatedVnfFile));
116 VendorSoftwareProductRestUtils.updateVendorSoftwareProductToNextVersion(vsp.right, user, filePath, updatedVnfFile);
117 HomePage.showVspRepository();
119 ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
120 DeploymentArtifactPage.verifyArtifactsExistInTable(filePath, updatedVnfFile);
123 public static Pair<String, VendorSoftwareProductObject> onboardAndValidate(ResourceReqDetails resourceReqDetails, String filepath, String vnfFile, User user) throws Exception {
124 ExtentTestActions.log(Status.INFO, String.format("Going to onboard the VNF %s", vnfFile));
125 System.out.println(String.format("Going to onboard the VNF %s", vnfFile));
127 AmdocsLicenseMembers amdocsLicenseMembers = VendorLicenseModelRestUtils.createVendorLicense(user);
128 Pair<String, VendorSoftwareProductObject> createVendorSoftwareProduct = VendorSoftwareProductRestUtils.createVendorSoftwareProduct(resourceReqDetails, vnfFile, filepath, user, amdocsLicenseMembers);
129 String vspName = createVendorSoftwareProduct.left;
131 DownloadManager.downloadCsarByNameFromVSPRepository(vspName, createVendorSoftwareProduct.right.getVspId());
132 File latestFilefromDir = FileHandling.getLastModifiedFileNameFromDir();
134 ExtentTestActions.log(Status.INFO, String.format("Searching for onboarded %s", vnfFile));
135 HomePage.showVspRepository();
136 ExtentTestActions.log(Status.INFO,String.format("Going to import %s", vnfFile.substring(0, vnfFile.indexOf("."))));
137 importVSP(createVendorSoftwareProduct);
139 ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
141 // Verify deployment artifacts
142 Map<String, Object> combinedMap = ArtifactFromCsar.combineHeatArtifacstWithFolderArtifacsToMap(latestFilefromDir.getAbsolutePath());
144 LinkedList<HeatMetaFirstLevelDefinition> deploymentArtifacts = ((LinkedList<HeatMetaFirstLevelDefinition>) combinedMap.get("Deployment"));
145 ArtifactsCorrelationManager.addVNFartifactDetails(vspName, deploymentArtifacts);
147 List<String> heatEnvFilesFromCSAR = deploymentArtifacts.stream().filter(e -> e.getType().equals("HEAT_ENV")).
148 map(e -> e.getFileName()).
149 collect(Collectors.toList());
151 validateDeploymentArtifactsVersion(deploymentArtifacts, heatEnvFilesFromCSAR);
153 DeploymentArtifactPage.verifyArtifactsExistInTable(filepath, vnfFile);
154 return createVendorSoftwareProduct;
157 public static void validateDeploymentArtifactsVersion(LinkedList<HeatMetaFirstLevelDefinition> deploymentArtifacts,
158 List<String> heatEnvFilesFromCSAR) {
159 String artifactVersion;
162 for(HeatMetaFirstLevelDefinition deploymentArtifact: deploymentArtifacts) {
163 artifactVersion = "1";
165 if(deploymentArtifact.getType().equals("HEAT_ENV")) {
167 } else if(deploymentArtifact.getFileName().contains(".")) {
168 artifactName = deploymentArtifact.getFileName().trim().substring(0, deploymentArtifact.getFileName().lastIndexOf("."));
170 artifactName = deploymentArtifact.getFileName().trim();
173 if (heatEnvFilesFromCSAR.contains(artifactName + ".env")){
174 artifactVersion = "2";
176 ArtifactUIUtils.validateArtifactNameVersionType(artifactName, artifactVersion, deploymentArtifact.getType());